tests: add retry logic in simple_tcp_client in vweb_test.v

pull/6219/head
Delyan Angelov 2020-08-25 17:05:40 +03:00
parent 1619beda91
commit 7b7ab580ab
1 changed files with 14 additions and 2 deletions

View File

@ -226,6 +226,7 @@ fn testsuite_end() {
// utility code:
struct SimpleTcpClientConfig {
retries int = 10
host string = 'static.dev'
path string = '/'
agent string = 'v/net.tcp.v'
@ -234,12 +235,23 @@ struct SimpleTcpClientConfig {
}
fn simple_tcp_client(config SimpleTcpClientConfig) ?string {
client := net.dial('127.0.0.1', sport) or {
return error(err)
mut client := net.Socket{}
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 {
client.close() or { }
}
//
message := 'GET $config.path HTTP/1.1
Host: $config.host
User-Agent: $config.agent