@@ -24,17 +24,21 @@ defmodule PetTest do
2424 { :ok , % Tesla.Env { } = response } = PetApi . add_pet ( connection , pet )
2525 assert response . status == 200
2626
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 )
3335
3436 { :ok , response } = PetApi . delete_pet ( connection , petId )
3537 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 )
3842 end
3943
4044 test "update a pet" , % { connection: connection } do
@@ -50,10 +54,24 @@ defmodule PetTest do
5054 { :ok , response } = PetApi . update_pet ( connection , pet )
5155 assert response . status == 200
5256
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
5775 end
5876
5977 test "find pet by status" , % { connection: connection } do
0 commit comments