diff --git a/bindings/zig/src/opendal.zig b/bindings/zig/src/opendal.zig index 9ff46d70f170..248c1527a8b1 100644 --- a/bindings/zig/src/opendal.zig +++ b/bindings/zig/src/opendal.zig @@ -422,28 +422,28 @@ test "operator advanced operations" { } // TODO: test async operations - crash application -// test "async operations" { -// const coro = @import("libcoro"); -// -// const allocator = std.testing.allocator; -// const stack = try coro.stackAlloc(allocator, null); -// defer allocator.free(stack); +test "async operations" { + const coro = @import("libcoro"); -// var op = try Operator.init("memory", null); -// defer op.deinit(); + const allocator = std.testing.allocator; + const stack = try coro.stackAlloc(allocator, null); + defer allocator.free(stack); -// const data = "hello world"; + var op = try Operator.init("memory", null); + defer op.deinit(); -// const write_frame = try coro.xasync(writeData, .{ &op, "/test", data }, stack); -// defer write_frame.deinit(); + const data = "hello world"; -// const read_frame = try coro.xasync(readData, .{ &op, "/test" }, stack); -// defer read_frame.deinit(); + const write_frame = try coro.xasync(writeData, .{ &op, "/test", data }, stack); + defer write_frame.deinit(); -// try coro.xawait(write_frame); -// const read_bytes = try coro.xawait(read_frame); -// try testing.expectEqualStrings(read_bytes, data); -// } + const read_frame = try coro.xasync(readData, .{ &op, "/test" }, stack); + defer read_frame.deinit(); + + try coro.xawait(write_frame); + const read_bytes = try coro.xawait(read_frame); + try testing.expectEqualStrings(read_bytes, data); +} fn writeData(op: *Operator, path: []const u8, data: []const u8) anyerror!void { try op.write(path, data);