Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
REF: new logic for require_no_mmap decorator
  • Loading branch information
prashantmital committed Jun 26, 2018
commit 76c53ace779688f8bd5ee345a22c4a1a190c7fc1
27 changes: 18 additions & 9 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ def _init_client(self):

try:
self.cmd_line = self.client.admin.command('getCmdLineOpts')
self.server_status = self.client.admin.command('serverStatus')
except pymongo.errors.OperationFailure as e:
msg = e.details.get('errmsg', '')
if e.code == 13 or 'unauthorized' in msg or 'login' in msg:
Expand All @@ -249,8 +248,8 @@ def _init_client(self):

# May not have this if OperationFailure was raised earlier.
self.cmd_line = self.client.admin.command('getCmdLineOpts')
self.server_status = self.client.admin.command('serverStatus')

self.server_status = self.client.admin.command('serverStatus')
self.ismaster = ismaster = self.client.admin.command('isMaster')
self.sessions_enabled = 'logicalSessionTimeoutMinutes' in ismaster

Expand Down Expand Up @@ -427,14 +426,24 @@ def require_connection(self, func):
"Cannot connect to MongoDB on %s" % (self.pair,),
func=func)

def require_storage_engine(self, engine):
"""Run a test only if the server is running the specified storage
engine (as determined by the `db.serverStatus` command)."""
#server_status = self.client.admin.command("serverStatus")
#current_engine = server_status["storageEngine"]["name"]
def require_no_mmap(self, func):
"""Run a test only if the server is not using the MMAPv1 storage
engine. Only works for standalone and replica sets; tests are
run regardless of storage engine on sharded clusters. """
def is_not_mmap():
if self.is_mongos:
return True
try:
storage_engine = self.server_status.get(
'storageEngine').get('name')
except AttributeError:
# Raised if the storageEngine key does not exist or if
# self.server_status is None.
return False
return storage_engine != 'mmapv1'

return self._require(
lambda: engine == self.server_status["storageEngine"]["name"],
"Storage engine must be %s" % str(engine))
is_not_mmap, "Storage engine must not be MMAPv1", func=func)

def require_version_min(self, *ver):
"""Run a test only if the server version is at least ``version``."""
Expand Down
9 changes: 4 additions & 5 deletions test/test_change_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TestClusterChangeStream(IntegrationTest):

@classmethod
@client_context.require_version_min(4, 0, 0, -1)
@client_context.require_storage_engine("wiredTiger")
@client_context.require_no_mmap
@client_context.require_no_standalone
def setUpClass(cls):
super(TestClusterChangeStream, cls).setUpClass()
Expand Down Expand Up @@ -98,7 +98,7 @@ class TestDatabaseChangeStream(IntegrationTest):

@classmethod
@client_context.require_version_min(4, 0, 0, -1)
@client_context.require_storage_engine("wiredTiger")
@client_context.require_no_mmap
@client_context.require_no_standalone
def setUpClass(cls):
super(TestDatabaseChangeStream, cls).setUpClass()
Expand Down Expand Up @@ -149,7 +149,7 @@ class TestCollectionChangeStream(IntegrationTest):

@classmethod
@client_context.require_version_min(3, 5, 11)
@client_context.require_storage_engine("wiredTiger")
@client_context.require_no_mmap
@client_context.require_no_standalone
def setUpClass(cls):
super(TestCollectionChangeStream, cls).setUpClass()
Expand Down Expand Up @@ -648,8 +648,7 @@ def create_tests():

for test in scenario_def['tests']:
new_test = create_test(scenario_def, test)
new_test = client_context.require_storage_engine(
"wiredTiger")(new_test)
new_test = client_context.require_no_mmap(new_test)

if 'minServerVersion' in test:
min_ver = tuple(
Expand Down