@@ -97,17 +97,23 @@ def test_run_instance_operations(capsys, dispose_of):
9797
9898
9999def test_delete_instance (capsys , dispose_of ):
100- dispose_of ( INSTANCE )
100+ from concurrent . futures import TimeoutError
101101
102- # Can't delete it, it doesn't exist
103- instanceadmin .delete_instance (PROJECT , INSTANCE )
104- out = capsys .readouterr ().out
105- assert "Deleting instance" in out
106- assert f"Instance { INSTANCE } does not exist" in out
102+ @backoff .on_exception (backoff .expo , TimeoutError )
103+ def _set_up_instance ():
104+ dispose_of (INSTANCE )
107105
108- # Ok, create it then
109- instanceadmin .run_instance_operations (PROJECT , INSTANCE , CLUSTER1 )
110- capsys .readouterr () # throw away output
106+ # Can't delete it, it doesn't exist
107+ instanceadmin .delete_instance (PROJECT , INSTANCE )
108+ out = capsys .readouterr ().out
109+ assert "Deleting instance" in out
110+ assert f"Instance { INSTANCE } does not exist" in out
111+
112+ # Ok, create it then
113+ instanceadmin .run_instance_operations (PROJECT , INSTANCE , CLUSTER1 )
114+ capsys .readouterr () # throw away output
115+
116+ _set_up_instance ()
111117
112118 # Now delete it
113119 instanceadmin .delete_instance (PROJECT , INSTANCE )
@@ -117,22 +123,29 @@ def test_delete_instance(capsys, dispose_of):
117123
118124
119125def test_add_and_delete_cluster (capsys , dispose_of ):
120- dispose_of ( INSTANCE )
126+ from concurrent . futures import TimeoutError
121127
122- # This won't work, because the instance isn't created yet
123- instanceadmin .add_cluster (PROJECT , INSTANCE , CLUSTER2 )
124- out = capsys .readouterr ().out
125- assert f"Instance { INSTANCE } does not exist" in out
128+ @backoff .on_exception (backoff .expo , TimeoutError )
129+ def _set_up_instance ():
130+ dispose_of (INSTANCE )
126131
127- # Get the instance created
128- instanceadmin .run_instance_operations (PROJECT , INSTANCE , CLUSTER1 )
129- capsys .readouterr () # throw away output
132+ # This won't work, because the instance isn't created yet
133+ instanceadmin .add_cluster (PROJECT , INSTANCE , CLUSTER2 )
134+ out = capsys .readouterr ().out
135+ assert f"Instance { INSTANCE } does not exist" in out
136+
137+ # Get the instance created
138+ instanceadmin .run_instance_operations (PROJECT , INSTANCE , CLUSTER1 )
139+ capsys .readouterr () # throw away output
140+
141+ _set_up_instance ()
130142
131143 # Add a cluster to that instance
132144 # Avoid failing for "instance is currently being changed" by
133145 # applying an exponential backoff
134- w_backoff = backoff .on_exception (backoff .expo , exceptions .ServiceUnavailable )
135- w_backoff (instanceadmin .add_cluster )(PROJECT , INSTANCE , CLUSTER2 )
146+ backoff_503 = backoff .on_exception (backoff .expo , exceptions .ServiceUnavailable )
147+
148+ backoff_503 (instanceadmin .add_cluster )(PROJECT , INSTANCE , CLUSTER2 )
136149 out = capsys .readouterr ().out
137150 assert f"Adding cluster to instance { INSTANCE } " in out
138151 assert "Listing clusters..." in out
0 commit comments