Skip to content

Commit e1cfdfe

Browse files
author
Test
committed
remove tests that did not add any value and where causing other tests to fail randomly
1 parent f1c0897 commit e1cfdfe

3 files changed

Lines changed: 21 additions & 33 deletions

File tree

‎src/Samples/TestStack.BDDfy.Samples/CanRunAsyncSteps.cs‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace TestStack.BDDfy.Samples
77
{
88
public class CanRunAsyncSteps
99
{
10-
private Sut _sut;
10+
private object _sut;
1111

1212
internal async void GivenSomeAsyncSetup()
1313
{
@@ -25,23 +25,19 @@ internal async void AndThenBddfyShouldCaptureExceptionsThrownInAsyncMethod()
2525
throw new Exception("Exception in async void method!!");
2626
}
2727

28-
private async Task<Sut> CreateSut()
28+
private static async Task<object> CreateSut()
2929
{
3030
await Task.Delay(500);
31-
return new Sut();
31+
return new object();
3232
}
3333

3434
[Fact]
3535
public void Run()
3636
{
3737
var engine = this.LazyBDDfy();
38-
var exception = Should.Throw<Exception>(() => engine.Run());
38+
var exception = Should.Throw<Exception>(engine.Run);
3939

4040
exception.Message.ShouldBe("Exception in async void method!!");
4141
}
42-
43-
internal class Sut
44-
{
45-
}
4642
}
4743
}

‎src/Samples/TestStack.BDDfy.Samples/CanRunAsyncVoidSteps.cs‎

Lines changed: 0 additions & 18 deletions
This file was deleted.

‎src/TestStack.BDDfy/Processors/AsyncTestSyncContext.cs‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,26 @@ namespace TestStack.BDDfy
88
/// </summary>
99
internal class AsyncTestSyncContext : SynchronizationContext
1010
{
11-
readonly ManualResetEvent _event = new(initialState: true);
11+
readonly object _lock = new();
1212
Exception _exception;
1313
int _operationCount;
1414

1515
public override void OperationCompleted()
1616
{
17-
var result = Interlocked.Decrement(ref _operationCount);
18-
if (result == 0)
19-
_event.Set();
17+
lock (_lock)
18+
{
19+
_operationCount--;
20+
if (_operationCount == 0)
21+
Monitor.PulseAll(_lock);
22+
}
2023
}
2124

2225
public override void OperationStarted()
2326
{
24-
Interlocked.Increment(ref _operationCount);
25-
_event.Reset();
27+
lock (_lock)
28+
{
29+
_operationCount++;
30+
}
2631
}
2732

2833
public override void Post(SendOrPostCallback d, object state)
@@ -59,7 +64,12 @@ public override void Send(SendOrPostCallback d, object state)
5964

6065
public Exception WaitForCompletion()
6166
{
62-
_event.WaitOne();
67+
lock (_lock)
68+
{
69+
while (_operationCount > 0)
70+
Monitor.Wait(_lock);
71+
}
72+
6373
return _exception;
6474
}
6575
}

0 commit comments

Comments
 (0)