Skip to content

Commit c349703

Browse files
authored
Attempt to remove flakyness in tests for Cassandra Nodetool (DataDog#22653)
1 parent df6fd50 commit c349703

2 files changed

Lines changed: 19 additions & 14 deletions

File tree

cassandra_nodetool/tests/compose/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ services:
3434
CASSANDRA_SEEDS: ${CASSANDRA_SEEDS}
3535
JVM_EXTRA_OPTS: "-Dcassandra.skip_schema_check=true"
3636
healthcheck:
37-
test: ["CMD-SHELL", "cqlsh -e 'SELECT now() FROM system.local'"]
37+
test: ["CMD-SHELL", "cqlsh -e 'SELECT now() FROM system.local' && test $(nodetool status | grep -c '^UN') -eq 2"]
3838
interval: 15s
3939
timeout: 10s
4040
retries: 20

cassandra_nodetool/tests/conftest.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99

1010
from datadog_checks.dev import docker_run
11+
from datadog_checks.dev.conditions import WaitFor
1112
from datadog_checks.dev.docker import get_container_ip
1213

1314
from . import common
@@ -22,6 +23,21 @@
2223
}
2324

2425

26+
def create_keyspace():
27+
subprocess.check_call(
28+
[
29+
"docker",
30+
"exec",
31+
common.CASSANDRA_CONTAINER_NAME,
32+
"cqlsh",
33+
"-e",
34+
"CREATE KEYSPACE IF NOT EXISTS test WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor':2}",
35+
"--request-timeout",
36+
"20",
37+
]
38+
)
39+
40+
2541
@pytest.fixture(scope="session")
2642
def dd_environment():
2743
"""Start the cassandra cluster with required configuration."""
@@ -32,6 +48,7 @@ def dd_environment():
3248

3349
with docker_run(
3450
compose_file,
51+
build=True,
3552
service_name=common.CASSANDRA_CONTAINER_NAME,
3653
waith_for_health=True,
3754
):
@@ -41,18 +58,6 @@ def dd_environment():
4158
compose_file,
4259
service_name=common.CASSANDRA_CONTAINER_NAME_2,
4360
waith_for_health=True,
61+
conditions=[WaitFor(create_keyspace, attempts=10, wait=10)],
4462
):
45-
subprocess.check_call(
46-
[
47-
"docker",
48-
"exec",
49-
common.CASSANDRA_CONTAINER_NAME,
50-
"cqlsh",
51-
"-e",
52-
"CREATE KEYSPACE IF NOT EXISTS test \
53-
WITH REPLICATION={'class':'SimpleStrategy', 'replication_factor':2}",
54-
"--request-timeout",
55-
"20",
56-
]
57-
)
5863
yield common.CONFIG_INSTANCE, E2E_METADATA

0 commit comments

Comments
 (0)