1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tests: add retry logic in simple_tcp_client in vweb_test.v

This commit is contained in:
Delyan Angelov
2020-08-25 17:05:40 +03:00
parent 1619beda91
commit 7b7ab580ab

View File

@ -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