@@ -24,17 +24,21 @@ defmodule PetTest do
24
24
{ :ok , % Tesla.Env { } = response } = PetApi . add_pet ( connection , pet )
25
25
assert response . status == 200
26
26
27
- { :ok , pet } = PetApi . get_pet_by_id ( connection , petId )
28
- assert pet . id == petId
29
- assert pet . name == "elixir client test"
30
- assert pet . photoUrls == [ "http://test_elixir_unit_test.com" ]
31
- assert pet . category == % Category { id: petId , name: "test elixir category" }
32
- assert pet . tags == [ % Tag { :id => petId , :name => "test elixir tag" } ]
27
+ retry_assert ( fn ->
28
+ { :ok , pet } = PetApi . get_pet_by_id ( connection , petId )
29
+ assert pet . id == petId
30
+ assert pet . name == "elixir client test"
31
+ assert pet . photoUrls == [ "http://test_elixir_unit_test.com" ]
32
+ assert pet . category == % Category { id: petId , name: "test elixir category" }
33
+ assert pet . tags == [ % Tag { :id => petId , :name => "test elixir tag" } ]
34
+ end )
33
35
34
36
{ :ok , response } = PetApi . delete_pet ( connection , petId )
35
37
assert response . status == 200
36
- { :ok , response } = PetApi . get_pet_by_id ( connection , petId )
37
- assert response . status == 404
38
+ retry_assert ( fn ->
39
+ { :ok , response } = PetApi . get_pet_by_id ( connection , petId )
40
+ assert response . status == 404
41
+ end )
38
42
end
39
43
40
44
test "update a pet" , % { connection: connection } do
@@ -50,10 +54,24 @@ defmodule PetTest do
50
54
{ :ok , response } = PetApi . update_pet ( connection , pet )
51
55
assert response . status == 200
52
56
53
- { :ok , pet } = PetApi . get_pet_by_id ( connection , petId )
54
- assert pet . id == petId
55
- assert pet . name == "elixir client updatePet"
56
- assert pet . status == "pending"
57
+ retry_assert ( fn ->
58
+ { :ok , pet } = PetApi . get_pet_by_id ( connection , petId )
59
+ assert pet . id == petId
60
+ assert pet . name == "elixir client updatePet"
61
+ assert pet . status == "pending"
62
+ end , 5 , 100 )
63
+ end
64
+
65
+ def retry_assert ( fun , attempts \\ 3 , delay \\ 100 )
66
+ def retry_assert ( _fun , 0 , _delay ) , do: flunk ( "assertion failed after retries" )
67
+ def retry_assert ( fun , attempts , delay ) do
68
+ try do
69
+ fun . ( )
70
+ rescue
71
+ _e ->
72
+ Process . sleep ( delay )
73
+ retry_assert ( fun , attempts - 1 , delay )
74
+ end
57
75
end
58
76
59
77
test "find pet by status" , % { connection: connection } do
0 commit comments