Skip to content

Commit 1616890

Browse files
committed
Fix BasicActivation_Reentrant_RecoveryAfterExpiredMessage flakiness
Use event-driven drain instead of fixed delay: - Reduce request count from 10 to 2 to keep processing time reasonable - Use GetLabel() as a barrier/drain operation instead of Task.Delay - Since TestGrain is non-reentrant, GetLabel() will block until all previously queued DoLongAction requests complete - This eliminates timing-dependent flakiness
1 parent 0246cc8 commit 1616890

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

test/DefaultCluster.Tests/BasicActivationTests.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,16 @@ public async Task BasicActivation_Reentrant_RecoveryAfterExpiredMessage()
282282
{
283283
// set short response time and ask to do long operation, to trigger expired msgs in the silo queues.
284284
TimeSpan shortTimeout = TimeSpan.FromMilliseconds(1000);
285+
TimeSpan longActionDuration = TimeSpan.FromMilliseconds(shortTimeout.TotalMilliseconds * 3);
285286
this.SetResponseTimeout(shortTimeout);
286287

287288
ITestGrain grain = this.GrainFactory.GetGrain<ITestGrain>(GetRandomGrainId());
288-
int num = 10;
289+
// Use only 2 requests to keep total processing time reasonable.
290+
// Since TestGrain is not reentrant, requests are processed sequentially.
291+
int num = 2;
289292
for (long i = 0; i < num; i++)
290293
{
291-
Task task = grain.DoLongAction(
292-
TimeSpan.FromMilliseconds(shortTimeout.TotalMilliseconds * 3),
293-
"A_" + i);
294+
Task task = grain.DoLongAction(longActionDuration, "A_" + i);
294295
promises.Add(task);
295296
}
296297
try
@@ -302,13 +303,15 @@ public async Task BasicActivation_Reentrant_RecoveryAfterExpiredMessage()
302303
this.Logger.LogInformation("Done with stress iteration.");
303304
}
304305

305-
// The messages have already expired since the timeout (1s) has passed
306-
// and Task.WhenAll has returned. A small delay ensures the silo has
307-
// processed the expirations before we send the next request.
308-
await Task.Delay(TimeSpan.FromSeconds(1));
309-
310-
// set the regular response time back, expect msgs ot succeed.
306+
// Restore the regular response timeout before draining.
311307
this.SetResponseTimeout(prevTimeout);
308+
309+
// Since TestGrain is non-reentrant, calling any method will block until
310+
// all previously queued requests complete. This acts as a barrier/drain
311+
// operation without needing fixed delays.
312+
this.Logger.LogInformation("Draining grain queue by calling GetLabel()...");
313+
await grain.GetLabel();
314+
this.Logger.LogInformation("Grain queue drained.");
312315

313316
this.Logger.LogInformation("About to send a next legit request that should succeed.");
314317
await grain.DoLongAction(TimeSpan.FromMilliseconds(1), "B_" + 0);

0 commit comments

Comments
 (0)