test: Add spawn behavior test

This commit is contained in:
mochalins 2024-07-09 11:25:19 +09:00 committed by Jacob Young
parent 6446596ba1
commit c8e0095362
2 changed files with 22 additions and 0 deletions

View File

@ -1465,6 +1465,7 @@ test {
_ = Semaphore;
_ = Condition;
_ = RwLock;
_ = Pool;
}
fn testIncrementNotify(value: *usize, event: *ResetEvent) void {

View File

@ -254,6 +254,27 @@ pub fn spawn(pool: *Pool, comptime func: anytype, args: anytype) !void {
pool.cond.signal();
}
test spawn {
const TestFn = struct {
fn checkRun(completed: *bool) void {
completed.* = true;
}
};
var completed: bool = false;
{
var pool: Pool = undefined;
try pool.init(.{
.allocator = std.testing.allocator,
});
defer pool.deinit();
try pool.spawn(TestFn.checkRun, .{&completed});
}
try std.testing.expectEqual(true, completed);
}
fn worker(pool: *Pool) void {
pool.mutex.lock();
defer pool.mutex.unlock();