Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
chore: updating tests and docs to use Context.FullyQualifiedKey
Browse files Browse the repository at this point in the history
  • Loading branch information
tanderson-ld committed Jun 4, 2024
1 parent 19ddbee commit 8282b56
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/LaunchDarkly.ClientSdk/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public ConfigurationBuilder Events(IComponentConfigurer<IEventProcessor> eventsC
/// </para>
/// <list type="bullet">
/// <item><description> The first time this happens in the application, the SDK will generate a
/// pseudo-random GUID and overwrite the context's <see cref="Context.Key"/> with this string.
/// pseudo-random GUID and overwrite the context's <see cref="Context.FullyQualifiedKey"/> with this string.
/// </description></item>
/// <item><description> The SDK will then cache this key so that the same key will be reused next time.
/// </description></item>
Expand Down
2 changes: 1 addition & 1 deletion src/LaunchDarkly.ClientSdk/Integrations/TestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ internal ItemDescriptor CreateFlag(int version, Context context)
}
int variation;
if (!_variationByContextKey.TryGetValue(context.Kind, out var keys) ||
!keys.TryGetValue(context.Key, out variation))
!keys.TryGetValue(context.FullyQualifiedKey, out variation))
{
variation = _variationFunc?.Invoke(context) ?? _defaultVariation;
}
Expand Down
2 changes: 1 addition & 1 deletion src/LaunchDarkly.ClientSdk/LdClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace LaunchDarkly.Sdk.Client
/// <para>
/// Normally, the SDK uses the exact context that you have specified in the <see cref="Context"/>. However,
/// you can also tell the SDK to generate a randomized identifier and use this as the context's
/// <see cref="Context.Key"/>; see <see cref="ConfigurationBuilder.GenerateAnonymousKeys(bool)"/>.
/// <see cref="Context.FullyQualifiedKey"/>; see <see cref="ConfigurationBuilder.GenerateAnonymousKeys(bool)"/>.
/// </para>
/// <para>
/// If you use more than one <see cref="ContextKind"/> in your evaluation contexts, and you request a
Expand Down
4 changes: 2 additions & 2 deletions tests/LaunchDarkly.ClientSdk.Tests/LDClientEndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void IdentifySwitchesUserAndGetsFlagsSync(UpdateMode mode)
var success = client.Identify(_otherUser, TimeSpan.FromSeconds(5));
Assert.True(success);
Assert.True(client.Initialized);
Assert.Equal(_otherUser.Key, client.Context.Key); // don't compare entire user, because SDK may have added device/os attributes
Assert.Equal(_otherUser.FullyQualifiedKey, client.Context.FullyQualifiedKey); // don't compare entire user, because SDK may have added device/os attributes

var req2 = VerifyRequest(server.Recorder, mode);
Assert.NotEqual(user1RequestPath, req2.Path);
Expand Down Expand Up @@ -211,7 +211,7 @@ public async Task IdentifySwitchesUserAndGetsFlagsAsync(UpdateMode mode)
var success = await client.IdentifyAsync(_otherUser);
Assert.True(success);
Assert.True(client.Initialized);
Assert.Equal(_otherUser.Key, client.Context.Key); // don't compare entire user, because SDK may have added device/os attributes
Assert.Equal(_otherUser.FullyQualifiedKey, client.Context.FullyQualifiedKey); // don't compare entire user, because SDK may have added device/os attributes

var req2 = VerifyRequest(server.Recorder, mode);
Assert.NotEqual(user1RequestPath, req2.Path);
Expand Down
8 changes: 4 additions & 4 deletions tests/LaunchDarkly.ClientSdk.Tests/LdClientEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void TrackSendsCustomEvent()
e => {
CustomEvent ce = Assert.IsType<CustomEvent>(e);
Assert.Equal("eventkey", ce.EventKey);
Assert.Equal(user.Key, ce.Context.Key);
Assert.Equal(user.FullyQualifiedKey, ce.Context.FullyQualifiedKey);
Assert.Equal(LdValue.Null, ce.Data);
Assert.Null(ce.MetricValue);
Assert.NotEqual(0, ce.Timestamp.Value);
Expand All @@ -68,7 +68,7 @@ public void TrackWithDataSendsCustomEvent()
e => {
CustomEvent ce = Assert.IsType<CustomEvent>(e);
Assert.Equal("eventkey", ce.EventKey);
Assert.Equal(user.Key, ce.Context.Key);
Assert.Equal(user.FullyQualifiedKey, ce.Context.FullyQualifiedKey);
Assert.Equal(data, ce.Data);
Assert.Null(ce.MetricValue);
Assert.NotEqual(0, ce.Timestamp.Value);
Expand All @@ -89,7 +89,7 @@ public void TrackWithMetricValueSendsCustomEvent()
e => {
CustomEvent ce = Assert.IsType<CustomEvent>(e);
Assert.Equal("eventkey", ce.EventKey);
Assert.Equal(user.Key, ce.Context.Key);
Assert.Equal(user.FullyQualifiedKey, ce.Context.FullyQualifiedKey);
Assert.Equal(data, ce.Data);
Assert.Equal(metricValue, ce.MetricValue);
Assert.NotEqual(0, ce.Timestamp.Value);
Expand Down Expand Up @@ -336,7 +336,7 @@ public void VariationSendsFeatureEventWithReasonForUnknownFlagWhenClientIsNotIni
private void CheckIdentifyEvent(object e, Context c)
{
IdentifyEvent ie = Assert.IsType<IdentifyEvent>(e);
Assert.Equal(c.Key, ie.Context.Key);
Assert.Equal(c.FullyQualifiedKey, ie.Context.FullyQualifiedKey);
Assert.NotEqual(0, ie.Timestamp.Value);
}
}
Expand Down
30 changes: 15 additions & 15 deletions tests/LaunchDarkly.ClientSdk.Tests/LdClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async Task InitWithAnonUserAddsRandomizedKey()

using (var client = await TestUtil.CreateClientAsync(config, AnonUser))
{
key1 = client.Context.Key;
key1 = client.Context.FullyQualifiedKey;
Assert.NotNull(key1);
Assert.NotEqual("", key1);
AssertHelpers.ContextsEqual(
Expand All @@ -77,7 +77,7 @@ public async Task InitWithAnonUserAddsRandomizedKey()
// Starting again should generate a new key, since we've turned off persistence
using (var client = await TestUtil.CreateClientAsync(config, AnonUser))
{
var key2 = client.Context.Key;
var key2 = client.Context.FullyQualifiedKey;
Assert.NotNull(key2);
Assert.NotEqual("", key2);
Assert.NotEqual(key1, key2);
Expand Down Expand Up @@ -112,7 +112,7 @@ public async Task InitWithAnonUserCanReusePreviousRandomizedKey()

using (var client = await TestUtil.CreateClientAsync(config, AnonUser))
{
key1 = client.Context.Key;
key1 = client.Context.FullyQualifiedKey;
Assert.NotNull(key1);
Assert.NotEqual("", key1);
AssertHelpers.ContextsEqual(
Expand All @@ -123,7 +123,7 @@ public async Task InitWithAnonUserCanReusePreviousRandomizedKey()
// Starting again should reuse the persisted key
using (var client = await TestUtil.CreateClientAsync(config, AnonUser))
{
Assert.Equal(key1, client.Context.Key);
Assert.Equal(key1, client.Context.FullyQualifiedKey);
AssertHelpers.ContextsEqual(
Context.BuilderFromContext(AnonUser).Key(key1).Build(),
client.Context);
Expand All @@ -147,7 +147,7 @@ public async void InitWithAnonUserPassesGeneratedUserToDataSource()
Assert.NotEqual(AnonUser, receivedContext);
Assert.Equal(client.Context, receivedContext);
AssertHelpers.ContextsEqual(
Context.BuilderFromContext(AnonUser).Key(receivedContext.Key).Build(),
Context.BuilderFromContext(AnonUser).Key(receivedContext.FullyQualifiedKey).Build(),
receivedContext);
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public async void InitWithAutoEnvAttributesDisabledNoAddedContexts()
Assert.NotEqual(AnonUser, receivedContext);
Assert.Equal(client.Context, receivedContext);
AssertHelpers.ContextsEqual(
Context.BuilderFromContext(AnonUser).Key(receivedContext.Key).Build(),
Context.BuilderFromContext(AnonUser).Key(receivedContext.FullyQualifiedKey).Build(),
receivedContext);
}
}
Expand All @@ -200,7 +200,7 @@ public void IdentifyUpdatesTheUser()
var updatedUser = Context.New("some new key");
var success = client.Identify(updatedUser, TimeSpan.FromSeconds(1));
Assert.True(success);
Assert.Equal(client.Context.Key, updatedUser.Key); // don't compare entire user, because SDK may have added device/os attributes
Assert.Equal(client.Context.FullyQualifiedKey, updatedUser.FullyQualifiedKey); // don't compare entire user, because SDK may have added device/os attributes
}
}

Expand Down Expand Up @@ -230,7 +230,7 @@ private async Task IdentifyCompletesOnlyWhenNewFlagsAreAvailable(Func<LdClient,
var dataSourceFactory = MockComponents.ComponentConfigurerFromLambda<IDataSource>(ctx =>
new MockDataSourceFromLambda(ctx.CurrentContext, async () =>
{
switch (ctx.CurrentContext.Key)
switch (ctx.CurrentContext.FullyQualifiedKey)
{
case "a":
ctx.DataSourceUpdateSink.Init(ctx.CurrentContext, userAFlags);
Expand Down Expand Up @@ -308,7 +308,7 @@ public async Task IdentifyWithAnonUserAddsRandomizedKey()
{
await client.IdentifyAsync(AnonUser);

key1 = client.Context.Key;
key1 = client.Context.FullyQualifiedKey;
Assert.NotNull(key1);
Assert.NotEqual("", key1);
AssertHelpers.ContextsEqual(
Expand All @@ -317,7 +317,7 @@ public async Task IdentifyWithAnonUserAddsRandomizedKey()

var anonUser2 = TestUtil.BuildAutoContext().Name("other").Build();
await client.IdentifyAsync(anonUser2);
var key2 = client.Context.Key;
var key2 = client.Context.FullyQualifiedKey;
Assert.Equal(key1, key2); // Even though persistence is disabled, the key is stable during the lifetime of the SDK client.
AssertHelpers.ContextsEqual(
Context.BuilderFromContext(anonUser2).Key(key2).Build(),
Expand All @@ -328,7 +328,7 @@ public async Task IdentifyWithAnonUserAddsRandomizedKey()
{
await client.IdentifyAsync(AnonUser);

var key3 = client.Context.Key;
var key3 = client.Context.FullyQualifiedKey;
Assert.NotNull(key3);
Assert.NotEqual("", key3);
Assert.NotEqual(key1, key3); // The previously generated key was discarded with the previous client.
Expand Down Expand Up @@ -365,7 +365,7 @@ public async Task IdentifyWithAnonUserCanReusePersistedRandomizedKey()
{
await client.IdentifyAsync(AnonUser);

key1 = client.Context.Key;
key1 = client.Context.FullyQualifiedKey;
Assert.NotNull(key1);
Assert.NotEqual("", key1);
AssertHelpers.ContextsEqual(
Expand All @@ -377,7 +377,7 @@ public async Task IdentifyWithAnonUserCanReusePersistedRandomizedKey()
{
await client.IdentifyAsync(AnonUser);

var key2 = client.Context.Key;
var key2 = client.Context.FullyQualifiedKey;
Assert.Equal(key1, key2);
AssertHelpers.ContextsEqual(
Context.BuilderFromContext(AnonUser).Key(key2).Build(),
Expand All @@ -404,7 +404,7 @@ public async void IdentifyWithAnonUserPassesGeneratedUserToDataSource()
Assert.NotEqual(AnonUser, receivedContext);
Assert.Equal(client.Context, receivedContext);
AssertHelpers.ContextsEqual(
Context.BuilderFromContext(AnonUser).Key(client.Context.Key).Build(),
Context.BuilderFromContext(AnonUser).Key(client.Context.FullyQualifiedKey).Build(),
receivedContext);
}
}
Expand Down Expand Up @@ -448,7 +448,7 @@ public async void IdentifyWithAutoEnvAttributesDisabledNoAddedContexts()
Assert.NotEqual(AnonUser, receivedContext);
Assert.Equal(client.Context, receivedContext);
AssertHelpers.ContextsEqual(
Context.BuilderFromContext(AnonUser).Key(receivedContext.Key).Build(),
Context.BuilderFromContext(AnonUser).Key(receivedContext.FullyQualifiedKey).Build(),
receivedContext);
}
}
Expand Down

0 comments on commit 8282b56

Please sign in to comment.