Skip to content

Commit 3c40541

Browse files
author
Sophia Tevosyan
committed
adding unit tests
1 parent a5252de commit 3c40541

File tree

4 files changed

+402
-6
lines changed

4 files changed

+402
-6
lines changed

src/Worker/Grpc/ExtendedSessionsCache.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void Dispose()
3030
/// This specifies how often the cache checks for stale items, and evicts them.
3131
/// </param>
3232
/// <returns>The IMemoryCache that holds the cached <see cref="ExtendedSessionState"/>.</returns>
33-
internal MemoryCache GetOrInitializeCache(double expirationScanFrequencyInSeconds)
33+
public MemoryCache GetOrInitializeCache(double expirationScanFrequencyInSeconds)
3434
{
3535
this.extendedSessions ??= new MemoryCache(new MemoryCacheOptions
3636
{
@@ -39,4 +39,13 @@ internal MemoryCache GetOrInitializeCache(double expirationScanFrequencyInSecond
3939

4040
return this.extendedSessions;
4141
}
42+
43+
/// <summary>
44+
/// Returns whether or not the cache has been initialized.
45+
/// </summary>
46+
/// <returns>True if the cache has been initialized, false otherwise.</returns>
47+
public bool IsInitialized()
48+
{
49+
return this.extendedSessions is not null;
50+
}
4251
}

src/Worker/Grpc/GrpcOrchestrationRunner.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,20 @@ public static string LoadAndRun(
175175
bool requiresHistory = false;
176176
double extendedSessionIdleTimeoutInSeconds = 0;
177177
MemoryCache? extendedSessions = null;
178-
179-
if (properties.TryGetValue("ExtendedSession", out object? isExtendedSessionObj)
180-
&& isExtendedSessionObj is bool isExtendedSession
181-
&& isExtendedSession
182-
&& properties.TryGetValue("ExtendedSessionIdleTimeoutInSeconds", out object? extendedSessionIdleTimeoutObj)
178+
179+
if (properties.TryGetValue("ExtendedSessionIdleTimeoutInSeconds", out object? extendedSessionIdleTimeoutObj)
183180
&& extendedSessionIdleTimeoutObj is double extendedSessionIdleTimeout
184181
&& extendedSessionIdleTimeout >= 0)
185182
{
186183
extendedSessionIdleTimeoutInSeconds = extendedSessionIdleTimeout;
187184
extendedSessions = extendedSessionsCache.GetOrInitializeCache(extendedSessionIdleTimeoutInSeconds);
185+
}
188186

187+
if (properties.TryGetValue("ExtendedSession", out object? isExtendedSessionObj)
188+
&& isExtendedSessionObj is bool isExtendedSession
189+
&& isExtendedSession
190+
&& extendedSessions != null)
191+
{
189192
if (extendedSessions.TryGetValue(request.InstanceId, out ExtendedSessionState? extendedSessionState) && extendedSessionState is not null)
190193
{
191194
OrchestrationRuntimeState runtimeState = extendedSessionState!.RuntimeState;

0 commit comments

Comments
 (0)