Mercurial > hg > orthanc-tests
changeset 494:cffef67c9a94
added retries to httpbin
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 10 Aug 2022 15:15:20 +0200 |
parents | be5144a75c63 |
children | 75d8a5261f82 |
files | Database/Lua/HttpClient.lua |
diffstat | 1 files changed, 26 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/Database/Lua/HttpClient.lua Tue Aug 09 18:06:29 2022 +0200 +++ b/Database/Lua/HttpClient.lua Wed Aug 10 15:15:20 2022 +0200 @@ -1,5 +1,5 @@ -- for these tests, we issue HTTP requests to httpbin.org that performs smart echo (it returns all data/headers it has received + some extra data) - +-- since these tests to httpbin.org fails a lot, we have added 10 retries testSucceeded = true local payload = {} @@ -11,25 +11,41 @@ httpHeaders['Toto'] = 'Tutu' -- Issue HttpPost with body -response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders)) +retry = 10 +response = nil +while retry > 0 and response == nil do + response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders)) +end testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end -- Issue HttpPost without body -response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders)) +retry = 10 +response = nil +while retry > 0 and response == nil do + response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders)) +end testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') testSucceeded = testSucceeded and (response['data'] == '') if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end -- Issue HttpPut with body -response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders)) +retry = 10 +response = nil +while retry > 0 and response == nil do + response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders)) +end testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end -- Issue HttpPut without body -response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders)) +retry = 10 +response = nil +while retry > 0 and response == nil do + response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders)) +end testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') testSucceeded = testSucceeded and (response['data'] == '') if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end @@ -41,7 +57,11 @@ -- in curl at this point -- Issue HttpGet -response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders)) +retry = 10 +response = nil +while retry > 0 and response == nil do + response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders)) +end testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end