comparison Database/Lua/HttpClient.lua @ 494:cffef67c9a94

added retries to httpbin
author Alain Mazy <am@osimis.io>
date Wed, 10 Aug 2022 15:15:20 +0200
parents e0b502b31a8a
children 75d8a5261f82
comparison
equal deleted inserted replaced
493:be5144a75c63 494:cffef67c9a94
1 -- 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) 1 -- 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)
2 2 -- since these tests to httpbin.org fails a lot, we have added 10 retries
3 testSucceeded = true 3 testSucceeded = true
4 4
5 local payload = {} 5 local payload = {}
6 payload['stringMember'] = 'toto' 6 payload['stringMember'] = 'toto'
7 payload['intMember'] = 2 7 payload['intMember'] = 2
9 local httpHeaders = {} 9 local httpHeaders = {}
10 httpHeaders['Content-Type'] = 'application/json' 10 httpHeaders['Content-Type'] = 'application/json'
11 httpHeaders['Toto'] = 'Tutu' 11 httpHeaders['Toto'] = 'Tutu'
12 12
13 -- Issue HttpPost with body 13 -- Issue HttpPost with body
14 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders)) 14 retry = 10
15 response = nil
16 while retry > 0 and response == nil do
17 response = ParseJson(HttpPost('http://httpbin.org/post', DumpJson(payload), httpHeaders))
18 end
15 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') 19 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
16 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') 20 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
17 if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end 21 if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end
18 22
19 -- Issue HttpPost without body 23 -- Issue HttpPost without body
20 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders)) 24 retry = 10
25 response = nil
26 while retry > 0 and response == nil do
27 response = ParseJson(HttpPost('http://httpbin.org/post', nil, httpHeaders))
28 end
21 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') 29 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
22 testSucceeded = testSucceeded and (response['data'] == '') 30 testSucceeded = testSucceeded and (response['data'] == '')
23 if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end 31 if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end
24 32
25 -- Issue HttpPut with body 33 -- Issue HttpPut with body
26 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders)) 34 retry = 10
35 response = nil
36 while retry > 0 and response == nil do
37 response = ParseJson(HttpPut('http://httpbin.org/put', DumpJson(payload), httpHeaders))
38 end
27 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') 39 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
28 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') 40 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto')
29 if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end 41 if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end
30 42
31 -- Issue HttpPut without body 43 -- Issue HttpPut without body
32 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders)) 44 retry = 10
45 response = nil
46 while retry > 0 and response == nil do
47 response = ParseJson(HttpPut('http://httpbin.org/put', nil, httpHeaders))
48 end
33 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') 49 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
34 testSucceeded = testSucceeded and (response['data'] == '') 50 testSucceeded = testSucceeded and (response['data'] == '')
35 if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end 51 if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end
36 52
37 -- Issue HttpDelete (juste make sure it is issued, we can't check the response) 53 -- Issue HttpDelete (juste make sure it is issued, we can't check the response)
39 55
40 -- TODO Very strange: Since Orthanc 1.6.0, a timeout frequently occurs 56 -- TODO Very strange: Since Orthanc 1.6.0, a timeout frequently occurs
41 -- in curl at this point 57 -- in curl at this point
42 58
43 -- Issue HttpGet 59 -- Issue HttpGet
44 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders)) 60 retry = 10
61 response = nil
62 while retry > 0 and response == nil do
63 response = ParseJson(HttpGet('http://httpbin.org/get', httpHeaders))
64 end
45 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') 65 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu')
46 if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end 66 if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end
47 67
48 68
49 system = ParseJson(RestApiGet('/system')) 69 system = ParseJson(RestApiGet('/system'))