mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
test: Add spawn behavior test
This commit is contained in:
parent
6446596ba1
commit
c8e0095362
@ -1465,6 +1465,7 @@ test {
|
||||
_ = Semaphore;
|
||||
_ = Condition;
|
||||
_ = RwLock;
|
||||
_ = Pool;
|
||||
}
|
||||
|
||||
fn testIncrementNotify(value: *usize, event: *ResetEvent) void {
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user