Compare commits

...

4 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire 486446cb6b Unit tests
- Make type check explicit
2023-06-29 17:29:07 +02:00
Tristan B. Velloza Kildaire eaaa879959 Unit tests
- Added `notifyAll()` positive-failure test for a disposed event
2023-06-29 17:26:52 +02:00
Tristan B. Velloza Kildaire a7f5917cc2 Unit tests
- Cleaned up redundant assertion
2023-06-29 17:25:35 +02:00
Tristan B. Velloza Kildaire 115cb73e4b Event
- Now if the resource is disposed we throw an exception

Unit tests

- test notifying a disposed event
2023-06-29 17:25:16 +02:00
1 changed files with 43 additions and 2 deletions

View File

@ -465,7 +465,17 @@ public class Event
/* Write a single byte to it */
byte wakeByte = 69;
write(pipeWriteEnd, &wakeByte, 1); // TODO: Collect status and if bad, unlock, throw exception
long status = write(pipeWriteEnd, &wakeByte, 1);
version(unittest)
{
writeln("write status: ", status);
}
/* On error writing */
if(status == -1)
{
throw new FatalException(this, FatalError.NOTIFY_FAILURE, "Cannot notify this thread, resource unavailable - event disposed maybe?");
}
}
/* If the thread provided is NOT wait()-ing on this event */
else
@ -724,5 +734,36 @@ unittest
/* Ensure that we got an exception */
assert(foundException !is null);
// assert(foundE) TODO: Add further specificty checks
assert(cast(FatalException)foundException);
/* We should not be able to notify */
try
{
event.notify(thread1);
assert(false);
}
catch(FatalException e)
{
assert(e.getFatalType() == FatalError.NOTIFY_FAILURE);
}
catch(SnoozeError)
{
assert(false);
}
/* We should not be able to notifyAll() */
try
{
event.notifyAll();
assert(false);
}
catch(FatalException e)
{
assert(e.getFatalType() == FatalError.NOTIFY_FAILURE);
}
catch(SnoozeError)
{
assert(false);
}
}