Unit tests

- Added a unit test for timeouts
This commit is contained in:
Tristan B. Velloza Kildaire 2023-02-26 17:06:01 +02:00
parent ee745a4db6
commit 7a69537ebe
1 changed files with 31 additions and 0 deletions

View File

@ -335,4 +335,35 @@ unittest
{
assert(true);
}
}
unittest
{
Event event = new Event();
class TestThread : Thread
{
private Event event;
this(Event event)
{
super(&worker);
this.event = event;
}
public void worker()
{
writeln("("~to!(string)(Thread.getThis().id())~") Thread is waiting...");
/* Here we test timeout, we never notify so this should timeout and return false */
assert(event.wait(dur!("seconds")(2)) == false);
writeln("("~to!(string)(Thread.getThis().id())~") Thread is waiting... [done]");
}
}
TestThread thread1 = new TestThread(event);
thread1.start();
/* Wait for the thread to exit */
thread1.join();
}