tests: add retry logic in simple_tcp_client in vweb_test.v
parent
1619beda91
commit
7b7ab580ab
vlib/vweb/tests
|
@ -226,6 +226,7 @@ fn testsuite_end() {
|
||||||
|
|
||||||
// utility code:
|
// utility code:
|
||||||
struct SimpleTcpClientConfig {
|
struct SimpleTcpClientConfig {
|
||||||
|
retries int = 10
|
||||||
host string = 'static.dev'
|
host string = 'static.dev'
|
||||||
path string = '/'
|
path string = '/'
|
||||||
agent string = 'v/net.tcp.v'
|
agent string = 'v/net.tcp.v'
|
||||||
|
@ -234,12 +235,23 @@ struct SimpleTcpClientConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn simple_tcp_client(config SimpleTcpClientConfig) ?string {
|
fn simple_tcp_client(config SimpleTcpClientConfig) ?string {
|
||||||
client := net.dial('127.0.0.1', sport) or {
|
mut client := net.Socket{}
|
||||||
return error(err)
|
mut tries := 0
|
||||||
|
for tries < config.retries {
|
||||||
|
tries++
|
||||||
|
client = net.dial('127.0.0.1', sport) or {
|
||||||
|
if tries > config.retries {
|
||||||
|
return error(err)
|
||||||
|
}
|
||||||
|
time.sleep_ms(150)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
defer {
|
defer {
|
||||||
client.close() or { }
|
client.close() or { }
|
||||||
}
|
}
|
||||||
|
//
|
||||||
message := 'GET $config.path HTTP/1.1
|
message := 'GET $config.path HTTP/1.1
|
||||||
Host: $config.host
|
Host: $config.host
|
||||||
User-Agent: $config.agent
|
User-Agent: $config.agent
|
||||||
|
|
Loading…
Reference in New Issue