You've already forked linux-packaging-mono
Imported Upstream version 5.20.0.185
Former-commit-id: fcd643a64a9c5470917dbbb1be4ba228e5c14650
This commit is contained in:
parent
97f8185566
commit
f737def5f5
@ -491,6 +491,35 @@ namespace MonoTests.System.Threading
|
||||
c1.Dispose ();
|
||||
}
|
||||
}
|
||||
|
||||
[Test] // https://github.com/mono/mono/issues/12421
|
||||
public void EnsurePostIsNotCalled ()
|
||||
{
|
||||
SynchronizationContext mainContext = SynchronizationContext.Current;
|
||||
var asc = new AssertSyncContext ();
|
||||
SynchronizationContext.SetSynchronizationContext (asc);
|
||||
var ct = new CancellationTokenSource ();
|
||||
var tcs = new TaskCompletionSource<bool> ();
|
||||
ct.Token.Register (() => tcs.TrySetCanceled ());
|
||||
|
||||
bool taskIsCancelled = false;
|
||||
Action awaitAction = async () => {
|
||||
try { await tcs.Task; }
|
||||
catch (OperationCanceledException) {
|
||||
taskIsCancelled = true;
|
||||
}
|
||||
};
|
||||
awaitAction ();
|
||||
ct.Cancel (); // should not trigger SynchronizationContext.Post
|
||||
Assert.IsTrue (taskIsCancelled);
|
||||
SynchronizationContext.SetSynchronizationContext (mainContext);
|
||||
}
|
||||
|
||||
class AssertSyncContext : SynchronizationContext
|
||||
{
|
||||
public override void Post (SendOrPostCallback d, object state) =>
|
||||
throw new InvalidOperationException ("SynchronizationContext.Post was not expected.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user