tests: make vlib/net/udp_test.v more stable, and less noisy on the tests-sanitize-address-gcc job
parent
d585fbea8a
commit
71dc6c224a
|
@ -1,22 +1,28 @@
|
||||||
import net
|
import net
|
||||||
|
import time
|
||||||
|
|
||||||
fn echo_server(mut c net.UdpConn) {
|
fn echo_server(mut c net.UdpConn) {
|
||||||
|
mut count := 0
|
||||||
for {
|
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 }
|
read, addr := c.read(mut buf) or { continue }
|
||||||
|
eprintln('Server got addr $addr, read: $read | buf: $buf')
|
||||||
println('Server got addr $addr')
|
|
||||||
|
|
||||||
c.write_to(addr, buf[..read]) or {
|
c.write_to(addr, buf[..read]) or {
|
||||||
println('Server: connection dropped')
|
println('Server: connection dropped')
|
||||||
return
|
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 (
|
const server_addr = '127.0.0.1:40003'
|
||||||
server_addr = '127.0.0.1:40003'
|
|
||||||
)
|
|
||||||
|
|
||||||
fn echo() ? {
|
fn echo() ? {
|
||||||
mut c := net.dial_udp(server_addr) or { panic('could not net.dial_udp: $err') }
|
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 {}
|
l.close() or {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
|
||||||
test_udp()
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue