Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.Text.Json" Version="10.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.Text.Json" Version="10.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="JsonSubTypes" Version="2.0.1" />
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.Text.Json" Version="10.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions DevCycle.SDK.Server.Common/API/DevCycleBaseClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using DevCycle.SDK.Server.Common.Exception;
using DevCycle.SDK.Server.Common.Model;
Expand All @@ -22,6 +23,7 @@ public abstract class DevCycleBaseClient : IDevCycleClient
public abstract string Platform();
public abstract IDevCycleApiClient GetApiClient();
public abstract DevCycleProvider GetOpenFeatureProvider();
public virtual Task InitializeAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
public abstract Task<Dictionary<string, Feature>> AllFeatures(DevCycleUser user);
public abstract Task<Dictionary<string, ReadOnlyVariable<object>>> AllVariables(DevCycleUser user);
public abstract Task<Variable<T>> Variable<T>(DevCycleUser user, string key, T defaultValue);
Expand Down
5 changes: 5 additions & 0 deletions DevCycle.SDK.Server.Common/API/DevCycleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public override Metadata GetMetadata()
return new Metadata(Client.SdkPlatform);
}

public override Task InitializeAsync(EvaluationContext context, CancellationToken cancellationToken = default)
{
return Client.InitializeAsync(cancellationToken);
}

public override async Task<ResolutionDetails<bool>> ResolveBooleanValueAsync(string flagKey, bool defaultValue, EvaluationContext context = null,
CancellationToken cancellationToken = new CancellationToken())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="OpenFeature" Version="2.2.0" />
<PackageReference Include="OpenFeature" Version="2.13.0" />
<PackageReference Include="Polly" Version="8.5.1" />
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.Text.Json" Version="10.0.0" />
<None Include="..\README.md" Pack="true" PackagePath="/" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.15.6" />
<PackageReference Include="System.Text.Json" Version="9.0.1" />
<PackageReference Include="System.Text.Json" Version="10.0.0" />
</ItemGroup>
Comment thread
jonathannorris marked this conversation as resolved.

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.1" />
<PackageReference Include="System.Text.Json" Version="10.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="RichardSzalay.MockHttp" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.1" />
<PackageReference Include="System.Text.Json" Version="10.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions DevCycle.SDK.Server.Local.MSTests/DevCycleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,5 +624,15 @@ public async Task EvalHooks_MultipleHooksInOptions()
Assert.AreEqual(1, hook2.FinallyCallCount);
Assert.IsNotNull(result);
}

[TestMethod]
public async Task TestOpenFeatureProviderWaitsForClientInit()
{
using var dvcClient = DevCycleTestClient.getTestClient();
await OpenFeature.Api.Instance.SetProviderAsync(dvcClient.GetOpenFeatureProvider());
var ctx = EvaluationContext.Builder().Set("user_id", "j_test").Build();
var result = await OpenFeature.Api.Instance.GetClient().GetBooleanValueAsync("test", false, ctx);
Assert.IsTrue(result);
Comment on lines +631 to +635
}
}
}
26 changes: 23 additions & 3 deletions DevCycle.SDK.Server.Local/Api/DevCycleLocalClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using SystemTimer = System.Timers.Timer;
using DevCycle.SDK.Server.Common.API;
using DevCycle.SDK.Server.Common.Model;
using DevCycle.SDK.Server.Common.Model.Local;
Expand Down Expand Up @@ -73,8 +75,9 @@
private readonly EventQueue eventQueue;
private readonly ILocalBucketing localBucketing;
private readonly ILogger logger;
private readonly Timer timer;
private readonly SystemTimer timer;
private bool closing;
private readonly Task initializeTask;
private DevCycleProvider OpenFeatureProvider { get; }
private readonly EvalHooksRunner evalHooksRunner;

Expand All @@ -84,7 +87,7 @@
ILoggerFactory loggerFactory,
EnvironmentConfigManager configManager,
ILocalBucketing localBucketing,
DevCycleRestClientOptions restClientOptions = null

Check warning on line 90 in DevCycle.SDK.Server.Local/Api/DevCycleLocalClient.cs

View workflow job for this annotation

GitHub Actions / run-example

Cannot convert null literal to non-nullable reference type.

Check warning on line 90 in DevCycle.SDK.Server.Local/Api/DevCycleLocalClient.cs

View workflow job for this annotation

GitHub Actions / run-example

Cannot convert null literal to non-nullable reference type.

Check warning on line 90 in DevCycle.SDK.Server.Local/Api/DevCycleLocalClient.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
)
{
ValidateSDKKey(sdkKey);
Expand All @@ -103,11 +106,11 @@
logger.LogWarning("The config CDN slug is being overriden, please ensure to update the config to v2 according to the config CDN updates documentation.");

}
timer = new Timer(dvcLocalOptions.EventFlushIntervalMs);
timer = new SystemTimer(dvcLocalOptions.EventFlushIntervalMs);
timer.Elapsed += OnTimedEvent;
timer.AutoReset = true;
timer.Enabled = true;
Task.Run(async delegate { await this.configManager.InitializeConfigAsync(); });
initializeTask = this.configManager.InitializeConfigAsync();
OpenFeatureProvider = new DevCycleProvider(this);
}

Expand Down Expand Up @@ -259,6 +262,23 @@
return OpenFeatureProvider;
}

public override async Task InitializeAsync(CancellationToken cancellationToken = default)
{
if (cancellationToken.CanBeCanceled)
{
var tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
using (cancellationToken.Register(() => tcs.TrySetResult(true)))
{
var completed = await Task.WhenAny(initializeTask, tcs.Task).ConfigureAwait(false);
if (completed != initializeTask)
{
cancellationToken.ThrowIfCancellationRequested();
}
}
}
await initializeTask.ConfigureAwait(false);
}

public override Task<Dictionary<string, Feature>> AllFeatures(DevCycleUser user)
{
if (!configManager.Initialized)
Expand Down
8 changes: 4 additions & 4 deletions DevCycle.SDK.Server.Local/DevCycle.SDK.Server.Local.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="LaunchDarkly.EventSource" Version="5.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
<PackageReference Include="System.Text.Json" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.0" />
<PackageReference Include="System.Text.Json" Version="10.0.0" />
<PackageReference Include="Wasmtime" Version="34.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="JsonSubTypes" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
<PackageReference Include="RestSharp" Version="112.0.0" />
</ItemGroup>

Expand Down
Loading