Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/PatternKit.Generators.Tests/ObserverGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ public static async System.Threading.Tasks.Task<string> Run()
var demoType = asm.GetType("PatternKit.Examples.Generators.Demo");
var runMethod = demoType!.GetMethod("Run");
var task = (System.Threading.Tasks.Task<string>)runMethod!.Invoke(null, null)!;
task.Wait();
if (!task.Wait(TimeSpan.FromSeconds(30)))
throw new TimeoutException("Demo.Run() did not complete within 30 seconds.");
var result = task.Result;
Assert.Equal("AsyncHandler:42", result);
}
Expand Down Expand Up @@ -629,7 +630,7 @@ public static async System.Threading.Tasks.Task<string> Run()
evt.Publish(new Temperature(10));

// Wait deterministically for async handler to complete
await tcs.Task.WaitAsync(System.TimeSpan.FromSeconds(5));
await tcs.Task.WaitAsync(System.TimeSpan.FromSeconds(30));

return string.Join("|", log);
}
Expand All @@ -655,7 +656,8 @@ public static async System.Threading.Tasks.Task<string> Run()
var demoType = asm.GetType("PatternKit.Examples.Generators.Demo");
var runMethod = demoType!.GetMethod("Run");
var task = (System.Threading.Tasks.Task<string>)runMethod!.Invoke(null, null)!;
task.Wait();
if (!task.Wait(TimeSpan.FromSeconds(30)))
throw new TimeoutException("Demo.Run() did not complete within 30 seconds.");
var result = task.Result;

// Both handlers should have been invoked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ public Task Serializes_When_Synchronized()
[Fact]
public async Task Cancellation_Observed()
{
var template = new SampleAsyncTemplate(delayMs: 100);
using var cts = new CancellationTokenSource(10);
// Use a long delay with a pre-cancelled token to avoid timing races
var template = new SampleAsyncTemplate(delayMs: 5000);
using var cts = new CancellationTokenSource();
cts.Cancel(); // pre-cancel so cancellation is immediate and deterministic

// Assert.ThrowsAnyAsync verifies that OperationCanceledException or derived types are thrown
await Assert.ThrowsAnyAsync<OperationCanceledException>(
Expand Down
Loading