forked from mongodb/mongo-python-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_change_stream.py
More file actions
686 lines (590 loc) · 26.7 KB
/
test_change_stream.py
File metadata and controls
686 lines (590 loc) · 26.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
# Copyright 2017 MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test the change_stream module."""
import random
import os
import re
import sys
import string
import threading
import time
import uuid
from contextlib import contextmanager
from itertools import product
sys.path[0:0] = ['']
from bson import BSON, ObjectId, SON, json_util
from bson.binary import (ALL_UUID_REPRESENTATIONS,
Binary,
STANDARD,
PYTHON_LEGACY)
from bson.py3compat import iteritems
from bson.raw_bson import DEFAULT_RAW_BSON_OPTIONS, RawBSONDocument
from pymongo import monitoring
from pymongo.change_stream import _NON_RESUMABLE_GETMORE_ERRORS
from pymongo.command_cursor import CommandCursor
from pymongo.errors import (InvalidOperation, OperationFailure,
ServerSelectionTimeoutError)
from pymongo.message import _CursorAddress
from pymongo.read_concern import ReadConcern
from test import client_context, unittest, IntegrationTest
from test.utils import (
EventListener, WhiteListEventListener, rs_or_single_client
)
class TestClusterChangeStream(IntegrationTest):
@classmethod
@client_context.require_version_min(4, 0, 0, -1)
@client_context.require_no_mmap
@client_context.require_no_standalone
def setUpClass(cls):
super(TestClusterChangeStream, cls).setUpClass()
cls.dbs = [cls.db, cls.client.pymongo_test_2]
@classmethod
def tearDownClass(cls):
for db in cls.dbs:
cls.client.drop_database(db)
super(TestClusterChangeStream, cls).tearDownClass()
def change_stream(self, *args, **kwargs):
return self.client.watch(*args, **kwargs)
def generate_unique_collnames(self, numcolls):
# Generate N collection names unique to a test.
collnames = []
for idx in range(1, numcolls + 1):
collnames.append(self.id() + '_' + str(idx))
return collnames
def insert_and_check(self, change_stream, db, collname, doc):
coll = db[collname]
coll.insert_one(doc)
change = next(change_stream)
self.assertEqual(change['operationType'], 'insert')
self.assertEqual(change['ns'], {'db': db.name,
'coll': collname})
self.assertEqual(change['fullDocument'], doc)
def test_simple(self):
collnames = self.generate_unique_collnames(3)
with self.change_stream() as change_stream:
for db, collname in product(self.dbs, collnames):
self.insert_and_check(
change_stream, db, collname, {'_id': collname}
)
class TestDatabaseChangeStream(IntegrationTest):
@classmethod
@client_context.require_version_min(4, 0, 0, -1)
@client_context.require_no_mmap
@client_context.require_no_standalone
def setUpClass(cls):
super(TestDatabaseChangeStream, cls).setUpClass()
def change_stream(self, *args, **kwargs):
return self.db.watch(*args, **kwargs)
def generate_unique_collnames(self, numcolls):
# Generate N collection names unique to a test.
collnames = []
for idx in range(1, numcolls + 1):
collnames.append(self.id() + '_' + str(idx))
return collnames
def insert_and_check(self, change_stream, collname, doc):
coll = self.db[collname]
coll.insert_one(doc)
change = next(change_stream)
self.assertEqual(change['operationType'], 'insert')
self.assertEqual(change['ns'], {'db': self.db.name,
'coll': collname})
self.assertEqual(change['fullDocument'], doc)
def test_simple(self):
collnames = self.generate_unique_collnames(3)
with self.change_stream() as change_stream:
for collname in collnames:
self.insert_and_check(
change_stream, collname, {'_id': uuid.uuid4()}
)
def test_isolation(self):
# Ensure inserts to other dbs don't show up in our ChangeStream.
other_db = self.client.pymongo_test_temp
self.assertNotEqual(
other_db, self.db, msg="Isolation must be tested on separate DBs"
)
collname = self.id()
with self.change_stream() as change_stream:
other_db[collname].insert_one({'_id': uuid.uuid4()})
self.insert_and_check(
change_stream, collname, {'_id': uuid.uuid4()}
)
self.client.drop_database(other_db)
class TestCollectionChangeStream(IntegrationTest):
@classmethod
@client_context.require_version_min(3, 5, 11)
@client_context.require_no_mmap
@client_context.require_no_standalone
def setUpClass(cls):
super(TestCollectionChangeStream, cls).setUpClass()
cls.coll = cls.db.change_stream_test
# SERVER-31885 On a mongos the database must exist in order to create
# a changeStream cursor. However, WiredTiger drops the database when
# there are no more collections. Let's prevent that.
cls.db.prevent_implicit_database_deletion.insert_one({})
@classmethod
def tearDownClass(cls):
cls.db.prevent_implicit_database_deletion.drop()
super(TestCollectionChangeStream, cls).tearDownClass()
def setUp(self):
# Use a new collection for each test.
self.coll = self.db[self.id()]
def tearDown(self):
self.coll.drop()
def insert_and_check(self, change_stream, doc):
self.coll.insert_one(doc)
change = next(change_stream)
self.assertEqual(change['operationType'], 'insert')
self.assertEqual(change['ns'], {'db': self.coll.database.name,
'coll': self.coll.name})
self.assertEqual(change['fullDocument'], doc)
def test_watch(self):
with self.coll.watch(
[{'$project': {'foo': 0}}], full_document='updateLookup',
max_await_time_ms=1000, batch_size=100) as change_stream:
self.assertEqual([{'$project': {'foo': 0}}],
change_stream._pipeline)
self.assertEqual('updateLookup', change_stream._full_document)
self.assertIsNone(change_stream._resume_token)
self.assertEqual(1000, change_stream._max_await_time_ms)
self.assertEqual(100, change_stream._batch_size)
self.assertIsInstance(change_stream._cursor, CommandCursor)
self.assertEqual(
1000, change_stream._cursor._CommandCursor__max_await_time_ms)
self.coll.insert_one({})
change = change_stream.next()
resume_token = change['_id']
with self.assertRaises(TypeError):
self.coll.watch(pipeline={})
with self.assertRaises(TypeError):
self.coll.watch(full_document={})
# No Error.
with self.coll.watch(resume_after=resume_token):
pass
def test_full_pipeline(self):
"""$changeStream must be the first stage in a change stream pipeline
sent to the server.
"""
listener = WhiteListEventListener("aggregate")
results = listener.results
client = rs_or_single_client(event_listeners=[listener])
self.addCleanup(client.close)
coll = client[self.db.name][self.coll.name]
with coll.watch([{'$project': {'foo': 0}}]) as _:
pass
self.assertEqual(1, len(results['started']))
command = results['started'][0]
self.assertEqual('aggregate', command.command_name)
self.assertEqual([
{'$changeStream': {'fullDocument': 'default'}},
{'$project': {'foo': 0}}],
command.command['pipeline'])
def test_iteration(self):
with self.coll.watch(batch_size=2) as change_stream:
num_inserted = 10
self.coll.insert_many([{} for _ in range(num_inserted)])
self.coll.drop()
inserts_received = 0
for change in change_stream:
if change['operationType'] not in ('drop', 'invalidate'):
self.assertEqual(change['operationType'], 'insert')
inserts_received += 1
self.assertEqual(num_inserted, inserts_received)
# Last change should be invalidate.
self.assertEqual(change['operationType'], 'invalidate')
with self.assertRaises(StopIteration):
change_stream.next()
with self.assertRaises(StopIteration):
next(change_stream)
def _test_next_blocks(self, change_stream):
inserted_doc = {'_id': ObjectId()}
changes = []
t = threading.Thread(
target=lambda: changes.append(change_stream.next()))
t.start()
# Sleep for a bit to prove that the call to next() blocks.
time.sleep(1)
self.assertTrue(t.is_alive())
self.assertFalse(changes)
self.coll.insert_one(inserted_doc)
# Join with large timeout to give the server time to return the change,
# in particular for shard clusters.
t.join(30)
self.assertFalse(t.is_alive())
self.assertEqual(1, len(changes))
self.assertEqual(changes[0]['operationType'], 'insert')
self.assertEqual(changes[0]['fullDocument'], inserted_doc)
def test_next_blocks(self):
"""Test that next blocks until a change is readable"""
# Use a short await time to speed up the test.
with self.coll.watch(max_await_time_ms=250) as change_stream:
self._test_next_blocks(change_stream)
def test_aggregate_cursor_blocks(self):
"""Test that an aggregate cursor blocks until a change is readable."""
with self.coll.aggregate([{'$changeStream': {}}],
maxAwaitTimeMS=250) as change_stream:
self._test_next_blocks(change_stream)
def test_concurrent_close(self):
"""Ensure a ChangeStream can be closed from another thread."""
# Use a short await time to speed up the test.
with self.coll.watch(max_await_time_ms=250) as change_stream:
def iterate_cursor():
for _ in change_stream:
pass
t = threading.Thread(target=iterate_cursor)
t.start()
self.coll.insert_one({})
time.sleep(1)
change_stream.close()
t.join(3)
self.assertFalse(t.is_alive())
def test_update_resume_token(self):
"""ChangeStream must continuously track the last seen resumeToken."""
with self.coll.watch() as change_stream:
self.assertIsNone(change_stream._resume_token)
for _ in range(3):
self.coll.insert_one({})
change = next(change_stream)
self.assertEqual(change['_id'], change_stream._resume_token)
@client_context.require_no_mongos # PYTHON-1739
def test_raises_error_on_missing_id(self):
"""ChangeStream will raise an exception if the server response is
missing the resume token.
"""
with self.coll.watch([{'$project': {'_id': 0}}]) as change_stream:
self.coll.insert_one({})
# Server returns an error after SERVER-37786, otherwise pymongo
# raises an error.
with self.assertRaises((InvalidOperation, OperationFailure)):
next(change_stream)
# The cursor should now be closed.
with self.assertRaises(StopIteration):
next(change_stream)
def test_resume_on_error(self):
"""ChangeStream will automatically resume one time on a resumable
error (including not master) with the initial pipeline and options,
except for the addition/update of a resumeToken.
"""
with self.coll.watch([]) as change_stream:
self.insert_and_check(change_stream, {'_id': 1})
# Cause a cursor not found error on the next getMore.
cursor = change_stream._cursor
address = _CursorAddress(cursor.address, self.coll.full_name)
self.client._close_cursor_now(cursor.cursor_id, address)
self.insert_and_check(change_stream, {'_id': 2})
def test_does_not_resume_fatal_errors(self):
"""ChangeStream will not attempt to resume fatal server errors."""
for code in _NON_RESUMABLE_GETMORE_ERRORS:
with self.coll.watch() as change_stream:
self.coll.insert_one({})
def mock_next(*args, **kwargs):
change_stream._cursor.close()
raise OperationFailure('Mock server error', code=code)
original_next = change_stream._cursor.next
change_stream._cursor.next = mock_next
with self.assertRaises(OperationFailure):
next(change_stream)
change_stream._cursor.next = original_next
with self.assertRaises(StopIteration):
next(change_stream)
def test_initial_empty_batch(self):
"""Ensure that a cursor returned from an aggregate command with a
cursor id, and an initial empty batch, is not closed on the driver
side.
"""
with self.coll.watch() as change_stream:
# The first batch should be empty.
self.assertEqual(
0, len(change_stream._cursor._CommandCursor__data))
cursor_id = change_stream._cursor.cursor_id
self.assertTrue(cursor_id)
self.insert_and_check(change_stream, {})
# Make sure we're still using the same cursor.
self.assertEqual(cursor_id, change_stream._cursor.cursor_id)
def test_kill_cursors(self):
"""The killCursors command sent during the resume process must not be
allowed to raise an exception.
"""
def raise_error():
raise ServerSelectionTimeoutError('mock error')
with self.coll.watch([]) as change_stream:
self.insert_and_check(change_stream, {'_id': 1})
# Cause a cursor not found error on the next getMore.
cursor = change_stream._cursor
address = _CursorAddress(cursor.address, self.coll.full_name)
self.client._close_cursor_now(cursor.cursor_id, address)
cursor.close = raise_error
self.insert_and_check(change_stream, {'_id': 2})
def test_unknown_full_document(self):
"""Must rely on the server to raise an error on unknown fullDocument.
"""
try:
with self.coll.watch(full_document='notValidatedByPyMongo'):
pass
except OperationFailure:
pass
def test_change_operations(self):
"""Test each operation type."""
expected_ns = {'db': self.coll.database.name, 'coll': self.coll.name}
with self.coll.watch() as change_stream:
# Insert.
inserted_doc = {'_id': ObjectId(), 'foo': 'bar'}
self.coll.insert_one(inserted_doc)
change = change_stream.next()
self.assertTrue(change['_id'])
self.assertEqual(change['operationType'], 'insert')
self.assertEqual(change['ns'], expected_ns)
self.assertEqual(change['fullDocument'], inserted_doc)
# Update.
update_spec = {'$set': {'new': 1}, '$unset': {'foo': 1}}
self.coll.update_one(inserted_doc, update_spec)
change = change_stream.next()
self.assertTrue(change['_id'])
self.assertEqual(change['operationType'], 'update')
self.assertEqual(change['ns'], expected_ns)
self.assertNotIn('fullDocument', change)
self.assertEqual({'updatedFields': {'new': 1},
'removedFields': ['foo']},
change['updateDescription'])
# Replace.
self.coll.replace_one({'new': 1}, {'foo': 'bar'})
change = change_stream.next()
self.assertTrue(change['_id'])
self.assertEqual(change['operationType'], 'replace')
self.assertEqual(change['ns'], expected_ns)
self.assertEqual(change['fullDocument'], inserted_doc)
# Delete.
self.coll.delete_one({'foo': 'bar'})
change = change_stream.next()
self.assertTrue(change['_id'])
self.assertEqual(change['operationType'], 'delete')
self.assertEqual(change['ns'], expected_ns)
self.assertNotIn('fullDocument', change)
# Invalidate.
self.coll.drop()
change = change_stream.next()
# 4.1 returns a "drop" change document.
if change['operationType'] == 'drop':
self.assertTrue(change['_id'])
self.assertEqual(change['ns'], expected_ns)
# Last change should be invalidate.
change = change_stream.next()
self.assertTrue(change['_id'])
self.assertEqual(change['operationType'], 'invalidate')
self.assertNotIn('ns', change)
self.assertNotIn('fullDocument', change)
# The ChangeStream should be dead.
with self.assertRaises(StopIteration):
change_stream.next()
def test_raw(self):
"""Test with RawBSONDocument."""
raw_coll = self.coll.with_options(
codec_options=DEFAULT_RAW_BSON_OPTIONS)
with raw_coll.watch() as change_stream:
raw_doc = RawBSONDocument(BSON.encode({'_id': 1}))
self.coll.insert_one(raw_doc)
change = next(change_stream)
self.assertIsInstance(change, RawBSONDocument)
self.assertEqual(change['operationType'], 'insert')
self.assertEqual(change['ns']['db'], self.coll.database.name)
self.assertEqual(change['ns']['coll'], self.coll.name)
self.assertEqual(change['fullDocument'], raw_doc)
self.assertEqual(change['_id'], change_stream._resume_token)
def test_uuid_representations(self):
"""Test with uuid document _ids and different uuid_representation."""
for uuid_representation in ALL_UUID_REPRESENTATIONS:
for id_subtype in (STANDARD, PYTHON_LEGACY):
resume_token = None
options = self.coll.codec_options.with_options(
uuid_representation=uuid_representation)
coll = self.coll.with_options(codec_options=options)
with coll.watch() as change_stream:
coll.insert_one(
{'_id': Binary(uuid.uuid4().bytes, id_subtype)})
resume_token = change_stream.next()['_id']
# Should not error.
coll.watch(resume_after=resume_token)
def test_document_id_order(self):
"""Test with document _ids that need their order preserved."""
random_keys = random.sample(string.ascii_letters,
len(string.ascii_letters))
random_doc = {'_id': SON([(key, key) for key in random_keys])}
for document_class in (dict, SON, RawBSONDocument):
options = self.coll.codec_options.with_options(
document_class=document_class)
coll = self.coll.with_options(codec_options=options)
with coll.watch() as change_stream:
coll.insert_one(random_doc)
resume_token = change_stream.next()['_id']
# The resume token is always a document.
self.assertIsInstance(resume_token, document_class)
# Should not error.
coll.watch(resume_after=resume_token)
coll.delete_many({})
def test_read_concern(self):
"""Test readConcern is not validated by the driver."""
# Read concern 'local' is not allowed for $changeStream.
coll = self.coll.with_options(read_concern=ReadConcern('local'))
with self.assertRaises(OperationFailure):
coll.watch()
# Does not error.
coll = self.coll.with_options(read_concern=ReadConcern('majority'))
with coll.watch():
pass
class TestAllScenarios(unittest.TestCase):
@classmethod
@client_context.require_connection
def setUpClass(cls):
cls.listener = WhiteListEventListener("aggregate")
cls.client = rs_or_single_client(event_listeners=[cls.listener])
@classmethod
def tearDownClass(cls):
cls.client
def setUp(self):
self.listener.results.clear()
def setUpCluster(self, scenario_dict):
assets = [
(scenario_dict["database_name"], scenario_dict["collection_name"]),
(scenario_dict["database2_name"], scenario_dict["collection2_name"]),
]
for db, coll in assets:
self.client.drop_database(db)
self.client[db].create_collection(coll)
def tearDown(self):
self.listener.results.clear()
_TEST_PATH = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'change_streams'
)
def camel_to_snake(camel):
# Regex to convert CamelCase to snake_case.
snake = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', camel)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', snake).lower()
def get_change_stream(client, scenario_def, test):
# Get target namespace on which to instantiate change stream
target = test["target"]
if target == "collection":
db = client.get_database(scenario_def["database_name"])
cs_target = db.get_collection(scenario_def["collection_name"])
elif target == "database":
cs_target = client.get_database(scenario_def["database_name"])
elif target == "client":
cs_target = client
else:
raise ValueError("Invalid target in spec")
# Construct change stream kwargs dict
cs_pipeline = test["changeStreamPipeline"]
options = test["changeStreamOptions"]
cs_options = {}
for key, value in iteritems(options):
cs_options[camel_to_snake(key)] = value
# Create and return change stream
return cs_target.watch(pipeline=cs_pipeline, **cs_options)
def run_operation(client, operation):
# Apply specified operations
opname = camel_to_snake(operation["name"])
arguments = operation["arguments"]
cmd = getattr(client.get_database(
operation["database"]).get_collection(
operation["collection"]), opname
)
return cmd(**arguments)
def assert_dict_is_subset(superdict, subdict):
"""Check that subdict is a subset of superdict."""
exempt_fields = ["documentKey", "_id"]
for key, value in iteritems(subdict):
if key not in superdict:
assert False
if isinstance(value, dict):
assert_dict_is_subset(superdict[key], value)
continue
if key in exempt_fields:
superdict[key] = "42"
assert superdict[key] == value
def check_event(event, expectation_dict):
if event is None:
raise AssertionError
for key, value in iteritems(expectation_dict):
if isinstance(value, dict):
assert_dict_is_subset(
getattr(event, key), value
)
else:
assert getattr(event, key) == value
def create_test(scenario_def, test):
def run_scenario(self):
# Set up
self.setUpCluster(scenario_def)
try:
with get_change_stream(
self.client, scenario_def, test
) as change_stream:
for operation in test["operations"]:
# Run specified operations
run_operation(self.client, operation)
num_expected_changes = len(test["result"]["success"])
changes = [
change_stream.next() for _ in range(num_expected_changes)
]
except OperationFailure as exc:
if test["result"].get("error") is None:
raise
expected_code = test["result"]["error"]["code"]
self.assertEqual(exc.code, expected_code)
else:
# Check for expected output from change streams
for change, expected_changes in zip(changes, test["result"]["success"]):
assert_dict_is_subset(change, expected_changes)
self.assertEqual(len(changes), len(test["result"]["success"]))
finally:
# Check for expected events
results = self.listener.results
for expectation in test["expectations"]:
for idx, (event_type, event_desc) in enumerate(iteritems(expectation)):
results_key = event_type.split("_")[1]
event = results[results_key][idx] if len(results[results_key]) > idx else None
check_event(event, event_desc)
return run_scenario
def create_tests():
for dirpath, _, filenames in os.walk(_TEST_PATH):
dirname = os.path.split(dirpath)[-1]
for filename in filenames:
with open(os.path.join(dirpath, filename)) as scenario_stream:
scenario_def = json_util.loads(scenario_stream.read())
test_type = os.path.splitext(filename)[0]
for test in scenario_def['tests']:
new_test = create_test(scenario_def, test)
new_test = client_context.require_no_mmap(new_test)
if 'minServerVersion' in test:
min_ver = tuple(
int(elt) for
elt in test['minServerVersion'].split('.'))
new_test = client_context.require_version_min(*min_ver)(
new_test)
if 'maxServerVersion' in test:
max_ver = tuple(
int(elt) for
elt in test['maxServerVersion'].split('.'))
new_test = client_context.require_version_max(*max_ver)(
new_test)
topologies = test['topology']
new_test = client_context.require_cluster_type(topologies)(
new_test)
test_name = 'test_%s_%s_%s' % (
dirname,
test_type.replace("-", "_"),
str(test['description'].replace(" ", "_")))
new_test.__name__ = test_name
setattr(TestAllScenarios, new_test.__name__, new_test)
create_tests()
if __name__ == '__main__':
unittest.main()