authorgravatar for kenta@lithdew.netlithdew <kenta@lithdew.net> 2021-05-02 16:50:56+09:00
committergravatar for kenta@lithdew.netlithdew <kenta@lithdew.net> 2021-05-03 14:49:10+09:00
loga799ad05b37c4b04f73ad79f9e3c67c4036138ec
treed8f78a9c624b4e70e217100e520029d45bc9e113
parentaa15699269b416f46f3c10469d842b930ac26fc9

x/net/tcp: make tcp tests blocking to avoid unit test races


1 files changed, 5 insertions(+), 6 deletions(-)

lib/std/x/net/tcp.zig+5-6
...@@ -316,10 +316,10 @@ pub const Listener = struct {...@@ -316,10 +316,10 @@ pub const Listener = struct {
316 }316 }
317};317};
318318
319test "tcp: create non-blocking pair" {319test "tcp: create client/listener pair" {
320 if (builtin.os.tag == .wasi) return error.SkipZigTest;320 if (builtin.os.tag == .wasi) return error.SkipZigTest;
321321
322 const listener = try tcp.Listener.init(.ip, os.SOCK_NONBLOCK | os.SOCK_CLOEXEC);322 const listener = try tcp.Listener.init(.ip, os.SOCK_CLOEXEC);
323 defer listener.deinit();323 defer listener.deinit();
324324
325 try listener.bind(tcp.Address.initIPv4(IPv4.unspecified, 0));325 try listener.bind(tcp.Address.initIPv4(IPv4.unspecified, 0));
...@@ -327,13 +327,12 @@ test "tcp: create non-blocking pair" {...@@ -327,13 +327,12 @@ test "tcp: create non-blocking pair" {
327327
328 const binded_address = try listener.getLocalAddress();328 const binded_address = try listener.getLocalAddress();
329329
330 const client = try tcp.Client.init(.ip, os.SOCK_NONBLOCK | os.SOCK_CLOEXEC);330 const client = try tcp.Client.init(.ip, os.SOCK_CLOEXEC);
331 defer client.deinit();331 defer client.deinit();
332332
333 testing.expectError(error.WouldBlock, client.connect(binded_address));333 try client.connect(binded_address);
334 try client.getError();
335334
336 const conn = try listener.accept(os.SOCK_NONBLOCK | os.SOCK_CLOEXEC);335 const conn = try listener.accept(os.SOCK_CLOEXEC);
337 defer conn.deinit();336 defer conn.deinit();
338}337}
339338