ghostty/pkg/libuv/tests.zig
Mitchell Hashimoto 37b854f77c Revert "update libuv tests"
This reverts commit 2228675973b789a938c0d5e30b138f3e5d88121e.
2022-08-17 11:36:08 -07:00

38 lines
1.2 KiB
Zig

//! This file contains other behavior tests for the libuv integration.
//! We trust that libuv works, but still test some behaviors to ensure
//! that our wrappers around libuv are working as expected.
const std = @import("std");
const testing = std.testing;
const libuv = @import("main.zig");
test "Async: cancel timer" {
const alloc = testing.allocator;
var loop = try libuv.Loop.init(alloc);
defer loop.deinit(alloc);
var timer = try libuv.Timer.init(alloc, loop);
defer timer.deinit(alloc);
// Start a timer with a long timeout. This will block our loop.
try timer.start((struct {
fn callback(_: *libuv.Timer) void {}
}).callback, 5000, 5000);
var async_handle = try libuv.Async.init(testing.allocator, loop, (struct {
fn callback(v: *libuv.Async) void {
v.loop().stop();
v.close(null);
}
}).callback);
defer async_handle.deinit(testing.allocator);
try async_handle.send();
// This run through the loop should exit because we called loop stop.
_ = try loop.run(.default);
// We need to run the loop one more time to handle all our close callbacks.
timer.close(null);
_ = try loop.run(.default);
}