Mercurial > hg > orthanc-tests
annotate 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 |
rev | line source |
---|---|
104 | 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) |
494 | 2 -- since these tests to httpbin.org fails a lot, we have added 10 retries |
102 | 3 testSucceeded = true |
4 | |
5 local payload = {} | |
6 payload['stringMember'] = 'toto' | |
7 payload['intMember'] = 2 | |
8 | |
9 local httpHeaders = {} | |
10 httpHeaders['Content-Type'] = 'application/json' | |
11 httpHeaders['Toto'] = 'Tutu' | |
12 | |
13 -- Issue HttpPost with body | |
494 | 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 | |
102 | 19 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
20 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') | |
104 | 21 if not testSucceeded then print('Failed in HttpPost with body') PrintRecursive(response) end |
102 | 22 |
23 -- Issue HttpPost without body | |
494 | 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 | |
102 | 29 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
104 | 30 testSucceeded = testSucceeded and (response['data'] == '') |
31 if not testSucceeded then print('Failed in HttpPost without body') PrintRecursive(response) end | |
102 | 32 |
33 -- Issue HttpPut with body | |
494 | 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 | |
102 | 39 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
104 | 40 testSucceeded = testSucceeded and (response['json']['intMember'] == 2 and response['json']['stringMember'] == 'toto') |
41 if not testSucceeded then print('Failed in HttpPut with body') PrintRecursive(response) end | |
102 | 42 |
43 -- Issue HttpPut without body | |
494 | 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 | |
102 | 49 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
104 | 50 testSucceeded = testSucceeded and (response['data'] == '') |
51 if not testSucceeded then print('Failed in HttpPut without body') PrintRecursive(response) end | |
102 | 52 |
53 -- Issue HttpDelete (juste make sure it is issued, we can't check the response) | |
54 HttpDelete('http://httpbin.org/delete', httpHeaders) | |
55 | |
263
a2719263fd04
test_study_series_find_inconsistency
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
104
diff
changeset
|
56 -- TODO Very strange: Since Orthanc 1.6.0, a timeout frequently occurs |
a2719263fd04
test_study_series_find_inconsistency
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
104
diff
changeset
|
57 -- in curl at this point |
a2719263fd04
test_study_series_find_inconsistency
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
104
diff
changeset
|
58 |
102 | 59 -- Issue HttpGet |
494 | 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 | |
102 | 65 testSucceeded = testSucceeded and (response['headers']['Content-Type'] == 'application/json' and response['headers']['Toto'] == 'Tutu') |
104 | 66 if not testSucceeded then print('Failed in HttpGet') PrintRecursive(response) end |
102 | 67 |
480
5ac463ebf463
added a test for lua SetHttpTimeout
Alain Mazy <am@osimis.io>
parents:
263
diff
changeset
|
68 |
481 | 69 system = ParseJson(RestApiGet('/system')) |
480
5ac463ebf463
added a test for lua SetHttpTimeout
Alain Mazy <am@osimis.io>
parents:
263
diff
changeset
|
70 |
481 | 71 if system['Version'] == 'mainline' or system['Version'] == '1.11.1' or system['ApiVersion'] >= 18 then -- introduced in 1.11.1 which is ApiVersion 17 (too lazy to reimplement IsAboveOrthancVersion in lua :-) ) |
72 -- Test SetHttpTimeout | |
73 SetHttpTimeout(10) | |
74 response = HttpGet('https://httpstat.us/200?sleep=1000') | |
75 testSucceeded = testSucceeded and (response == '200 OK') | |
76 if not testSucceeded then print('Failed in SetHttpTimeout1') PrintRecursive(response) end | |
77 | |
78 SetHttpTimeout(1) | |
79 response = HttpGet('https://httpstat.us/200?sleep=2000') | |
80 testSucceeded = testSucceeded and (response == nil) | |
81 if not testSucceeded then print('Failed in SetHttpTimeout2') PrintRecursive(response) end | |
82 end | |
480
5ac463ebf463
added a test for lua SetHttpTimeout
Alain Mazy <am@osimis.io>
parents:
263
diff
changeset
|
83 |
102 | 84 if testSucceeded then |
85 print('OK') | |
86 else | |
87 print('FAILED') | |
88 end |