Skip to content

Commit f8710fa

Browse files
committed
make repl_set_step_down aysnc
1 parent 04e02e3 commit f8710fa

File tree

6 files changed

+26
-13
lines changed

6 files changed

+26
-13
lines changed

test/asynchronous/helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
from bson.son import SON
4444
from pymongo import common, message
45+
from pymongo.read_preferences import ReadPreference
4546
from pymongo.ssl_support import HAVE_SSL, _ssl # type:ignore[attr-defined]
4647
from pymongo.uri_parser import parse_uri
4748

@@ -150,6 +151,16 @@ def _create_user(authdb, user, pwd=None, roles=None, **kwargs):
150151
return authdb.command(cmd)
151152

152153

154+
async def async_repl_set_step_down(client, **kwargs):
155+
"""Run replSetStepDown, first unfreezing a secondary with replSetFreeze."""
156+
cmd = SON([("replSetStepDown", 1)])
157+
cmd.update(kwargs)
158+
159+
# Unfreeze a secondary to ensure a speedy election.
160+
await client.admin.command("replSetFreeze", 0, read_preference=ReadPreference.SECONDARY)
161+
await client.admin.command(cmd)
162+
163+
153164
class client_knobs:
154165
def __init__(
155166
self,

test/asynchronous/test_connections_survive_primary_stepdown_spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
sys.path[0:0] = [""]
2121

2222
from test.asynchronous import AsyncIntegrationTest, async_client_context, unittest
23+
from test.asynchronous.helpers import async_repl_set_step_down
2324
from test.utils import (
2425
CMAPListener,
2526
async_ensure_all_connected,
26-
repl_set_step_down,
2727
)
2828

2929
from bson import SON
@@ -88,7 +88,7 @@ async def test_get_more_iteration(self):
8888
for _ in range(batch_size):
8989
await cursor.next()
9090
# Force step-down the primary.
91-
repl_set_step_down(self.client, replSetStepDown=5, force=True)
91+
await async_repl_set_step_down(self.client, replSetStepDown=5, force=True)
9292
# Get await anext batch of results.
9393
for _ in range(batch_size):
9494
await cursor.next()

test/helpers.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
from bson.son import SON
4444
from pymongo import common, message
45+
from pymongo.read_preferences import ReadPreference
4546
from pymongo.ssl_support import HAVE_SSL, _ssl # type:ignore[attr-defined]
4647
from pymongo.uri_parser import parse_uri
4748

@@ -150,6 +151,16 @@ def _create_user(authdb, user, pwd=None, roles=None, **kwargs):
150151
return authdb.command(cmd)
151152

152153

154+
def repl_set_step_down(client, **kwargs):
155+
"""Run replSetStepDown, first unfreezing a secondary with replSetFreeze."""
156+
cmd = SON([("replSetStepDown", 1)])
157+
cmd.update(kwargs)
158+
159+
# Unfreeze a secondary to ensure a speedy election.
160+
client.admin.command("replSetFreeze", 0, read_preference=ReadPreference.SECONDARY)
161+
client.admin.command(cmd)
162+
163+
153164
class client_knobs:
154165
def __init__(
155166
self,

test/test_connections_survive_primary_stepdown_spec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
sys.path[0:0] = [""]
2121

2222
from test import IntegrationTest, client_context, unittest
23+
from test.helpers import repl_set_step_down
2324
from test.utils import (
2425
CMAPListener,
2526
ensure_all_connected,
26-
repl_set_step_down,
2727
)
2828

2929
from bson import SON

test/utils.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -799,16 +799,6 @@ async def async_wait_until(predicate, success_description, timeout=10):
799799
await asyncio.sleep(interval)
800800

801801

802-
def repl_set_step_down(client, **kwargs):
803-
"""Run replSetStepDown, first unfreezing a secondary with replSetFreeze."""
804-
cmd = SON([("replSetStepDown", 1)])
805-
cmd.update(kwargs)
806-
807-
# Unfreeze a secondary to ensure a speedy election.
808-
client.admin.command("replSetFreeze", 0, read_preference=ReadPreference.SECONDARY)
809-
client.admin.command(cmd)
810-
811-
812802
def is_mongos(client):
813803
res = client.admin.command(HelloCompat.LEGACY_CMD)
814804
return res.get("msg", "") == "isdbgrid"

tools/synchro.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"AsyncTestGridFileNoConnect": "TestGridFileNoConnect",
107107
"async_set_fail_point": "set_fail_point",
108108
"async_ensure_all_connected": "ensure_all_connected",
109+
"async_repl_set_step_down": "repl_set_step_down",
109110
}
110111

111112
docstring_replacements: dict[tuple[str, str], str] = {

0 commit comments

Comments
 (0)