Skip to content

Commit

Permalink
Actually fix config subtype issue (#194)
Browse files Browse the repository at this point in the history
* Actually fix config subtype issue

This time I was less lazy and added a test...

* Add a second of slack to the authenticator test

It has been annoyingly flakey for a while
  • Loading branch information
einarmo authored Oct 26, 2022
1 parent 37c6999 commit abda21b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cognite.Testing/Cognite.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<IsTestProject>false</IsTestProject>
</PropertyGroup>

<ItemGroup>
Expand Down
47 changes: 45 additions & 2 deletions ExtractorUtils.Test/integration/RemoteConfigTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Cognite.Extractor.Common;
using Cognite.Extractor.Configuration;
using Cognite.Extractor.Logging;
using Cognite.Extractor.Utils;
using CogniteSdk;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -10,7 +12,7 @@
using Xunit;
using Xunit.Abstractions;

namespace ExtractorUtils.Test.integration
namespace ExtractorUtils.Test.Integration
{
public class RemoteConfigTest
{
Expand All @@ -34,7 +36,7 @@ private async Task<ExtPipe> Setup(CDFTester tester)
private void WriteConfig(CogniteHost host, bool remote, string path, string pipelineId)
{
var lines = CDFTester.GetConfig(host, true);
lines = lines.Prepend($"type: {(remote ? "remote" : "local")}").Append(" extraction-pipeline:").Append($" pipeline-id: {pipelineId}").ToArray();
lines = lines.Prepend($"type: {(remote ? "remote" : "local")}").Append(" extraction-pipeline:").Append($" external-id: {pipelineId}").ToArray();
System.IO.File.WriteAllLines(path, lines);
}

Expand Down Expand Up @@ -193,5 +195,46 @@ await tester.Destination.CogniteClient.ExtPipes.CreateConfigAsync(new ExtPipeCon
System.IO.File.Delete($"_temp_{remoteConfigPath}");
}
}

class CogniteSubType : CogniteConfig
{
public string ExtraField { get; set; }
}

class SubTypeConfig : VersionedConfig
{
public CogniteSubType Cognite { get; set; }
public LoggerConfig Logger { get; set; }

public override void GenerateDefaults()
{
}
}

[Theory]
[InlineData(CogniteHost.BlueField)]
public async Task TestRemoteConfigSubtype(CogniteHost host)
{
var tester = new CDFTester(host, _output);
var remoteConfigPath = $"{tester.Prefix}-remote-config.yml";
var pipeline = await Setup(tester);
WriteConfig(host, true, remoteConfigPath, pipeline.ExternalId);
try
{
var services = new ServiceCollection();
await tester.Destination.CogniteClient.ExtPipes.CreateConfigAsync(new ExtPipeConfigCreate
{
Config = "{\"version\": 2, \"logger\": { \"console\": {\"level\": \"verbose\"}}}",
ExternalId = pipeline.ExternalId
});
var config = await services.AddRemoteConfig<SubTypeConfig>(null, remoteConfigPath, null, "utils-test-app", null, true, false, null, tester.Source.Token, 2);
Assert.NotNull(config.Cognite);
}
finally
{
await tester.Destination.CogniteClient.ExtPipes.DeleteAsync(new[] { pipeline.Id });
System.IO.File.Delete($"_temp_{remoteConfigPath}");
}
}
}
}
6 changes: 3 additions & 3 deletions ExtractorUtils.Test/unit/CogniteTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ public async Task TestAuthenticator()
await Task.Delay(100);
token = await auth.GetToken(); // same token
Assert.Equal("token0", token);
await Task.Delay(1000); // token expired
await Task.Delay(2000); // token expired
token = await auth.GetToken(); // new token
Assert.Equal("token1", token);
await Task.Delay(1100); // token expired
await Task.Delay(2100); // token expired
await Assert.ThrowsAsync<CogniteUtilsException>(() => auth.GetToken()); // failed, returns null
}

Expand Down Expand Up @@ -690,7 +690,7 @@ private static Task<HttpResponseMessage> mockAuthSendAsync(HttpRequestMessage me
// build expected response
var reply = "{" + Environment.NewLine +
$" \"token_type\": \"Bearer\",{Environment.NewLine}" +
$" \"expires_in\": 1,{Environment.NewLine}" +
$" \"expires_in\": 2,{Environment.NewLine}" +
$" \"access_token\": \"token{_tokenCounter}\"{Environment.NewLine}" +
"}";
_tokenCounter++;
Expand Down
1 change: 1 addition & 0 deletions ExtractorUtils/Configuration/RemoteConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private T InjectRemoteConfig(T config)
cogniteConfig.ApiKey = _remoteConfig.Cognite.ApiKey;
cogniteConfig.ExtractionPipeline = _remoteConfig.Cognite.ExtractionPipeline;
cogniteConfig.Host = _remoteConfig.Cognite.Host;
cogniteProperty.SetValue(config, cogniteConfig);
}

return config;
Expand Down

0 comments on commit abda21b

Please sign in to comment.