Skip to content

Commit

Permalink
Add timeout to MockQueryFunction to detect deadlocks in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jcparkyn committed Apr 25, 2024
1 parent 11aad02 commit 2c8738c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/Phetch.Tests/MockQueryFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Phetch.Core;
Expand Down Expand Up @@ -33,6 +34,12 @@ public async Task<TResult> Query(TArg arg)
var resultTask = Sources[_queryCount].Task;
_queryCount++;
Calls.Add(arg);

if (!Debugger.IsAttached)
{
// Stop early if we're not debugging and it takes a while, we've probably forgotten to set a result before awaiting.
return await resultTask.WaitAsync(TimeSpan.FromSeconds(2));
}
return await resultTask;
}

Expand Down

0 comments on commit 2c8738c

Please sign in to comment.