Skip to content

Commit 100da38

Browse files
authored
PCSM-237: Fix intermittent test failures due to race condition in wait_for_current_optime() (#156)
1 parent 6fec171 commit 100da38

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ __pycache__
1616

1717
/org.md
1818
/scratch.*
19+
20+
CLAUDE.md

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ build-backend = "poetry.core.masonry.api"
1515
[tool.pytest.ini_options]
1616
addopts = "-ra"
1717
testpaths = ["tests"]
18-
timeout = 10
18+
timeout = 15
1919
timeout_func_only = true

pyrightconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"venvPath": ".",
3+
"venv": ".venv",
4+
"extraPaths": ["tests"],
5+
"pythonVersion": "3.13",
6+
"typeCheckingMode": "basic",
7+
"useLibraryCodeForTypes": true
8+
}

tests/pcsm.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,20 @@ def wait_for_current_optime(self):
186186
status = self.pcsm.status()
187187
assert status["state"] == PCSM.State.RUNNING, status
188188

189-
curr_optime = self.source.server_info()["$clusterTime"]["clusterTime"]
189+
result = self.source.admin.command(
190+
{"appendOplogNote": 1, "data": {"msg": "test:sync_point"}}
191+
)
192+
curr_optime = result["$clusterTime"]["clusterTime"]
193+
190194
for _ in range(self.wait_timeout * 2):
191-
if curr_optime <= self.last_applied_op:
195+
last_applied = self.last_applied_op
196+
if curr_optime <= last_applied:
197+
# Even though the oplog entry is replicated, PCSM may not have finished
198+
# writing to the target database. Add a small delay to ensure completion.
199+
time.sleep(0.3)
192200
return
193201

194202
time.sleep(0.5)
195-
status = self.pcsm.status()
196203

197204
raise WaitTimeoutError()
198205

0 commit comments

Comments
 (0)