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
|
"""The unittest.TestCase for FSM workloads."""
from __future__ import absolute_import
import os.path
import threading
from buildscripts.resmokelib.testing.testcases import interface
from buildscripts.resmokelib.testing.testcases import jsrunnerfile
class FSMWorkloadTestCase(jsrunnerfile.JSRunnerFileTestCase):
"""An FSM workload to execute."""
REGISTERED_NAME = "fsm_workload_test"
_COUNTER_LOCK = threading.Lock()
_COUNTER = 0
def __init__( #pylint: disable=too-many-arguments
self, logger, fsm_workload, shell_executable=None, shell_options=None, same_db=False,
same_collection=False, db_name_prefix=None):
"""Initialize the FSMWorkloadTestCase with the FSM workload file."""
self.same_collection = same_collection
self.same_db = same_db or self.same_collection
self.db_name_prefix = db_name_prefix
self.dbpath_prefix = None
jsrunnerfile.JSRunnerFileTestCase.__init__(
self, logger, "FSM workload", fsm_workload,
test_runner_file="jstests/concurrency/fsm_libs/resmoke_runner.js",
shell_executable=shell_executable, shell_options=shell_options)
def configure(self, fixture, *args, **kwargs):
"""Configure the FSMWorkloadTestCase runner."""
interface.ProcessTestCase.configure(self, fixture, *args, **kwargs)
self.dbpath_prefix = self.fixture.get_dbpath_prefix()
global_vars = self.shell_options.get("global_vars", {}).copy()
test_data = global_vars.get("TestData", {}).copy()
self._populate_test_data(test_data)
global_vars["TestData"] = test_data
self.shell_options["global_vars"] = global_vars
@property
def fsm_workload(self):
"""Get the test name."""
return self.test_name
def _populate_test_data(self, test_data):
test_data["fsmWorkloads"] = self.fsm_workload
test_data["resmokeDbPathPrefix"] = self.dbpath_prefix
with FSMWorkloadTestCase._COUNTER_LOCK:
count = FSMWorkloadTestCase._COUNTER
if not self.same_db:
FSMWorkloadTestCase._COUNTER += 1
# We use a global incrementing counter as a prefix for the database name to avoid any
# collection lifecycle related issues in sharded clusters. This more closely matches how
# uniqueDBName() and uniqueCollName() would have returned distinct values when called once
# for each FSM workload in the entire schedule by runner.js.
test_prefix = self.db_name_prefix if self.db_name_prefix else "test"
test_data["dbNamePrefix"] = "{}{:d}_".format(test_prefix, count)
if not self.same_db:
test_data["sameDB"] = True
if not self.same_collection:
test_data["sameCollection"] = True
|