Skip to content

Commit

Permalink
Add socket test using fibers
Browse files Browse the repository at this point in the history
  • Loading branch information
skoppe committed Aug 21, 2024
1 parent 3467493 commit 517b863
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/ut/concurrency/io.d
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ unittest {
}

@safe
@("acceptAsync.connectAsync")
@("acceptAsync.connectAsync.basic")
unittest {
import concurrency.io.socket;
auto fd = listenTcp("127.0.0.1", 0);
Expand All @@ -70,3 +70,28 @@ unittest {
closeSocket(socket);
closeSocket(fd);
}

@safe
@("acceptAsync.connectAsync.fiber")
unittest {
import concurrency.io.socket;
import concurrency.fiber;

auto io = IOContext.construct(12);
io.run(fiber({
auto fd = listenTcp("127.0.0.1", 0);
auto socket = tcpSocket();
auto port = fd.getPort();

auto result = whenAll(
acceptAsync(fd),
connectAsync(socket, "127.0.0.1", port),
).yield().value;

auto client = result[0];

closeSocket(client.fd);
closeSocket(socket);
closeSocket(fd);
})).syncWait.assumeOk;
}

0 comments on commit 517b863

Please sign in to comment.