Skip to content

Commit c77ad08

Browse files
authored
Consolidate test setup (#242)
* Consolidate test setup The frontend and backend functional tests use completely different deployment strategies, which complicates maintenance. While the frontend's "podman compose" mechanism is appealing, it only works with docker *also* installed as `podman compose` preferentially uses the docker compose engine and the podman compose engine doesn't function correctly. Instead, consolidate on a simpified manual podman pod deployment strategy using a common helper script. I moved some files around to help make this a bit more consistent and readable: it'd be nice if GitHub were smart enough to recognize the moved files, but I'm not sure it will. * Build functional test image early We use it for the DB init stage, so my local runs used an earlier build but that doesn't work on CI.
1 parent 1cff1fc commit c77ad08

21 files changed

+391
-378
lines changed

.github/workflows/frontend-check.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
steps:
3333
- name: checkout
3434
uses: actions/checkout@v4
35-
- name: enable podman socket to facilitate podman compose
36-
run: systemctl --user enable --now podman.socket
35+
# - name: enable podman socket to facilitate podman compose
36+
# run: systemctl --user enable --now podman.socket
3737
- name: run frontend e2e tests
3838
run: ./frontend/tests/e2e.sh
3939
# TODO: add back when the e2e tests capture screenshots

backend/tests/db_seed.py

Lines changed: 0 additions & 107 deletions
This file was deleted.

backend/tests/functional.containerfile

Lines changed: 0 additions & 28 deletions
This file was deleted.

backend/tests/functional/conftest.py

Lines changed: 11 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -10,87 +10,28 @@
1010
"""
1111
import os
1212
import time
13+
import requests
1314

14-
from elasticsearch import Elasticsearch
1515
import pytest
1616

1717

1818
@pytest.fixture(scope="session")
1919
def server():
2020
server = os.getenv("SERVER")
2121
assert server, "SERVER environment variable must be set"
22-
return server
23-
24-
25-
@pytest.fixture(scope="session", autouse=True)
26-
def restore_snapshot():
27-
28-
def indices(db: Elasticsearch) -> set[str]:
29-
r = db.indices.get("*")
30-
cdm = {i for i in r.keys() if i.startswith("cdmv")}
31-
return cdm
32-
22+
start = time.time()
3323
ok = False
24+
waited = False
3425
while not ok:
35-
time.sleep(5)
3626
try:
37-
start = time.time()
38-
db = Elasticsearch("http://localhost:9200")
39-
db.cluster.health(wait_for_status="green")
40-
print(f"Opensearch claims ready after {time.time()-start:.3f} seconds")
27+
requests.get(f"{server}/api/version")
4128
ok = True
4229
except Exception as exc:
43-
print(f"Opensearch isn't ready: {type(exc).__name__} ({str(exc)!r})")
30+
if (time.time() - start) > 60.0:
31+
assert False, f"Waited over a minute for server to start: {str(exc)!r})"
32+
time.sleep(1.0)
33+
waited = True
4434
continue
45-
46-
r = db.indices.get("*")
47-
cdm = indices(db)
48-
if not cdm:
49-
try:
50-
# Opensearch hasn't been loaded yet, so restore the snapshot
51-
print("Restoring 'base' snapshot...")
52-
r = db.snapshot.create_repository(
53-
repository="functional",
54-
body={
55-
"type": "fs",
56-
"settings": {"location": "/var/tmp/snapshot"},
57-
},
58-
)
59-
assert (
60-
r.get("acknowledged") is True
61-
), f"Opensearch didn't create the repository: {r}"
62-
r = db.snapshot.get(repository="functional", snapshot="base")
63-
# We expect one snapshot, named "base"
64-
assert (
65-
r["snapshots"][0]["snapshot"] == "base"
66-
), f"Opensearch didn't find our snapshot: {r}"
67-
r = db.snapshot.restore(
68-
repository="functional",
69-
snapshot="base",
70-
request_timeout=20,
71-
body={"indices": "cdmv*dev-*"},
72-
wait_for_completion=True,
73-
master_timeout="60s",
74-
)
75-
assert (
76-
r["snapshot"]["shards"]["failed"] == 0
77-
), f"Opensearch restore failed: {r}"
78-
cdm = indices(db)
79-
except Exception as exc:
80-
print(
81-
f"Opensearch restore problem: {type(exc).__name__} ({str(exc)!r})"
82-
)
83-
raise
84-
print(f"Restored {len(cdm)} indices: {','.join(cdm)}")
85-
time.sleep(2) # Paranoia: allow stabilization
86-
87-
# CDM operations assume large "max result window" (maximum number of
88-
# returns), although this is mostly important for metric data. Oddly,
89-
# the snapshot save/restore seems to end up dropping that setting on
90-
# the one specific index where it matters. So just make sure they're
91-
# all OK.
92-
db.indices.put_settings(body={"index.max_result_window": 262144})
93-
hits = db.search(index="cdmv7dev-run")
94-
ids = [h["_source"]["run"]["id"] for h in hits["hits"]["hits"]]
95-
print(f"Found run IDs {ids} ({len(ids)})")
96-
assert len(ids) == 5, "Expected CDM run documents are missing"
35+
if waited:
36+
print(f"(waited {time.time()-start:0.3f} seconds for server)", end="")
37+
return server

backend/tests/functional/setup/funcconfig.toml

Lines changed: 0 additions & 66 deletions
This file was deleted.

backend/tests/functional/setup/opensearch.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,10 @@
11
#!/bin/bash
22
if [ ${DEBUG} ]; then set -ex ;fi
33

4-
cleanup () {
5-
set +e
6-
echo "Cleaning up..."
7-
podman pod stop "${POD_NAME}"
8-
podman rm "${POD_NAME}-func" "${POD_NAME}-front" "${POD_NAME}-back" "${POD_NAME}-opensearch"
9-
podman pod rm "${POD_NAME}"
10-
}
11-
124
BRANCH="$(git rev-parse --show-toplevel)"
13-
BACKEND="${BRANCH}/backend"
14-
FRONTEND="${BRANCH}/frontend"
15-
SETUP="${BACKEND}"/tests/functional/setup
16-
CPT_CONFIG=${CPT_CONFIG:-"${SETUP}/funcconfig.toml"}
17-
export POD_NAME=${POD_NAME:-FUNC${RANDOM}}
18-
19-
# DEVEL=1 backend/tests/functional/setup/test.sh
20-
#
21-
# In "DEVEL" mode, allow external access to the server port, and don't terminate
22-
# the pod when this script exits.
23-
if [ ${DEVEL} ]
24-
then
25-
PUBLISH="--publish 127.0.0.1:8000:8000 --publish 127.0.0.1:9200:9200"
26-
else
27-
PUBLISH=""
28-
trap cleanup EXIT
29-
fi
30-
podman pod create --name=${POD_NAME} ${PUBLISH}
5+
TESTING="${BRANCH}/testing"
316

32-
${BACKEND}/scripts/version.py
33-
podman build -f backend.containerfile --tag backend "${BACKEND}"
34-
podman build -f frontend.containerfile --tag frontend "${FRONTEND}"
35-
podman build -f tests/functional/setup/functional.containerfile --tag functional "${BACKEND}"
7+
. ${TESTING}/pod_setup.sh
8+
CONTAINERS+=( "${POD_NAME}-func" )
369

37-
POD="--pod ${POD_NAME}"
38-
39-
"${SETUP}"/opensearch.sh
40-
podman run -d ${POD} --name="${POD_NAME}-back" -v "${CPT_CONFIG}:/opt/backend/ocpperf.toml:Z" localhost/backend
41-
podman run -d ${POD} --name="${POD_NAME}-front" localhost/frontend
4210
podman run ${POD} --name="${POD_NAME}-func" localhost/functional
43-
44-
if [ ${DEVEL} ]
45-
then
46-
echo -e "\n\n--------------\nWhen finished, type\n podman pod stop ${POD_NAME}\n--------------"
47-
fi

backend/tests/functional/test_run.py renamed to backend/tests/functional/test_ilab_runs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from dataclasses import dataclass
22
from datetime import datetime, timezone
3-
import os
43

54
import pytest
65
import requests
@@ -50,7 +49,7 @@ class Run:
5049
]
5150

5251

53-
class TestRun:
52+
class TestIlabRuns:
5453

5554
def test_get_runs(self, server):
5655

0 commit comments

Comments
 (0)