-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f50d7a
commit ba94f7a
Showing
5 changed files
with
175 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace RazorBlade.Tests.Support; | ||
|
||
public class StepSemaphore | ||
{ | ||
private readonly SemaphoreSlim _semaphoreStartOfStep = new(0); | ||
private readonly SemaphoreSlim _semaphoreEndOfStep = new(0); | ||
private int _isFirstStep; | ||
|
||
public async Task WaitForNextStepAsync() | ||
{ | ||
if (Interlocked.Exchange(ref _isFirstStep, 1) != 0) | ||
_semaphoreEndOfStep.Release(); | ||
|
||
var result = await _semaphoreStartOfStep.WaitAsync(10_000); | ||
result.ShouldBeTrue(); | ||
} | ||
|
||
public Task NotifyEndOfLastStepAsync() | ||
{ | ||
_semaphoreEndOfStep.Release(); | ||
|
||
return Task.CompletedTask; // Just to make the API consistent | ||
} | ||
|
||
public async Task StartNextStepAndWaitForResultAsync() | ||
{ | ||
_semaphoreStartOfStep.Release(); | ||
|
||
var result = await _semaphoreEndOfStep.WaitAsync(10_000); | ||
result.ShouldBeTrue(); | ||
} | ||
} |