-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/mrpmorris/Fluxor
- Loading branch information
Showing
7 changed files
with
120 additions
and
30 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
53 changes: 53 additions & 0 deletions
53
...or.UnitTests/StoreTests/ThreadingTests/DispatchReentrancyTests/DispatchReentrancyTests.cs
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,53 @@ | ||
using Fluxor.UnitTests.StoreTests.ThreadingTests.DispatchReentrancyTests.SupportFiles; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Fluxor.UnitTests.StoreTests.ThreadingTests.DispatchReentrancyTests | ||
{ | ||
public class DispatchReentrancyTests | ||
{ | ||
private readonly IDispatcher Dispatcher; | ||
private readonly IStore Subject; | ||
private readonly IFeature<CounterState> Feature; | ||
|
||
[Fact] | ||
public async Task WhenObserverSubscribesToAnAction_AndDispatchesAnActionFromANewThread_ThenThereShouldBeNoDeadlock() | ||
{ | ||
Thread initialThread = Thread.CurrentThread; | ||
Subject.SubscribeToAction<StoreInitializedAction>(this, _ => | ||
{ | ||
var thread = new Thread(() => | ||
{ | ||
Thread.Sleep(50); | ||
while (Thread.CurrentThread == initialThread) | ||
Thread.Sleep(0); | ||
|
||
Dispatcher.Dispatch(new IncrementCounterAction()); | ||
}); | ||
thread.Start(); | ||
thread.Join(); | ||
}); | ||
|
||
var timeout = Task.Delay(1000); | ||
var initialize = Task.Run(async () => | ||
{ | ||
await Task.Yield(); | ||
await Subject.InitializeAsync(); | ||
}); | ||
await Task.WhenAny(timeout, initialize); | ||
Assert.False(timeout.IsCompleted, "Time out due to deadlock"); | ||
} | ||
|
||
public DispatchReentrancyTests() | ||
{ | ||
Dispatcher = new Dispatcher(); | ||
Subject = new Store(Dispatcher); | ||
|
||
Feature = new CounterFeature(); | ||
Subject.AddFeature(Feature); | ||
} | ||
|
||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...nitTests/StoreTests/ThreadingTests/DispatchReentrancyTests/SupportFiles/CounterFeature.cs
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,8 @@ | ||
namespace Fluxor.UnitTests.StoreTests.ThreadingTests.DispatchReentrancyTests.SupportFiles | ||
{ | ||
class CounterFeature : Feature<CounterState> | ||
{ | ||
public override string GetName() => "Counter"; | ||
protected override CounterState GetInitialState() => new(counter: 0); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
....UnitTests/StoreTests/ThreadingTests/DispatchReentrancyTests/SupportFiles/CounterState.cs
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,13 @@ | ||
namespace Fluxor.UnitTests.StoreTests.ThreadingTests.DispatchReentrancyTests.SupportFiles | ||
{ | ||
public class CounterState | ||
{ | ||
public readonly int Counter; | ||
|
||
public CounterState(int counter) | ||
{ | ||
Counter = counter; | ||
} | ||
} | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
.../StoreTests/ThreadingTests/DispatchReentrancyTests/SupportFiles/IncrementCounterAction.cs
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,6 @@ | ||
namespace Fluxor.UnitTests.StoreTests.ThreadingTests.DispatchReentrancyTests.SupportFiles | ||
{ | ||
class IncrementCounterAction | ||
{ | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...UnitTests/StoreTests/ThreadingTests/DispatchReentrancyTests/SupportFiles/IsolatedTests.cs
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,6 @@ | ||
namespace Fluxor.UnitTests.StoreTests.ThreadingTests.DispatchReentrancyTests.SupportFiles | ||
{ | ||
public class IsolatedTests : Middleware | ||
{ | ||
} | ||
} |