Skip to content

Commit ba15faa

Browse files
committed
Parameterize test methods
1 parent c94cc23 commit ba15faa

File tree

2 files changed

+23
-49
lines changed

2 files changed

+23
-49
lines changed

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def read(filename):
3434
'Cython',
3535
'asyncpg>=0.18.2, < 0.20',
3636
'pyodbc',
37-
'psycopg2-binary>=2.7.5'
37+
'psycopg2-binary>=2.7.5',
38+
'parameterized'
3839
],
3940
python_requires='>=3.6',
4041
classifiers=[

tests/bwc/test_recovery.py

+21-48
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,23 @@
11
import time
22
import unittest
33

4+
from parameterized import parameterized
45
from crate.client import connect
56
import random
67
from random import sample
78

89
from crate.qa.tests import NodeProvider, insert_data, UpgradePath
910

11+
UPGRADE_42_TO_43 = ('4.2.x to 4.3.x', UpgradePath('4.2.x', '4.3.x'), 3,)
12+
UPGRADE_43_TO_LATEST = ('4.3.x to latest-nightly', UpgradePath('4.3.x', 'latest-nightly'), 3,)
13+
1014

1115
class RecoveryTest(NodeProvider, unittest.TestCase):
16+
1217
"""
1318
In depth testing of the recovery mechanism during a rolling restart.
1419
Based on org.elasticsearch.upgrades.RecoveryIT.java
1520
"""
16-
17-
def test(self):
18-
self._run_tests(
19-
[
20-
UpgradePath('4.2.x', '4.3.x'),
21-
UpgradePath('4.3.x', 'latest-nightly'),
22-
],
23-
[
24-
self._test_relocation_with_concurrent_indexing,
25-
self._test_recovery,
26-
self._test_update_docs,
27-
self._test_recovery_closed_index,
28-
self._test_closed_index_during_rolling_upgrade,
29-
self._test_relocation_with_concurrent_indexing,
30-
]
31-
)
32-
33-
def test_from_4_3(self):
34-
self._run_tests(
35-
[
36-
UpgradePath('4.3.x', 'latest-nightly')
37-
],
38-
[
39-
self._test_turnoff_translog_retention_after_upgraded,
40-
self._test_operation_based_recovery,
41-
]
42-
)
43-
44-
def _run_tests(self, paths, tests):
45-
for path in paths:
46-
for test in tests:
47-
with self.subTest(repr(path)):
48-
try:
49-
self.setUp()
50-
print(f'Run {test.__name__} upgrading versions {path}')
51-
test(path, nodes=3)
52-
finally:
53-
self.tearDown()
54-
5521
def _assert_num_docs_by_node_id(self, conn, schema, table_name, node_id, expected_count):
5622
c = conn.cursor()
5723
c.execute('''select num_docs from sys.shards where schema_name = ? and table_name = ? and node['id'] = ?''',
@@ -94,7 +60,8 @@ def _upgrade_cluster(self, cluster, version, nodes):
9460
new_node = self.upgrade_node(node, version)
9561
cluster[i] = new_node
9662

97-
def _test_recovery_with_concurrent_indexing(self, path, nodes):
63+
@parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST])
64+
def test_recovery_with_concurrent_indexing(self, name, path, nodes):
9865
"""
9966
This test creates a new table and insert data at every stage of the
10067
rolling upgrade.
@@ -154,8 +121,8 @@ def _test_recovery_with_concurrent_indexing(self, path, nodes):
154121
for node_id in node_ids:
155122
self._assert_num_docs_by_node_id(conn, 'doc', 'test', node_id[0], 105)
156123

157-
def _test_relocation_with_concurrent_indexing(self, path, nodes):
158-
124+
@parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST])
125+
def test_relocation_with_concurrent_indexing(self, name, path, nodes):
159126
cluster = self._new_cluster(path.from_version, nodes)
160127
cluster.start()
161128

@@ -224,7 +191,8 @@ def _test_relocation_with_concurrent_indexing(self, path, nodes):
224191
for node_id in node_ids:
225192
self._assert_num_docs_by_node_id(conn, 'doc', 'test', node_id[0], 105)
226193

227-
def _test_recovery(self, path, nodes):
194+
@parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST])
195+
def test_recovery(self, name, path, nodes):
228196
"""
229197
This test creates a new table, insert data and asserts the state at every stage of the
230198
rolling upgrade.
@@ -261,7 +229,8 @@ def _test_recovery(self, path, nodes):
261229

262230
self._assert_is_green(conn, 'doc', 'test')
263231

264-
def _test_recovery_closed_index(self, path, nodes):
232+
@parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST])
233+
def test_recovery_closed_index(self, name, path, nodes):
265234
"""
266235
This test creates a table in the non upgraded cluster and closes it. It then
267236
checks that the table is effectively closed and potentially replicated.
@@ -292,7 +261,8 @@ def _test_recovery_closed_index(self, path, nodes):
292261

293262
self._assert_is_closed(conn, 'doc', 'test')
294263

295-
def _test_closed_index_during_rolling_upgrade(self, path, nodes):
264+
@parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST])
265+
def test_closed_index_during_rolling_upgrade(self, name, path, nodes):
296266
"""
297267
This test creates and closes a new table at every stage of the rolling
298268
upgrade. It then checks that the table is effectively closed and
@@ -341,7 +311,8 @@ def _test_closed_index_during_rolling_upgrade(self, path, nodes):
341311

342312
self._assert_is_closed(conn, 'doc', 'upgraded_cluster')
343313

344-
def _test_update_docs(self, path, nodes):
314+
@parameterized.expand([UPGRADE_42_TO_43, UPGRADE_43_TO_LATEST])
315+
def test_update_docs(self, name, path, nodes):
345316
"""
346317
This test creates a new table, insert data and updates data at every state at every stage of the
347318
rolling upgrade.
@@ -391,7 +362,8 @@ def _test_update_docs(self, path, nodes):
391362
for result in res:
392363
self.assertEqual(result['rowcount'], 1)
393364

394-
def _test_operation_based_recovery(self, path, nodes):
365+
@parameterized.expand([UPGRADE_43_TO_LATEST])
366+
def test_operation_based_recovery(self, name, path, nodes):
395367
"""
396368
Tests that we should perform an operation-based recovery if there were
397369
some but not too many uncommitted documents (i.e., less than 10% of
@@ -444,7 +416,8 @@ def _test_operation_based_recovery(self, path, nodes):
444416

445417
self._assert_ensure_checkpoints_are_synced(conn, 'doc', 'test')
446418

447-
def _test_turnoff_translog_retention_after_upgraded(self, path, nodes):
419+
@parameterized.expand([UPGRADE_43_TO_LATEST])
420+
def test_turnoff_translog_retention_after_upgraded(self, name, path, nodes):
448421
"""
449422
Verifies that once all shard copies on the new version, we should turn
450423
off the translog retention for indices with soft-deletes.

0 commit comments

Comments
 (0)