Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Oct 15, 2024
1 parent 68b0140 commit 99e0565
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/DotNext.Tests/Threading/AsyncReaderWriterLockTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public static void DisposedWhenSynchronousWriteLockAcquired()
[Fact]
public static void AcquireReadWriteLockSynchronously()
{
var l = new AsyncReaderWriterLock();
using var l = new AsyncReaderWriterLock();
True(l.TryEnterReadLock(DefaultTimeout));
True(l.TryEnterReadLock(DefaultTimeout));
Equal(2L, l.CurrentReadCount);
Expand All @@ -247,11 +247,11 @@ public static void AcquireReadWriteLockSynchronously()
[Fact]
public static void ResumeMultipleReadersSynchronously()
{
var l = new AsyncReaderWriterLock();
using var l = new AsyncReaderWriterLock();
True(l.TryEnterWriteLock());

var t1 = new Thread(() => True(l.TryEnterReadLock(DefaultTimeout))) { IsBackground = true };
var t2 = new Thread(() => True(l.TryEnterReadLock(DefaultTimeout))) { IsBackground = true };
var t1 = new Thread(TryEnterReadLock) { IsBackground = true };
var t2 = new Thread(TryEnterReadLock) { IsBackground = true };
t1.Start();
t2.Start();

Expand All @@ -260,5 +260,7 @@ public static void ResumeMultipleReadersSynchronously()
True(t2.Join(DefaultTimeout));

Equal(2L, l.CurrentReadCount);

void TryEnterReadLock() => True(l.TryEnterReadLock(DefaultTimeout));
}
}
11 changes: 11 additions & 0 deletions src/DotNext.Tests/Threading/AsyncResetEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,15 @@ public static void ManualResetEventSynchronousCompletion(IAsyncResetEvent resetE
Equal(resetEvent.ResetMode is EventResetMode.ManualReset, resetEvent.IsSet);
}
}

[Theory]
[MemberData(nameof(GetResetEvents))]
public static void AlreadySignaledEvents(IAsyncResetEvent resetEvent)
{
using (resetEvent)
{
True(resetEvent.Signal());
True(resetEvent.Wait(DefaultTimeout));
}
}
}

0 comments on commit 99e0565

Please sign in to comment.