Skip to content

Commit

Permalink
Enable enumeration of the keys and entries in RequestContext (#8674) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond committed Nov 11, 2023
1 parent 7980370 commit cd1aebc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Orleans.Core.Abstractions/Runtime/RequestContext.cs
Expand Up @@ -160,6 +160,16 @@ public static void Clear()
}
}

/// <summary>
/// Gets the collection of keys for the values currently in the request context.
/// </summary>
public static IEnumerable<string> Keys => CallContextData.Value.Values.Keys;

/// <summary>
/// Gets the collection of entries currently in the request context.
/// </summary>
public static IEnumerable<KeyValuePair<string, object>> Entries => CallContextData.Value.Values;

internal readonly struct ContextProperties
{
public Dictionary<string, object> Values { get; init; }
Expand Down
4 changes: 4 additions & 0 deletions test/DefaultCluster.Tests/RequestContextTest.cs
Expand Up @@ -21,6 +21,8 @@ public async Task RequestContextCallerToCalleeFlow()
var infoFromGrain = await grain.GetRequestContext();
Assert.NotNull(infoFromGrain);
Assert.True((int)infoFromGrain == 10);

Assert.Contains("GrainInfo", RequestContext.Keys);
}

[Fact(Skip = "Was failing before (just masked as a Pass), needs fixing or removing"), TestCategory("RequestContext"), TestCategory("Functional")]
Expand All @@ -33,6 +35,8 @@ public async Task RequestContextCalleeToCallerFlow()
var infoFromGrain = RequestContext.Get("GrainInfo");
Assert.NotNull(infoFromGrain);
Assert.True((int)infoFromGrain == 15);

Assert.Contains("GrainInfo", RequestContext.Keys);
}
}
}

0 comments on commit cd1aebc

Please sign in to comment.