From 5236a33fc1ebc60e1a8dbcd43605240b1cc18da8 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sun, 16 May 2021 17:35:16 -0500 Subject: [PATCH] make mongo tests safer to run in parallel pants runs each test file separately in pytest. So, if two files try to modify the same database at the same time, we'll get strange results. So, modify the db name to ensure that they are safe in parallel. --- st2common/tests/unit/test_db.py | 2 ++ st2tests/st2tests/config.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/st2common/tests/unit/test_db.py b/st2common/tests/unit/test_db.py index 7fe10ef3f4..0ae1ee79f1 100644 --- a/st2common/tests/unit/test_db.py +++ b/st2common/tests/unit/test_db.py @@ -126,6 +126,7 @@ def test_check_connect(self): def test_network_level_compression(self): disconnect() + # db is not modified in this test, so this is safe to run in parallel. db_name = "st2" db_host = "localhost" db_port = 27017 @@ -521,6 +522,7 @@ def test_db_connect_server_selection_timeout_ssl_on_non_ssl_listener(self): # and propagating the error disconnect() + # db is not modified in this test, so this is safe to run in parallel. db_name = "st2" db_host = "localhost" db_port = 27017 diff --git a/st2tests/st2tests/config.py b/st2tests/st2tests/config.py index feef6f589f..9848ffb626 100644 --- a/st2tests/st2tests/config.py +++ b/st2tests/st2tests/config.py @@ -85,7 +85,9 @@ def _register_config_opts(): def _override_db_opts(): - CONF.set_override(name="db_name", override="st2-test", group="database") + # use separate dbs for safer parallel test runs + db_name = f"st2-test{os.environ.get('ST2TESTS_PARALLEL_SLOT', '')}" + CONF.set_override(name="db_name", override=db_name, group="database") CONF.set_override(name="host", override="127.0.0.1", group="database")