Skip to content

Commit 5ef97a3

Browse files
authored
PLM-146: Increase test timeout (#107)
1 parent 3f2b00d commit 5ef97a3

File tree

11 files changed

+72
-70
lines changed

11 files changed

+72
-70
lines changed

main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -584,28 +584,28 @@ func createServer(ctx context.Context, sourceURI, targetURI string) (*server, er
584584
promRegistry := prometheus.NewRegistry()
585585
metrics.Init(promRegistry)
586586

587-
mlink := plm.New(source, target)
587+
lm := plm.New(source, target)
588588

589-
err = Restore(ctx, target, mlink)
589+
err = Restore(ctx, target, lm)
590590
if err != nil {
591591
return nil, errors.Wrap(err, "recover PLM")
592592
}
593593

594-
mlink.SetOnStateChanged(func(newState plm.State) {
595-
err := DoCheckpoint(ctx, target, mlink)
594+
lm.SetOnStateChanged(func(newState plm.State) {
595+
err := DoCheckpoint(ctx, target, lm)
596596
if err != nil {
597597
log.New("http:checkpointing").Error(err, "checkpoint")
598598
} else {
599599
log.New("http:checkpointing").Debugf("Checkpoint saved on %q", newState)
600600
}
601601
})
602602

603-
go RunCheckpointing(ctx, target, mlink)
603+
go RunCheckpointing(ctx, target, lm)
604604

605605
s := &server{
606606
sourceCluster: source,
607607
targetCluster: target,
608-
plm: mlink,
608+
plm: lm,
609609
stopHeartbeat: stopHeartbeat,
610610
promRegistry: promRegistry,
611611
}

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77
import testing
8-
from mlink import PLM
8+
from plm import PLM
99
from pymongo import MongoClient
1010

1111

@@ -52,7 +52,7 @@ def target_conn(request: pytest.FixtureRequest):
5252

5353

5454
@pytest.fixture(scope="session")
55-
def mlink(request: pytest.FixtureRequest):
55+
def plm(request: pytest.FixtureRequest):
5656
"""Provide a plm instance."""
5757
url = request.config.getoption("--plm_url") or os.environ["TEST_PLM_URL"]
5858
return PLM(url)
@@ -65,8 +65,8 @@ def plm_bin(request: pytest.FixtureRequest):
6565

6666

6767
@pytest.fixture(scope="session")
68-
def t(source_conn: MongoClient, target_conn: MongoClient, mlink: PLM):
69-
return testing.Testing(source_conn, target_conn, mlink)
68+
def t(source_conn: MongoClient, target_conn: MongoClient, plm: PLM):
69+
return testing.Testing(source_conn, target_conn, plm)
7070

7171

7272
@pytest.fixture(autouse=True)

tests/mlink.py renamed to tests/plm.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __str__(self):
2525

2626

2727
class PLM:
28-
"""MLink provides methods to interact with the PLM service."""
28+
"""PLM provides methods to interact with the PLM service."""
2929

3030
class State(StrEnum):
3131
"""State represents the state of the PLM service."""
@@ -38,7 +38,7 @@ class State(StrEnum):
3838
FINALIZED = "finalized"
3939

4040
def __init__(self, uri: str):
41-
"""Initialize MLink with the given URI."""
41+
"""Initialize PLM with the given URI."""
4242
self.uri = uri
4343

4444
def status(self):
@@ -116,13 +116,13 @@ class Phase(StrEnum):
116116
def __init__(
117117
self,
118118
source: MongoClient,
119-
mlink: PLM,
119+
plm: PLM,
120120
phase: Phase,
121121
options: dict,
122122
wait_timeout=None,
123123
):
124124
self.source: MongoClient = source
125-
self.mlink = mlink
125+
self.plm = plm
126126
self.phase = phase
127127
self.options = options
128128
self.wait_timeout = wait_timeout or 10
@@ -147,43 +147,43 @@ def __exit__(self, _t, exc, _tb):
147147
def start(self, pause_on_initial_sync=False):
148148
"""Start the PLM service."""
149149
self.finalize(fast=True)
150-
self.mlink.start(pause_on_initial_sync=pause_on_initial_sync, **self.options)
150+
self.plm.start(pause_on_initial_sync=pause_on_initial_sync, **self.options)
151151

152152
def finalize(self, *, fast=False):
153153
"""Finalize the PLM service."""
154-
state = self.mlink.status()
154+
state = self.plm.status()
155155

156156
if state["state"] == PLM.State.PAUSED:
157157
if state["initialSync"]["cloneCompleted"]:
158-
self.mlink.resume()
159-
state = self.mlink.status()
158+
self.plm.resume()
159+
state = self.plm.status()
160160

161161
if state["state"] == PLM.State.RUNNING:
162162
if not fast:
163163
self.wait_for_current_optime()
164164
self.wait_for_initial_sync()
165-
self.mlink.finalize()
166-
state = self.mlink.status()
165+
self.plm.finalize()
166+
state = self.plm.status()
167167

168168
if state["state"] == PLM.State.FINALIZING:
169169
if not fast:
170170
self.wait_for_state(PLM.State.FINALIZED)
171171

172172
def wait_for_state(self, state: PLM.State):
173173
"""Wait for the PLM service to reach the specified state."""
174-
if self.mlink.status()["state"] == state:
174+
if self.plm.status()["state"] == state:
175175
return
176176

177177
for _ in range(self.wait_timeout * 2):
178178
time.sleep(0.5)
179-
if self.mlink.status()["state"] == state:
179+
if self.plm.status()["state"] == state:
180180
return
181181

182182
raise WaitTimeoutError()
183183

184184
def wait_for_current_optime(self):
185185
"""Wait for the current operation time to be applied."""
186-
status = self.mlink.status()
186+
status = self.plm.status()
187187
assert status["state"] == PLM.State.RUNNING, status
188188

189189
curr_optime = self.source.server_info()["$clusterTime"]["clusterTime"]
@@ -192,13 +192,13 @@ def wait_for_current_optime(self):
192192
return
193193

194194
time.sleep(0.5)
195-
status = self.mlink.status()
195+
status = self.plm.status()
196196

197197
raise WaitTimeoutError()
198198

199199
def wait_for_initial_sync(self):
200200
"""Wait for the PLM service to be finalizable."""
201-
status = self.mlink.status()
201+
status = self.plm.status()
202202
assert status["state"] != PLM.State.IDLE, status
203203

204204
if status["initialSync"]["completed"]:
@@ -211,28 +211,28 @@ def wait_for_initial_sync(self):
211211
return
212212

213213
time.sleep(0.5)
214-
status = self.mlink.status()
214+
status = self.plm.status()
215215

216216
raise WaitTimeoutError()
217217

218218
def wait_for_clone_completed(self):
219219
"""Wait for the PLM service completed clone."""
220-
status = self.mlink.status()
220+
status = self.plm.status()
221221
assert status["state"] != PLM.State.IDLE, status
222222

223223
for _ in range(self.wait_timeout * 2):
224224
if status["initialSync"]["cloneCompleted"]:
225225
return
226226

227227
time.sleep(0.5)
228-
status = self.mlink.status()
228+
status = self.plm.status()
229229

230230
raise WaitTimeoutError()
231231

232232
@property
233233
def last_applied_op(self):
234234
"""Get the last applied operation time."""
235-
status = self.mlink.status()
235+
status = self.plm.status()
236236
if last_replicated_op_time := status.get("lastReplicatedOpTime"):
237237
t_s, i_s = last_replicated_op_time.split(".")
238238
return bson.Timestamp(int(t_s), int(i_s))

tests/test_collections.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pytest
66
import testing
7-
from mlink import PLM, Runner
7+
from plm import PLM, Runner
88
from pymongo import MongoClient
99
from testing import Testing
1010

@@ -125,6 +125,7 @@ def test_create_view_with_collation(t: Testing, phase: Runner.Phase):
125125
t.compare_all()
126126

127127

128+
@pytest.mark.timeout(15)
128129
@pytest.mark.parametrize("phase", [Runner.Phase.APPLY, Runner.Phase.CLONE])
129130
def test_create_timeseries_ignored(t: Testing, phase: Runner.Phase):
130131
with t.run(phase):
@@ -326,6 +327,7 @@ def test_modify_view(t: Testing, phase: Runner.Phase):
326327
t.compare_all()
327328

328329

330+
@pytest.mark.timeout(15)
329331
@pytest.mark.parametrize("phase", [Runner.Phase.APPLY, Runner.Phase.CLONE])
330332
def test_modify_timeseries_options_ignored(t: Testing, phase: Runner.Phase):
331333
t.source["db_1"].create_collection(
@@ -586,7 +588,7 @@ def test_plm_109_rename_complex(t: Testing, phase: Runner.Phase):
586588

587589
t.compare_all()
588590

589-
591+
@pytest.mark.timeout(30)
590592
def test_plm_110_rename_during_clone_and_repl(t: Testing):
591593
payload = random.randbytes(1000)
592594
for i in range(10):

tests/test_documents.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pymongo
55
import pytest
6-
from mlink import Runner
6+
from plm import Runner
77
from testing import Testing
88

99

tests/test_indexes.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import pymongo
66
import pytest
7-
from mlink import Runner
7+
from plm import Runner
88
from testing import Testing
99

1010

@@ -61,12 +61,12 @@ def test_create_partial(t: Testing, phase: Runner.Phase):
6161

6262
@pytest.mark.parametrize("phase", [Runner.Phase.APPLY, Runner.Phase.CLONE])
6363
def test_create_hidden(t: Testing, phase: Runner.Phase):
64-
with t.run(phase) as mlink:
64+
with t.run(phase) as plm:
6565
name = t.source["db_1"]["coll_1"].create_index({"i": 1}, hidden=True)
6666
assert t.source["db_1"]["coll_1"].index_information()[name]["hidden"]
6767

6868
if phase == Runner.Phase.APPLY:
69-
mlink.wait_for_current_optime()
69+
plm.wait_for_current_optime()
7070
assert "hidden" not in t.target["db_1"]["coll_1"].index_information()[name]
7171

7272
t.compare_all()
@@ -296,7 +296,7 @@ def test_modify_unique(t: Testing, phase: Runner.Phase):
296296

297297
@pytest.mark.parametrize("phase", [Runner.Phase.APPLY, Runner.Phase.CLONE])
298298
def test_internal_create_many_props(t: Testing, phase: Runner.Phase):
299-
with t.run(phase) as mlink:
299+
with t.run(phase) as plm:
300300
options = {
301301
"unique": True,
302302
"hidden": True,
@@ -309,7 +309,7 @@ def test_internal_create_many_props(t: Testing, phase: Runner.Phase):
309309
assert source_index.get(prop) == val
310310

311311
if phase == Runner.Phase.APPLY:
312-
mlink.wait_for_current_optime()
312+
plm.wait_for_current_optime()
313313
target_index = t.target["db_1"]["coll_1"].index_information()[index_name]
314314
for prop, val in options.items():
315315
if prop == "expireAfterSeconds":
@@ -324,7 +324,7 @@ def test_internal_create_many_props(t: Testing, phase: Runner.Phase):
324324
def test_internal_modify_many_props(t: Testing, phase: Runner.Phase):
325325
index_name = t.source["db_1"]["coll_1"].create_index({"i": 1})
326326

327-
with t.run(phase) as mlink:
327+
with t.run(phase) as plm:
328328
t.source["db_1"].command(
329329
{
330330
"collMod": "coll_1",
@@ -336,7 +336,7 @@ def test_internal_modify_many_props(t: Testing, phase: Runner.Phase):
336336
assert source_index["prepareUnique"]
337337

338338
if phase == Runner.Phase.APPLY:
339-
mlink.wait_for_current_optime()
339+
plm.wait_for_current_optime()
340340
target_index = t.target["db_1"]["coll_1"].index_information()[index_name]
341341
assert "prepareUnique" not in target_index
342342

@@ -357,7 +357,7 @@ def test_internal_modify_many_props(t: Testing, phase: Runner.Phase):
357357
assert source_index.get(prop) == val
358358

359359
if phase == Runner.Phase.APPLY:
360-
mlink.wait_for_current_optime()
360+
plm.wait_for_current_optime()
361361
target_index = t.target["db_1"]["coll_1"].index_information()[index_name]
362362
for prop, val in modify_options.items():
363363
if prop == "expireAfterSeconds":
@@ -379,9 +379,9 @@ def test_internal_modify_index_props_complex(t: Testing, phase: Runner.Phase):
379379
assert "hidden" not in source_index1
380380
assert "expireAfterSeconds" not in source_index1
381381

382-
with t.run(phase) as mlink:
382+
with t.run(phase) as plm:
383383
if phase == Runner.Phase.APPLY:
384-
mlink.wait_for_current_optime()
384+
plm.wait_for_current_optime()
385385
target_index = t.target["db_1"]["coll_1"].index_information()[index_name]
386386
assert "prepareUnique" not in target_index
387387
assert "unique" not in target_index
@@ -408,7 +408,7 @@ def test_internal_modify_index_props_complex(t: Testing, phase: Runner.Phase):
408408
assert source_index2["expireAfterSeconds"] == 132
409409

410410
if phase == Runner.Phase.APPLY:
411-
mlink.wait_for_current_optime()
411+
plm.wait_for_current_optime()
412412
target_index = t.target["db_1"]["coll_1"].index_information()[index_name]
413413
assert "prepareUnique" not in target_index
414414
assert "unique" not in target_index
@@ -433,7 +433,7 @@ def test_internal_modify_index_props_complex(t: Testing, phase: Runner.Phase):
433433
assert source_index3["expireAfterSeconds"] == 133
434434

435435
if phase == Runner.Phase.APPLY:
436-
mlink.wait_for_current_optime()
436+
plm.wait_for_current_optime()
437437
target_index = t.target["db_1"]["coll_1"].index_information()[index_name]
438438
assert "prepareUnique" not in target_index
439439
assert "unique" not in target_index
@@ -449,16 +449,16 @@ def test_internal_modify_index_props_complex(t: Testing, phase: Runner.Phase):
449449

450450

451451
def test_manual_create_ttl(t: Testing):
452-
mlink = t.run(Runner.Phase.MANUAL)
452+
plm = t.run(Runner.Phase.MANUAL)
453453
try:
454454
t.source["db_1"]["coll_1"].create_index({"a": 1}, expireAfterSeconds=1)
455-
mlink.start()
455+
plm.start()
456456
t.source["db_1"]["coll_1"].create_index({"b": 1}, expireAfterSeconds=1)
457-
mlink.wait_for_initial_sync()
457+
plm.wait_for_initial_sync()
458458
t.source["db_1"]["coll_1"].create_index({"c": 1}, expireAfterSeconds=1)
459-
mlink.finalize()
459+
plm.finalize()
460460
except:
461-
mlink.finalize(fast=True)
461+
plm.finalize(fast=True)
462462
raise
463463

464464
t.compare_all()

0 commit comments

Comments
 (0)