Skip to content

Use ManualResetEventSlim for waithandle in tests (+increase timeout) #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions test/Exceptionless.Tests/Storage/PersistedDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void WillBeSaved() {
dict.Saved += (sender, args) => resetEvent.Set();
dict["test"] = "test";
Assert.Equal("test", dict["test"]);
bool success = resetEvent.WaitOne(250);
bool success = resetEvent.WaitOne(500);
Assert.True(success, "Failed to save dictionary.");
Assert.True(storage.Exists("test.json"));
}
Expand All @@ -29,14 +29,14 @@ public void WillSaveOnce() {
for (int i = 0; i < 10; i++)
dict["test" + i] = i.ToString();
Assert.Equal(10, dict.Count);
bool success = latch.Wait(250);
bool success = latch.Wait(500);
Assert.False(success, "Dictionary was saved multiple times.");
Assert.Equal(1, latch.Remaining);
Assert.True(storage.Exists("test.json"));

dict["test"] = "test";
Assert.Equal(11, dict.Count);
success = latch.Wait(250);
success = latch.Wait(500);
Assert.True(success, "Failed to save dictionary.");
Assert.True(storage.Exists("test.json"));
}
Expand Down
6 changes: 3 additions & 3 deletions test/Exceptionless.Tests/Utility/CountDownLatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Exceptionless.Tests.Utility {
public class CountDownLatch {
private int _remaining;
private EventWaitHandle _event;
private ManualResetEventSlim _event;

public CountDownLatch(int count) {
Reset(count);
Expand All @@ -14,7 +14,7 @@ public void Reset(int count) {
if (count < 0)
throw new ArgumentOutOfRangeException();
_remaining = count;
_event = new ManualResetEvent(false);
_event = new ManualResetEventSlim(false);
if (_remaining == 0)
_event.Set();
}
Expand All @@ -26,7 +26,7 @@ public void Signal() {
}

public bool Wait(int millisecondsTimeout) {
return _event.WaitOne(millisecondsTimeout);
return _event.Wait(millisecondsTimeout);
}

public int Remaining { get { return _remaining; } }
Expand Down