Skip to content

Commit 75584d7

Browse files
committed
guarantee cluster cleanup
1 parent 43e85ac commit 75584d7

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

tests/integration/standard/test_cluster.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,31 @@ def test_session_host_parameter(self):
200200
201201
@test_category connection
202202
"""
203+
def cleanup():
204+
"""
205+
When this test fails, the inline .shutdown() calls don't get
206+
called, so we register this as a cleanup.
207+
"""
208+
self.cluster_to_shutdown.shutdown()
209+
self.addCleanup(cleanup)
210+
203211
# Test with empty list
204-
cluster = Cluster(protocol_version=PROTOCOL_VERSION)
212+
self.cluster_to_shutdown = Cluster(protocol_version=PROTOCOL_VERSION)
205213
with self.assertRaises(NoHostAvailable):
206-
Session(cluster, [])
207-
cluster.shutdown()
214+
Session(self.cluster_to_shutdown, [])
215+
self.cluster_to_shutdown.shutdown()
208216

209217
# Test with only invalid
210-
cluster = Cluster(protocol_version=PROTOCOL_VERSION)
218+
self.cluster_to_shutdown = Cluster(protocol_version=PROTOCOL_VERSION)
211219
with self.assertRaises(NoHostAvailable):
212-
Session(cluster, [Host("1.2.3.4", SimpleConvictionPolicy)])
213-
cluster.shutdown()
220+
Session(self.cluster_to_shutdown, [Host("1.2.3.4", SimpleConvictionPolicy)])
221+
self.cluster_to_shutdown.shutdown()
214222

215223
# Test with valid and invalid hosts
216-
cluster = Cluster(protocol_version=PROTOCOL_VERSION)
217-
Session(cluster, [Host(x, SimpleConvictionPolicy) for x in
218-
("127.0.0.1", "127.0.0.2", "1.2.3.4")])
219-
cluster.shutdown()
224+
self.cluster_to_shutdown = Cluster(protocol_version=PROTOCOL_VERSION)
225+
Session(self.cluster_to_shutdown, [Host(x, SimpleConvictionPolicy) for x in
226+
("127.0.0.1", "127.0.0.2", "1.2.3.4")])
227+
self.cluster_to_shutdown.shutdown()
220228

221229
def test_protocol_negotiation(self):
222230
"""

0 commit comments

Comments
 (0)