Skip to content

Commit 8416c73

Browse files
committed
PYTHON-1421 Ensure Server monitor threads are (re)opened.
1 parent 628cd2d commit 8416c73

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

pymongo/topology.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2014-2016 MongoDB, Inc.
1+
# Copyright 2014-present MongoDB, Inc.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License"); you
44
# may not use this file except in compliance with the License. You
@@ -453,10 +453,10 @@ def _ensure_opened(self):
453453
# Start or restart the events publishing thread.
454454
if self._publish_tp or self._publish_server:
455455
self.__events_executor.open()
456-
else:
457-
# Restart monitors if we forked since previous call.
458-
for server in itervalues(self._servers):
459-
server.open()
456+
457+
# Ensure that the monitors are open.
458+
for server in itervalues(self._servers):
459+
server.open()
460460

461461
def _reset_server(self, address):
462462
"""Clear our pool for a server and mark it Unknown.

test/test_replica_set_reconfig.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2013-2015 MongoDB, Inc.
1+
# Copyright 2013-present MongoDB, Inc.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@ def test_client(self):
4242
host='a:1,b:2,c:3',
4343
replicaSet='rs',
4444
serverSelectionTimeoutMS=100)
45+
self.addCleanup(c.close)
4546

4647
# MongoClient connects to primary by default.
4748
wait_until(lambda: c.address is not None, 'connect to primary')
@@ -70,6 +71,7 @@ def test_replica_set_client(self):
7071
mongoses=[],
7172
host='a:1,b:2,c:3',
7273
replicaSet='rs')
74+
self.addCleanup(c.close)
7375

7476
wait_until(lambda: ('b', 2) in c.secondaries,
7577
'discover host "b"')
@@ -97,6 +99,7 @@ def test_replica_set_client(self):
9799
mongoses=[],
98100
host='a:1,b:2,c:3',
99101
replicaSet='rs')
102+
self.addCleanup(c.close)
100103

101104
wait_until(lambda: ('b', 2) in c.secondaries, 'discover host "b"')
102105
wait_until(lambda: ('c', 3) in c.secondaries, 'discover host "c"')
@@ -119,6 +122,7 @@ def test_socket_error_marks_member_down(self):
119122
mongoses=[],
120123
host='a:1',
121124
replicaSet='rs')
125+
self.addCleanup(c.close)
122126

123127
wait_until(lambda: len(c.nodes) == 2, 'discover both nodes')
124128

@@ -140,6 +144,7 @@ def test_client(self):
140144
mongoses=[],
141145
host='a:1',
142146
replicaSet='rs')
147+
self.addCleanup(c.close)
143148

144149
wait_until(lambda: len(c.nodes) == 2, 'discover both nodes')
145150

@@ -166,6 +171,7 @@ def test_replica_set_client(self):
166171
mongoses=[],
167172
host='a:1',
168173
replicaSet='rs')
174+
self.addCleanup(c.close)
169175

170176
wait_until(lambda: ('a', 1) == c.primary, 'discover the primary')
171177
wait_until(lambda: set([('b', 2)]) == c.secondaries,

0 commit comments

Comments
 (0)