-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding basic support for calling subs from multiple threads
Adding acceptance test for calling from multiple threads. Updated SubstituteContext to use ThreadLocal<T> from Rx. Added reference to System.Threading distributed with Microsoft's Reacive Extensions (Rx) framework for .NET 3.5. Adding Rx to acknowledgements.
- Loading branch information
Showing
9 changed files
with
19,970 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using System.Threading; | ||
using NUnit.Framework; | ||
|
||
namespace NSubstitute.Acceptance.Specs | ||
{ | ||
public class MultipleThreads | ||
{ | ||
[Test] | ||
public void CallFromMultipleThreads() | ||
{ | ||
var firstSub = Substitute.For<IFoo>(); | ||
var secondSub = Substitute.For<IFoo>(); | ||
|
||
using (var interrupted = new AutoResetEvent(false)) | ||
{ | ||
|
||
var initialThread = new Thread(() => | ||
{ | ||
firstSub.Number(); | ||
if (!interrupted.WaitOne(TimeSpan.FromSeconds(1))) Assert.Fail("Timed out waiting for interrupt"); | ||
1.Returns(1); | ||
}); | ||
var interruptingThread = new Thread(() => | ||
{ | ||
secondSub.Number().Returns(2); | ||
interrupted.Set(); | ||
}); | ||
|
||
initialThread.Start(); | ||
interruptingThread.Start(); | ||
|
||
initialThread.Join(); | ||
interruptingThread.Join(); | ||
} | ||
|
||
Assert.That(firstSub.Number(), Is.EqualTo(1)); | ||
Assert.That(secondSub.Number(), Is.EqualTo(2)); | ||
} | ||
|
||
public interface IFoo | ||
{ | ||
int Number(); | ||
} | ||
} | ||
} |
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
Binary file not shown.
Oops, something went wrong.