mirror of
https://github.com/osukey/osukey.git
synced 2025-05-30 01:47:30 +09:00
Revert test changes to test original class/scope
Importantly, this removes the call to CatchUnobservedExceptions(), which was outright incorrect (awaiting on the wrong task as a result) in the original test code.
This commit is contained in:
parent
1ec305e10d
commit
c3aec3bfe4
@ -1,28 +1,25 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Game.Extensions;
|
using osu.Game.Utils;
|
||||||
|
|
||||||
namespace osu.Game.Tests.NonVisual
|
namespace osu.Game.Tests.NonVisual
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TaskChainTest
|
public class TaskChainTest
|
||||||
{
|
{
|
||||||
private Task taskChain;
|
private TaskChain taskChain;
|
||||||
|
|
||||||
private int currentTask;
|
private int currentTask;
|
||||||
private CancellationTokenSource globalCancellationToken;
|
private CancellationTokenSource globalCancellationToken;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
taskChain = Task.CompletedTask;
|
|
||||||
|
|
||||||
globalCancellationToken = new CancellationTokenSource();
|
globalCancellationToken = new CancellationTokenSource();
|
||||||
|
taskChain = new TaskChain();
|
||||||
currentTask = 0;
|
currentTask = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,16 +78,7 @@ namespace osu.Game.Tests.NonVisual
|
|||||||
{
|
{
|
||||||
var mutex = new ManualResetEventSlim(false);
|
var mutex = new ManualResetEventSlim(false);
|
||||||
|
|
||||||
var task = taskChain.ContinueWithSequential(async () =>
|
var task = taskChain.Add(async () => await Task.Run(() => mutex.Wait(globalCancellationToken.Token)));
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await Task.Run(() => mutex.Wait(globalCancellationToken.Token));
|
|
||||||
}
|
|
||||||
catch (OperationCanceledException)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Allow task to potentially complete
|
// Allow task to potentially complete
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
@ -111,7 +99,7 @@ namespace osu.Game.Tests.NonVisual
|
|||||||
var cancellationSource = new CancellationTokenSource();
|
var cancellationSource = new CancellationTokenSource();
|
||||||
var token = CancellationTokenSource.CreateLinkedTokenSource(cancellationSource.Token, globalCancellationToken.Token);
|
var token = CancellationTokenSource.CreateLinkedTokenSource(cancellationSource.Token, globalCancellationToken.Token);
|
||||||
|
|
||||||
taskChain = taskChain.ContinueWithSequential(() =>
|
taskChain.Add(() =>
|
||||||
{
|
{
|
||||||
mutex.Wait(globalCancellationToken.Token);
|
mutex.Wait(globalCancellationToken.Token);
|
||||||
completionSource.SetResult(Interlocked.Increment(ref currentTask));
|
completionSource.SetResult(Interlocked.Increment(ref currentTask));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user