Skip to content

Commit d0e441a

Browse files
committed
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.
1 parent 85e4066 commit d0e441a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

st2common/tests/unit/test_db.py

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def test_check_connect(self):
126126
def test_network_level_compression(self):
127127
disconnect()
128128

129+
# db is not modified in this test, so this is safe to run in parallel.
129130
db_name = "st2"
130131
db_host = "localhost"
131132
db_port = 27017
@@ -521,6 +522,7 @@ def test_db_connect_server_selection_timeout_ssl_on_non_ssl_listener(self):
521522
# and propagating the error
522523
disconnect()
523524

525+
# db is not modified in this test, so this is safe to run in parallel.
524526
db_name = "st2"
525527
db_host = "localhost"
526528
db_port = 27017

st2tests/st2tests/config.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ def _register_config_opts():
8585

8686

8787
def _override_db_opts():
88-
CONF.set_override(name="db_name", override="st2-test", group="database")
88+
# use separate dbs for safer parallel test runs
89+
db_name = f"st2-test{os.environ.get('ST2TESTS_PARALLEL_SLOT', '')}"
90+
CONF.set_override(name="db_name", override=db_name, group="database")
8991
CONF.set_override(name="host", override="127.0.0.1", group="database")
9092

9193

0 commit comments

Comments
 (0)