Skip to content

Commit

Permalink
Use waithandle instead of Thread.Sleep. Fixes a race condition in run…
Browse files Browse the repository at this point in the history
…ning tests on Mono
  • Loading branch information
statianzo committed Jun 23, 2011
1 parent d1c827f commit 68518a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ _ReSharper.*
*.suo
*.userprefs
test-results
*.pidb
TestResult.xml
11 changes: 7 additions & 4 deletions src/Fleck.Tests/ReceiverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@ public class ReceiverTests
private bool _wasClosed;
private Mock<ISocket> _mockSocket;
private Receiver _receiver;
private string _message;
private EventWaitHandle _closeHandle;

[SetUp]
public void Setup()
{
_message = null;
_wasClosed = false;
_mockSocket = new Mock<ISocket>();
_receiver = new Receiver(_mockSocket.Object,s => _message = s, () => _wasClosed = true);
_closeHandle = new EventWaitHandle(false,EventResetMode.ManualReset);
_receiver = new Receiver(_mockSocket.Object,s => {}, () => {
_wasClosed = true;
_closeHandle.Set();
});
}

[Test]
Expand Down Expand Up @@ -52,7 +55,7 @@ public void ShouldCloseOnException()
.Throws<Exception>()
.Verifiable();
_receiver.Receive();
Thread.Sleep(100);
_closeHandle.WaitOne();
_mockSocket.Verify();
Assert.IsTrue(_wasClosed);
}
Expand Down

0 comments on commit 68518a8

Please sign in to comment.