Skip to content

Commit 639b79e

Browse files
committed
refactor: use configurable running service for Python integration tests
Instead of configuring and starting server instances within Python as test fixtures, simply testing against a running server. A mix of make target and docker-compose changes is used to achieve the same level of test coverage that previously relied on the (re-)configure and (re-)start of the services in conftest.py. A new `make` target, 'run_local_e2e_tests', can be used to run the integration tests locally. However, the stage FxA JWT validation tests in test_e2e.py are excluded. Those tests rely on the JWK configuration of the Token Server and the stage FxA API, making them less "local". Anyone working on that specific integration can certainly invoke those tests themselves. This patch also: - deletes some duplicate docs - moves the docker-compose yamls into a dir name 'docker'
1 parent b72fa52 commit 639b79e

25 files changed

+340
-366
lines changed

Makefile

Lines changed: 95 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,61 +69,121 @@ clean:
6969
cargo clean
7070

7171
docker_start_mysql:
72-
docker compose -f docker-compose.mysql.yaml up -d
72+
docker compose -f docker/docker-compose.mysql.yaml up -d
7373

7474
docker_start_mysql_rebuild:
75-
docker compose -f docker-compose.mysql.yaml up --build -d
75+
docker compose -f docker/docker-compose.mysql.yaml up --build -d
7676

7777
docker_stop_mysql:
78-
docker compose -f docker-compose.mysql.yaml down
78+
docker compose -f docker/docker-compose.mysql.yaml down
7979

8080
docker_start_spanner:
81-
docker compose -f docker-compose.spanner.yaml up -d
81+
docker compose -f docker/docker-compose.spanner.yaml up -d
8282

8383
docker_start_spanner_rebuild:
84-
docker compose -f docker-compose.spanner.yaml up --build -d
84+
docker compose -f docker/docker-compose.spanner.yaml up --build -d
8585

8686
docker_stop_spanner:
87-
docker compose -f docker-compose.spanner.yaml down
87+
docker compose -f docker/docker-compose.spanner.yaml down
8888

8989
.ONESHELL:
9090
docker_run_mysql_e2e_tests:
91+
exit_code=0
92+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__KTY \
93+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__ALG \
94+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__KID \
95+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__FXA_CREATED_AT \
96+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__USE \
97+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__N \
98+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__E \
99+
RESULTS_FILENAME=mysql_no_jwk_integration_results.xml \
91100
docker compose \
92-
-f docker-compose.mysql.yaml \
93-
-f docker-compose.e2e.mysql.yaml \
101+
-f docker/docker-compose.mysql.yaml \
102+
-f docker/docker-compose.e2e.mysql.yaml \
103+
-f docker/docker-compose.e2e.mysql.no-jwk-cache.yaml \
94104
up \
95105
--exit-code-from mysql-e2e-tests \
96-
--abort-on-container-exit;
97-
exit_code=$$?;
98-
docker cp mysql-e2e-tests:/mysql_integration_results.xml ${MYSQL_INT_JUNIT_XML};
99-
docker cp mysql-e2e-tests:/mysql_no_jwk_integration_results.xml ${MYSQL_NO_JWK_INT_JUNIT_XML};
100-
exit $$exit_code;
106+
--abort-on-container-exit || exit_code=$$?
107+
docker cp mysql-e2e-tests:/mysql_no_jwk_integration_results.xml ${MYSQL_NO_JWK_INT_JUNIT_XML}
108+
RESULTS_FILENAME=mysql_integration_results.xml docker compose \
109+
-f docker/docker-compose.mysql.yaml \
110+
-f docker/docker-compose.e2e.mysql.yaml \
111+
-f docker/docker-compose.e2e.mysql.jwk-cache.yaml \
112+
up \
113+
--exit-code-from mysql-e2e-tests \
114+
--abort-on-container-exit || exit_code=$$?
115+
docker cp mysql-e2e-tests:/mysql_integration_results.xml ${MYSQL_INT_JUNIT_XML}
116+
docker compose \
117+
-f docker/docker-compose.mysql.yaml \
118+
-f docker/docker-compose.e2e.mysql.yaml \
119+
down -v --remove-orphans
120+
exit $$exit_code
101121

102122
.ONESHELL:
103123
docker_run_postgres_e2e_tests:
124+
exit_code=0
125+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__KTY \
126+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__ALG \
127+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__KID \
128+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__FXA_CREATED_AT \
129+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__USE \
130+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__N \
131+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__E \
132+
RESULTS_FILENAME=postgres_no_jwk_integration_results.xml \
104133
docker compose \
105-
-f docker-compose.postgres.yaml \
106-
-f docker-compose.e2e.postgres.yaml \
134+
-f docker/docker-compose.postgres.yaml \
135+
-f docker/docker-compose.e2e.postgres.yaml \
136+
-f docker/docker-compose.e2e.postgres.no-jwk-cache.yaml \
107137
up \
108138
--exit-code-from postgres-e2e-tests \
109-
--abort-on-container-exit;
110-
exit_code=$$?;
111-
docker cp postgres-e2e-tests:/postgres_integration_results.xml ${POSTGRES_INT_JUNIT_XML};
112-
docker cp postgres-e2e-tests:/postgres_no_jwk_integration_results.xml ${POSTGRES_NO_JWK_INT_JUNIT_XML};
113-
exit $$exit_code;
139+
--abort-on-container-exit || exit_code=$$?
140+
docker cp postgres-e2e-tests:/postgres_no_jwk_integration_results.xml ${POSTGRES_NO_JWK_INT_JUNIT_XML}
141+
RESULTS_FILENAME=postgres_integration_results.xml docker compose \
142+
-f docker/docker-compose.postgres.yaml \
143+
-f docker/docker-compose.e2e.postgres.yaml \
144+
-f docker/docker-compose.e2e.postgres.jwk-cache.yaml \
145+
up \
146+
--exit-code-from postgres-e2e-tests \
147+
--abort-on-container-exit || exit_code=$$?
148+
docker cp postgres-e2e-tests:/postgres_integration_results.xml ${POSTGRES_INT_JUNIT_XML}
149+
docker compose \
150+
-f docker/docker-compose.postgres.yaml \
151+
-f docker/docker-compose.e2e.postgres.yaml \
152+
down -v --remove-orphans
153+
exit $$exit_code
114154

115155
.ONESHELL:
116156
docker_run_spanner_e2e_tests:
157+
exit_code=0
158+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__KTY \
159+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__ALG \
160+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__KID \
161+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__FXA_CREATED_AT \
162+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__USE \
163+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__N \
164+
env -u SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__E \
165+
RESULTS_FILENAME=spanner_no_jwk_integration_results.xml \
117166
docker compose \
118-
-f docker-compose.spanner.yaml \
119-
-f docker-compose.e2e.spanner.yaml \
167+
-f docker/docker-compose.spanner.yaml \
168+
-f docker/docker-compose.e2e.spanner.yaml \
169+
-f docker/docker-compose.e2e.spanner.no-jwk-cache.yaml \
170+
up \
171+
--exit-code-from spanner-e2e-tests \
172+
--abort-on-container-exit || exit_code=$$?
173+
docker cp spanner-e2e-tests:/spanner_no_jwk_integration_results.xml ${SPANNER_NO_JWK_INT_JUNIT_XML}
174+
RESULTS_FILENAME=spanner_integration_results.xml docker compose \
175+
-f docker/docker-compose.spanner.yaml \
176+
-f docker/docker-compose.e2e.spanner.yaml \
177+
-f docker/docker-compose.e2e.spanner.jwk-cache.yaml \
120178
up \
121179
--exit-code-from spanner-e2e-tests \
122-
--abort-on-container-exit;
123-
exit_code=$$?;
124-
docker cp spanner-e2e-tests:/spanner_integration_results.xml ${SPANNER_INT_JUNIT_XML};
125-
docker cp spanner-e2e-tests:/spanner_no_jwk_integration_results.xml ${SPANNER_NO_JWK_INT_JUNIT_XML};
126-
exit $$exit_code;
180+
--abort-on-container-exit || exit_code=$$?
181+
docker cp spanner-e2e-tests:/spanner_integration_results.xml ${SPANNER_INT_JUNIT_XML}
182+
docker compose \
183+
-f docker/docker-compose.spanner.yaml \
184+
-f docker/docker-compose.e2e.spanner.yaml \
185+
down -v --remove-orphans
186+
exit $$exit_code
127187

128188
run_mysql: $(INSTALL_STAMP)
129189
# See https://github.com/PyO3/pyo3/issues/1741 for discussion re: why we need to set the
@@ -180,6 +240,14 @@ run_token_server_integration_tests:
180240
poetry install --no-root --without dev
181241
poetry run pytest tools/tokenserver --junit-xml=${INTEGRATION_JUNIT_XML}
182242

243+
run_local_e2e_tests:
244+
PYTHONPATH=$(PWD)/tools \
245+
SYNC_MASTER_SECRET=$${SYNC_MASTER_SECRET:-secret0} \
246+
SYNC_TOKENSERVER__FXA_OAUTH_SERVER_URL=$${SYNC_TOKENSERVER__FXA_OAUTH_SERVER_URL:-http://localhost:6000} \
247+
TOKENSERVER_HOST=$${TOKENSERVER_HOST:-http://localhost:8000} \
248+
poetry -C tools/integration_tests \
249+
run pytest . --ignore=tokenserver/test_e2e.py
250+
183251
.PHONY: install
184252
install: $(INSTALL_STAMP) ## Install dependencies with poetry
185253
$(INSTALL_STAMP): pyproject.toml poetry.lock

docker-compose.e2e.mysql.yaml

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

docker-compose.e2e.postgres.yaml

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

docker-compose.e2e.spanner.yaml

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
syncserver:
3+
environment:
4+
SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__KTY: "RSA"
5+
SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__ALG: "RS256"
6+
SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__KID: "20190730-15e473fd"
7+
SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__FXA_CREATED_AT: "1564502400"
8+
SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__USE: "sig"
9+
SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__N: "15OpVGC7ws_SlU0gRbRh1Iwo8_gR8ElX2CDnbN5blKyXLg-ll0ogktoDXc-tDvTabRTxi7AXU0wWQ247odhHT47y5uz0GASYXdfPponynQ_xR9CpNn1eEL1gvDhQN9rfPIzfncl8FUi9V4WMd5f600QC81yDw9dX-Z8gdkru0aDaoEKF9-wU2TqrCNcQdiJCX9BISotjz_9cmGwKXFEekQNJWBeRQxH2bUmgwUK0HaqwW9WbYOs-zstNXXWFsgK9fbDQqQeGehXLZM4Cy5Mgl_iuSvnT3rLzPo2BmlxMLUvRqBx3_v8BTtwmNGA0v9O0FJS_mnDq0Iue0Dz8BssQCQ"
10+
SYNC_TOKENSERVER__FXA_OAUTH_PRIMARY_JWK__E: "AQAB"
11+
SYNC_TOKENSERVER__FXA_OAUTH_SERVER_URL: http://mock-fxa-server:6000
12+
mysql-e2e-tests:
13+
entrypoint:
14+
- /bin/sh
15+
- -c
16+
- >-
17+
PYTHONPATH=/app
18+
pytest /app/tools/integration_tests/
19+
--junit-xml=/${RESULTS_FILENAME}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
services:
2+
mysql-e2e-tests:
3+
entrypoint:
4+
- /bin/sh
5+
- -c
6+
- >-
7+
PYTHONPATH=/app
8+
pytest /app/tools/integration_tests/tokenserver/test_e2e.py
9+
--junit-xml=/${RESULTS_FILENAME}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
services:
2+
syncserver:
3+
environment:
4+
SYNC_CORS_MAX_AGE: "555"
5+
SYNC_CORS_ALLOWED_ORIGIN: "*"
6+
SYNC_TOKENSERVER__ENABLED: "true"
7+
SYNC_TOKENSERVER__FXA_EMAIL_DOMAIN: api-accounts.stage.mozaws.net
8+
SYNC_TOKENSERVER__FXA_METRICS_HASH_SECRET: secret0
9+
SYNC_TOKENSERVER__RUN_MIGRATIONS: "true"
10+
mysql-e2e-tests:
11+
container_name: mysql-e2e-tests
12+
depends_on:
13+
mock-fxa-server:
14+
condition: service_started
15+
syncserver:
16+
condition: service_healthy
17+
sync-db:
18+
condition: service_healthy
19+
tokenserver-db:
20+
condition: service_healthy
21+
image: app:build
22+
privileged: true
23+
user: root
24+
environment:
25+
SYNC_SERVER_URL: http://syncserver:8000
26+
TOKENSERVER_HOST: http://syncserver:8000
27+
SYNC_HOST: 0.0.0.0
28+
SYNC_MASTER_SECRET: secret0
29+
SYNC_SYNCSTORAGE__DATABASE_URL: mysql://test:test@sync-db:3306/syncstorage
30+
SYNC_TOKENSERVER__DATABASE_URL: mysql://test:test@tokenserver-db:3306/tokenserver
31+
SYNC_TOKENSERVER__NODE_TYPE: mysql
32+
SYNC_TOKENSERVER__FXA_EMAIL_DOMAIN: api-accounts.stage.mozaws.net
33+
SYNC_TOKENSERVER__FXA_METRICS_HASH_SECRET: secret0
34+
SQLALCHEMY_SILENCE_UBER_WARNING: 1
35+
RESULTS_FILENAME: ${RESULTS_FILENAME:-mysql_integration_results.xml}
36+
entrypoint:
37+
- /bin/sh
38+
- -c
39+
- >-
40+
PYTHONPATH=/app
41+
pytest /app/tools/integration_tests/
42+
--junit-xml=/${RESULTS_FILENAME}

0 commit comments

Comments
 (0)