Skip to content

Commit

Permalink
Fixed assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Oct 15, 2024
1 parent 6032383 commit ed922c7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
9 changes: 4 additions & 5 deletions src/DotNext.Tests/Threading/AsyncExclusiveLockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ public static async Task MixedLock()
await using var l = new AsyncExclusiveLock();
True(await l.TryAcquireAsync(DefaultTimeout));

var t = Task.Factory.StartNew(() => True(l.TryAcquire(DefaultTimeout)), TaskCreationOptions.LongRunning);
var t = Task.Factory.StartNew(() => l.TryAcquire(DefaultTimeout), TaskCreationOptions.LongRunning);
l.Release();

await t;
True(await t);
False(l.TryAcquire());
l.Release();
}
Expand All @@ -209,10 +209,9 @@ public static async Task DisposedWhenSynchronousLockAcquired()
var l = new AsyncExclusiveLock();
True(l.TryAcquire());

var t = Task.Factory.StartNew(() => Throws<ObjectDisposedException>(() => l.TryAcquire(DefaultTimeout)),
TaskCreationOptions.LongRunning);
var t = Task.Factory.StartNew(() => l.TryAcquire(DefaultTimeout), TaskCreationOptions.LongRunning);

l.Dispose();
await t;
await ThrowsAsync<ObjectDisposedException>(Func.Constant(t));
}
}
19 changes: 8 additions & 11 deletions src/DotNext.Tests/Threading/AsyncReaderWriterLockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,10 @@ public static async Task DisposedWhenSynchronousReadLockAcquired()
var l = new AsyncReaderWriterLock();
True(l.TryEnterReadLock());

var t = Task.Factory.StartNew(() => Throws<ObjectDisposedException>(() => l.TryEnterWriteLock(DefaultTimeout)),
TaskCreationOptions.LongRunning);
var t = Task.Factory.StartNew(() => l.TryEnterWriteLock(DefaultTimeout), TaskCreationOptions.LongRunning);

l.Dispose();
await t;
await ThrowsAsync<ObjectDisposedException>(Func.Constant(t));
}

[Fact]
Expand All @@ -216,11 +215,10 @@ public static async Task DisposedWhenSynchronousWriteLockAcquired()
var l = new AsyncReaderWriterLock();
True(l.TryEnterWriteLock());

var t = Task.Factory.StartNew(() => Throws<ObjectDisposedException>(() => l.TryEnterReadLock(DefaultTimeout)),
TaskCreationOptions.LongRunning);
var t = Task.Factory.StartNew(() => l.TryEnterReadLock(DefaultTimeout), TaskCreationOptions.LongRunning);

l.Dispose();
await t;
await ThrowsAsync<ObjectDisposedException>(Func.Constant(t));
}

[Fact]
Expand All @@ -231,12 +229,12 @@ public static async Task AcquireReadWriteLockSynchronously()
True(l.TryEnterReadLock(DefaultTimeout));
Equal(2L, l.CurrentReadCount);

var t = Task.Factory.StartNew(() => True(l.TryEnterWriteLock(DefaultTimeout)), TaskCreationOptions.LongRunning);
var t = Task.Factory.StartNew(() => l.TryEnterWriteLock(DefaultTimeout), TaskCreationOptions.LongRunning);

l.Release();
l.Release();

await t;
True(await t);
True(l.IsWriteLockHeld);

l.Release();
Expand All @@ -253,10 +251,9 @@ public static async Task ResumeMultipleReadersSynchronously()
var t2 = Task.Factory.StartNew(TryEnterReadLock, TaskCreationOptions.LongRunning);

l.Release();
await Task.WhenAll(t1, t2);

Equal(new[] { true, true }, await Task.WhenAll(t1, t2));
Equal(2L, l.CurrentReadCount);

void TryEnterReadLock() => True(l.TryEnterReadLock(DefaultTimeout));
bool TryEnterReadLock() => l.TryEnterReadLock(DefaultTimeout);
}
}
15 changes: 7 additions & 8 deletions src/DotNext.Tests/Threading/AsyncResetEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public static async Task ManualResetEventSynchronousCompletion(IAsyncResetEvent
{
False(resetEvent.IsSet);

var t = Task.Factory.StartNew(() => True(resetEvent.Wait(DefaultTimeout)), TaskCreationOptions.LongRunning);
var t = Task.Factory.StartNew(() => resetEvent.Wait(DefaultTimeout), TaskCreationOptions.LongRunning);

True(resetEvent.Signal());
await t;
True(await t);
Equal(resetEvent.ResetMode is EventResetMode.ManualReset, resetEvent.IsSet);
}
}
Expand All @@ -142,10 +142,10 @@ public static void AlreadySignaledEvents(IAsyncResetEvent resetEvent)
public static async Task AutoResetOnSyncWait()
{
using var are = new AsyncAutoResetEvent(false);
var t = Task.Factory.StartNew(() => True(are.Wait(DefaultTimeout)), TaskCreationOptions.LongRunning);
var t = Task.Factory.StartNew(() => are.Wait(DefaultTimeout), TaskCreationOptions.LongRunning);
True(are.Set());

await t;
True(await t);
False(are.IsSet);
}

Expand All @@ -158,12 +158,11 @@ public static async Task ResumeSuspendedCallersSequentially()

True(are.Set());

await Task.WhenAny(t1, t2);
True(t1.IsCompleted ^ t2.IsCompleted);
True(await Task.WhenAny(t1, t2).Unwrap());

True(are.Set());
await Task.WhenAll(t1, t2);
Equal(new[] { true, true }, await Task.WhenAll(t1, t2));

void Wait() => True(are.Wait(DefaultTimeout));
bool Wait() => are.Wait(DefaultTimeout);
}
}

0 comments on commit ed922c7

Please sign in to comment.