Skip to content

Commit f97a5e2

Browse files
authored
ci: Faster and smarter backup/restore tests (#3516)
From ``` ================== 11 passed, 4 warnings in 762.35s (0:12:42) ================== ``` to ``` ================== 11 passed, 4 warnings in 343.58s (0:05:43) ================== ```
1 parent b948b10 commit f97a5e2

File tree

5 files changed

+55
-61
lines changed

5 files changed

+55
-61
lines changed

Diff for: _integration-test/conftest.py

+1-42
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,17 @@
11
import os
2+
from os.path import join
23
import subprocess
3-
import time
44

5-
import httpx
65
import pytest
76

87
SENTRY_CONFIG_PY = "sentry/sentry.conf.py"
98
SENTRY_TEST_HOST = os.getenv("SENTRY_TEST_HOST", "http://localhost:9000")
109
TEST_USER = "[email protected]"
1110
TEST_PASS = "test123TEST"
12-
TIMEOUT_SECONDS = 60
13-
14-
15-
def pytest_addoption(parser):
16-
parser.addoption("--customizations", default="disabled")
1711

1812

1913
@pytest.fixture(scope="session", autouse=True)
2014
def configure_self_hosted_environment(request):
21-
subprocess.run(
22-
["docker", "compose", "--ansi", "never", "up", "-d"],
23-
check=True,
24-
capture_output=True,
25-
)
26-
for i in range(TIMEOUT_SECONDS):
27-
try:
28-
response = httpx.get(SENTRY_TEST_HOST, follow_redirects=True)
29-
except httpx.RequestError:
30-
time.sleep(1)
31-
else:
32-
if response.status_code == 200:
33-
break
34-
else:
35-
raise AssertionError("timeout waiting for self-hosted to come up")
36-
37-
if request.config.getoption("--customizations") == "enabled":
38-
os.environ["TEST_CUSTOMIZATIONS"] = "enabled"
39-
script_content = """\
40-
#!/bin/bash
41-
touch /created-by-enhance-image
42-
apt-get update
43-
apt-get install -y gcc libsasl2-dev python-dev-is-python3 libldap2-dev libssl-dev
44-
"""
45-
46-
with open("sentry/enhance-image.sh", "w") as script_file:
47-
script_file.write(script_content)
48-
# Set executable permissions for the shell script
49-
os.chmod("sentry/enhance-image.sh", 0o755)
50-
51-
# Write content to the requirements.txt file
52-
with open("sentry/requirements.txt", "w") as req_file:
53-
req_file.write("python-ldap\n")
54-
os.environ["MINIMIZE_DOWNTIME"] = "1"
55-
subprocess.run(["./install.sh"], check=True, capture_output=True)
5615
# Create test user
5716
subprocess.run(
5817
[

Diff for: _integration-test/test_backup.py

+38-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from os.path import join
23
import subprocess
34

45

@@ -20,7 +21,7 @@ def test_sentry_admin(setup_backup_restore_env_variables):
2021

2122

2223
def test_backup(setup_backup_restore_env_variables):
23-
# Docker was giving me permissioning issues when trying to create this file and write to it even after giving read + write access
24+
# Docker was giving me permission issues when trying to create this file and write to it even after giving read + write access
2425
# to group and owner. Instead, try creating the empty file and then give everyone write access to the backup file
2526
file_path = os.path.join(os.getcwd(), "sentry", "backup.json")
2627
sentry_admin_sh = os.path.join(os.getcwd(), "sentry-admin.sh")
@@ -42,21 +43,46 @@ def test_backup(setup_backup_restore_env_variables):
4243

4344
def test_import(setup_backup_restore_env_variables):
4445
# Bring postgres down and recreate the docker volume
46+
subprocess.run(["docker", "compose", "--ansi", "never", "down"], check=True)
47+
# We reset all DB-related volumes here and not just Postgres although the backups
48+
# are only for Postgres. The reason is to get a "clean slate" as we need the Kafka
49+
# and Clickhouse volumes to be back to their initial state as well ( without any events)
50+
# We cannot just rm and create them as they still need migrations.
51+
for name in ("postgres", "clickhouse", "kafka"):
52+
subprocess.run(["docker", "volume", "rm", f"sentry-{name}"], check=True)
53+
subprocess.run(
54+
[
55+
"rsync",
56+
"-aW",
57+
"--no-compress",
58+
"--mkpath",
59+
join(os.environ["RUNNER_TEMP"], "volumes", f"sentry-{name}", ""),
60+
f"/var/lib/docker/volumes/sentry-{name}/",
61+
],
62+
check=True,
63+
capture_output=True,
64+
)
65+
subprocess.run(["docker", "volume", "create", f"sentry-{name}"], check=True)
66+
4567
subprocess.run(
46-
["docker", "compose", "--ansi", "never", "stop", "postgres"], check=True
47-
)
48-
subprocess.run(
49-
["docker", "compose", "--ansi", "never", "rm", "-f", "-v", "postgres"],
50-
check=True,
51-
)
52-
subprocess.run(["docker", "volume", "rm", "sentry-postgres"], check=True)
53-
subprocess.run(["docker", "volume", "create", "--name=sentry-postgres"], check=True)
54-
subprocess.run(
55-
["docker", "compose", "--ansi", "never", "run", "web", "upgrade", "--noinput"],
68+
[
69+
"docker",
70+
"run",
71+
"--rm",
72+
"-v",
73+
"sentry-kafka:/data",
74+
"busybox",
75+
"chown",
76+
"-R",
77+
"1000:1000",
78+
"/data",
79+
],
5680
check=True,
81+
capture_output=True,
5782
)
83+
5884
subprocess.run(
59-
["docker", "compose", "--ansi", "never", "up", "-d"],
85+
["docker", "compose", "--ansi", "never", "up", "--wait"],
6086
check=True,
6187
capture_output=True,
6288
)

Diff for: _integration-test/test_run.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,15 @@ def test_custom_certificate_authorities():
326326
)
327327

328328
subprocess.run(
329-
["docker", "compose", "--ansi", "never", "up", "-d", "fixture-custom-ca-roots"],
329+
[
330+
"docker",
331+
"compose",
332+
"--ansi",
333+
"never",
334+
"up",
335+
"--wait",
336+
"fixture-custom-ca-roots",
337+
],
330338
check=True,
331339
)
332340
subprocess.run(
@@ -448,7 +456,4 @@ def test_customizations():
448456
]
449457
for command in commands:
450458
result = subprocess.run(command, check=False)
451-
if os.getenv("TEST_CUSTOMIZATIONS", "disabled") == "enabled":
452-
assert result.returncode == 0
453-
else:
454-
assert result.returncode != 0
459+
assert result.returncode == 0

Diff for: action.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ runs:
132132
"$RUNNER_TEMP/volumes/"
133133
cd ${{ github.action_path }}
134134
docker compose up --wait
135-
TEST_CUSTOMIZATIONS=enabled pytest -x --cov --junitxml=junit.xml _integration-test/
135+
pytest -x --cov --junitxml=junit.xml _integration-test/
136136
137137
- name: Upload coverage to Codecov
138138
uses: codecov/codecov-action@v5

Diff for: install/bootstrap-snuba.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
echo "${_group}Bootstrapping and migrating Snuba ..."
22

3-
$dcr snuba-api bootstrap --force
3+
if [[ -z "${SKIP_DB_MIGRATIONS:-}" ]]; then
4+
$dcr snuba-api bootstrap --force
5+
else
6+
echo "Skipped DB migrations due to SKIP_DB_MIGRATIONS=$SKIP_DB_MIGRATIONS"
7+
fi
48

59
echo "${_endgroup}"

0 commit comments

Comments
 (0)