Skip to content

Commit 565e5fa

Browse files
committed
No more need to call MongoClient.close in tests.
1 parent 6cd00ee commit 565e5fa

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

test/high_availability/test_ha.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -787,26 +787,23 @@ def test_alive(self):
787787
secondary_cx = connected(MongoClient(secondary))
788788
rsc = connected(MongoClient(self.seed, replicaSet=self.name))
789789

790-
try:
791-
self.assertTrue(primary_cx.alive())
792-
self.assertTrue(secondary_cx.alive())
793-
self.assertTrue(rsc.alive())
794-
795-
ha_tools.kill_primary()
796-
time.sleep(0.5)
790+
self.assertTrue(primary_cx.alive())
791+
self.assertTrue(secondary_cx.alive())
792+
self.assertTrue(rsc.alive())
797793

798-
self.assertFalse(primary_cx.alive())
799-
self.assertTrue(secondary_cx.alive())
800-
self.assertFalse(rsc.alive())
801-
802-
ha_tools.kill_members([secondary], 2)
803-
time.sleep(0.5)
804-
805-
self.assertFalse(primary_cx.alive())
806-
self.assertFalse(secondary_cx.alive())
807-
self.assertFalse(rsc.alive())
808-
finally:
809-
rsc.close()
794+
ha_tools.kill_primary()
795+
time.sleep(0.5)
796+
797+
self.assertFalse(primary_cx.alive())
798+
self.assertTrue(secondary_cx.alive())
799+
self.assertFalse(rsc.alive())
800+
801+
ha_tools.kill_members([secondary], 2)
802+
time.sleep(0.5)
803+
804+
self.assertFalse(primary_cx.alive())
805+
self.assertFalse(secondary_cx.alive())
806+
self.assertFalse(rsc.alive())
810807

811808

812809
class TestMongosHighAvailability(HATestCase):

test/test_gridfs.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,10 @@ def test_gridfs_replica_set(self):
446446
w=self.w, wtimeout=5000,
447447
read_preference=ReadPreference.SECONDARY)
448448

449-
try:
450-
fs = gridfs.GridFS(rsc.pymongo_test)
451-
oid = fs.put(b'foo')
452-
content = fs.get(oid).read()
453-
self.assertEqual(b'foo', content)
454-
finally:
455-
rsc.close()
449+
fs = gridfs.GridFS(rsc.pymongo_test)
450+
oid = fs.put(b'foo')
451+
content = fs.get(oid).read()
452+
self.assertEqual(b'foo', content)
456453

457454
def test_gridfs_secondary(self):
458455
primary_host, primary_port = self.primary

0 commit comments

Comments
 (0)