diff --git a/vlib/net/udp_test.v b/vlib/net/udp_test.v index a05121e576..fc1a193a0d 100644 --- a/vlib/net/udp_test.v +++ b/vlib/net/udp_test.v @@ -1,22 +1,28 @@ import net +import time fn echo_server(mut c net.UdpConn) { + mut count := 0 for { - mut buf := []byte{len: 100, init: 0} + eprintln('> echo_server loop count: $count') + mut buf := []byte{len: 100} read, addr := c.read(mut buf) or { continue } - - println('Server got addr $addr') - + eprintln('Server got addr $addr, read: $read | buf: $buf') c.write_to(addr, buf[..read]) or { println('Server: connection dropped') return } + count++ + // Normally, after responding, the test will end, but there are sometimes cases, + // when the echo_server continued looping, printing messages constantly. + // The sleep here, is a small precaution against spamming the CI with log messages, + // when there are network problems, and it allows easier root cause diagnostic, when + // they do happen: + time.sleep(1000 * time.millisecond) } } -const ( - server_addr = '127.0.0.1:40003' -) +const server_addr = '127.0.0.1:40003' fn echo() ? { mut c := net.dial_udp(server_addr) or { panic('could not net.dial_udp: $err') } @@ -53,7 +59,3 @@ fn test_udp() { l.close() or {} } - -fn main() { - test_udp() -}