Skip to content

Commit

Permalink
Use deterministic cancellation for this test.
Browse files Browse the repository at this point in the history
I think sometimes the connection is recieved and processes *after* the
next test has executed.
  • Loading branch information
alanmcgovern committed Jun 30, 2024
1 parent eccb5e2 commit 711137c
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,16 @@ public async Task Scrape_Incomplete ()
[Test]
public async Task Scrape_Timeout ()
{
var cancellation = new CancellationTokenSource ();
var tcs = new TaskCompletionSource<bool> ();
listener.ScrapeReceived += (o, e) => tcs.Task.Wait ();
listener.ScrapeReceived += (o, e) => {
cancellation.Cancel ();
tcs.Task.Wait ();
throw new InvalidOperationException ("Ensure this request isn't processed");
};

try {
var response = await tracker.ScrapeAsync (scrapeParams, new CancellationTokenSource (TimeSpan.FromMilliseconds (1)).Token).WithTimeout ();
var response = await tracker.ScrapeAsync (scrapeParams, cancellation.Token).WithTimeout ();
Assert.AreEqual (TrackerState.Offline, response.State);
} finally {
tcs.SetResult (true);
Expand Down

0 comments on commit 711137c

Please sign in to comment.