tests: make vlib/net/udp_test.v more stable, and less noisy on the tests-sanitize-address-gcc job

pull/13911/head
Delyan Angelov 2022-04-02 20:00:03 +03:00
parent d585fbea8a
commit 71dc6c224a
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 13 additions and 11 deletions

View File

@ -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()
}