-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle ResetRuntimeContext called concurrently.
- Loading branch information
1 parent
7e37d51
commit 454b5fa
Showing
4 changed files
with
185 additions
and
62 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
85 changes: 85 additions & 0 deletions
85
Package/Tests/CoreTests/Concurrency/MiscellaneousAsyncConcurrencyTests.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,85 @@ | ||
#if !UNITY_WEBGL | ||
|
||
using NUnit.Framework; | ||
using Proto.Promises; | ||
using Proto.Promises.Threading; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
|
||
#pragma warning disable CS0219 // The variable is assigned but its value is never used. | ||
|
||
namespace ProtoPromiseTests.Concurrency | ||
{ | ||
public class MiscellaneousAsyncConcurrencyTests | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
TestHelper.Setup(); | ||
} | ||
|
||
[TearDown] | ||
public void Teardown() | ||
{ | ||
TestHelper.Cleanup(); | ||
} | ||
|
||
public enum ContinuationType | ||
{ | ||
ContinueWith, | ||
Await | ||
} | ||
|
||
[Test] | ||
public void ResetRuntimeContext_SuppressesUnhandledExceptions_Concurrent() | ||
{ | ||
var threadHelper = new ThreadHelper(); | ||
threadHelper.ExecuteParallelActionsWithOffsets(true, | ||
//setup: | ||
() => { }, | ||
//teardown: | ||
() => { }, | ||
// actions: | ||
#if UNITY_2021_2_OR_NEWER || NETSTANDARD2_1_OR_GREATER || NETCOREAPP | ||
() => | ||
{ | ||
var asyncLock = new AsyncLock(); | ||
var key = asyncLock.Lock(); | ||
var keyPromise = asyncLock.LockAsync(); | ||
Promise.Manager.ResetRuntimeContext(); | ||
}, | ||
#endif | ||
() => | ||
{ | ||
var cancelationSource = CancelationSource.New(); | ||
Promise.Manager.ResetRuntimeContext(); | ||
}, | ||
() => CancelationSource.New().Dispose(), | ||
() => | ||
{ | ||
var deferred = Promise.NewDeferred(); | ||
deferred.Resolve(); | ||
var promise = deferred.Promise; | ||
promise.Then(() => { }).Forget(); | ||
try | ||
{ | ||
promise.Then(() => { }); | ||
} | ||
catch (System.InvalidOperationException) | ||
{ | ||
} | ||
}, | ||
() => | ||
{ | ||
var deferred = Promise.NewDeferred(); | ||
var promise = deferred.Promise.Then(() => { }); | ||
Promise.Manager.ResetRuntimeContext(); | ||
}, | ||
() => Promise.Manager.ResetRuntimeContext() | ||
); | ||
} | ||
} | ||
} | ||
|
||
#endif // !UNITY_WEBGL |
11 changes: 11 additions & 0 deletions
11
Package/Tests/CoreTests/Concurrency/MiscellaneousAsyncConcurrencyTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.