From 7b7ab580abd6937a4b40475462ecfea94eb4e049 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 25 Aug 2020 17:05:40 +0300 Subject: [PATCH] tests: add retry logic in simple_tcp_client in vweb_test.v --- vlib/vweb/tests/vweb_test.v | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/vlib/vweb/tests/vweb_test.v b/vlib/vweb/tests/vweb_test.v index e08877751c..9239e72294 100644 --- a/vlib/vweb/tests/vweb_test.v +++ b/vlib/vweb/tests/vweb_test.v @@ -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