def check_compress_service_logs_swallow_error(self): """Try compressing a non-existent service log, and check that it logs a message without throwing an error. """ from tests.ducktape_mock import session_context tc = TestContext(session_context=session_context(), module=sys.modules[DummyTestNoDescription.__module__], cls=DummyTestNoDescription, function=DummyTestNoDescription.test_this) tc._logger = logging.getLogger(__name__) temp_log_file = tempfile.NamedTemporaryFile(delete=False).name try: tmp_log_handler = logging.FileHandler(temp_log_file) tc._logger.addHandler(tmp_log_handler) test_obj = tc.cls(tc) # Expect an error to be triggered but swallowed test_obj.compress_service_logs(node=None, service=None, node_logs=["hi"]) tmp_log_handler.close() with open(temp_log_file, "r") as f: s = f.read() assert s.find("Error compressing log hi") >= 0 finally: if os.path.exists(temp_log_file): os.remove(temp_log_file)
def check_test_context_double_close(self): context = TestContext(session_context=ducktape_mock.session_context(), cls=DummyTest, function=DummyTest.test_function_description) context.close() context.close() assert not hasattr(context, "services")
def check_no_description(self): """If nobody has a docstring, there shouldn't be an error, and description should be empty string""" context = TestContext( session_context=ducktape_mock.session_context(), cls=DummyTestNoDescription, function=DummyTestNoDescription.test_this, ) assert context.description == ""
def check_cluster_property(self): exp_cluster = ClusterSpec.simple_linux(5) tc = TestContext(session_context=ducktape_mock.session_context(), cluster=exp_cluster, cls=DummyTest, function=DummyTest.test_function_description) test_obj = tc.cls(tc) assert test_obj.cluster == exp_cluster
def check_copy_constructor(self): """Regression test against a bug introduced in 0.3.7 The TestContext copy constructor was copying the ServiceRegistry object by reference. As a result, services registering themselves with one test context would be registered with the copied context as well, resulting in the length of the service registry to grow additively from test to test. This problem cropped up in particular with parametrized tests. """ expander = MarkedFunctionExpander(session_context=session_context(), cls=DummyTest, function=DummyTest.test_me) ctx_list = expander.expand() for ctx in ctx_list: # Constructing an instance of the test class causes a service to be registered with the test context ctx.cls(ctx) # Ensure that each context.services object is a unique reference assert len(set(id(ctx.services) for ctx in ctx_list)) == len(ctx_list)
def check_copy_constructor(self): """Regression test against a bug introduced in 0.3.7 The TestContext copy constructor was copying the ServiceRegistry object by reference. As a result, services registering themselves with one test context would be registered with the copied context as well, resulting in the length of the service registry to grow additively from test to test. This problem cropped up in particular with parametrized tests. """ expander = MarkedFunctionExpander(session_context=session_context(), cls=DummyTest, function=DummyTest.test_me, cluster=MagicMock()) ctx_list = expander.expand() for ctx in ctx_list: # Constructing an instance of the test class causes a service to be registered with the test context ctx.cls(ctx) # Ensure that each context.services object is a unique reference assert len(set(id(ctx.services) for ctx in ctx_list)) == len(ctx_list)
def check_simple_messaging(self): s_context = session_context() cluster = LocalhostCluster(num_nodes=1000) t_context = test_context(s_context, cluster) client_id = "test-runner-{}-{}".format(os.getpid(), id(self)) receiver_response_factory = EventResponseFactory() receiver = Receiver(5556, 5656) receiver.start() port = receiver.port try: p = mp.Process(target=self.ready_response, args=(client_id, port)) p.start() event = receiver.recv(timeout=10000) assert event["event_type"] == ClientEventFactory.READY logging.info('replying to client') receiver.send(receiver_response_factory.ready(event, s_context, t_context, cluster)) finally: p.join()
def check_from_class(self): """If the test method has no docstring, description should come from the class docstring""" context = TestContext(session_context=ducktape_mock.session_context(), cls=DummyTest, function=DummyTest.test_class_description) assert context.description == "class description"
def check_from_function(self): """If the function has a docstring, the description should come from the function""" context = TestContext(session_context=ducktape_mock.session_context(), cls=DummyTest, function=DummyTest.test_function_description) assert context.description == "function description"
def setup_method(self, method): self.cluster = LocalhostCluster() self.session_context = session_context(cluster=self.cluster) self.context = test_context(self.session_context)
def setup(self): dir = tempfile.gettempdir() session_ctx = session_context(results_dir=dir) test_ctx = TestContext(session_context=session_ctx) return TemplateRenderingTest(test_ctx)
def check_from_class(self): """If the test method has no docstring, description should come from the class docstring""" context = TestContext( session_context=ducktape_mock.session_context(), cls=DummyTest, function=DummyTest.test_class_description ) assert context.description == "class description"
def check_from_function(self): """If the function has a docstring, the description should come from the function""" context = TestContext( session_context=ducktape_mock.session_context(), cls=DummyTest, function=DummyTest.test_function_description ) assert context.description == "function description"
def check_no_description(self): """If nobody has a docstring, there shouldn't be an error, and description should be empty string""" context = TestContext(session_context=ducktape_mock.session_context(), cls=DummyTestNoDescription, function=DummyTestNoDescription.test_this) assert context.description == ""
def setup_method(self, _): self.cluster = LocalhostCluster() self.session_context = session_context() self.context = test_context(self.session_context, cluster=self.cluster)
def setup_method(self, _): self.cluster = LocalhostCluster(is_type_based=False) self.session_context = session_context() self.context = test_context(self.session_context, cluster=self.cluster)