Skip to content

Commit 15840c5

Browse files
authoredMar 18, 2025
chore: migrate tokenserver tests to pytest with junit output
* add pytest and script to make for running tests with pytest * add conftest for pytest path handling * move store test results to capture integration results * remove unneeded run_tests and fix warnings about assert_() Closes SYNC-4612
1 parent 324a6d8 commit 15840c5

File tree

6 files changed

+32
-48
lines changed

6 files changed

+32
-48
lines changed
 

‎.circleci/config.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,24 @@ commands:
116116
name: Merge llvm-cov results
117117
command: make merge_coverage_results
118118

119-
store-unit-test-results:
119+
store-test-results:
120120
steps:
121121
- store_test_results:
122122
path: workflow/test-results
123123
- store_artifacts:
124124
path: workflow/test-results
125125

126+
run-tokenserver-integration-tests:
127+
steps:
128+
- run:
129+
when: always
130+
name: Tokenserver integration tests
131+
command: |
132+
# NOTE: Python3.12 requires `--break-system-packages`.
133+
# This command is run on the circleci/rust image, which is running python 3.10
134+
make run_token_server_integration_tests
135+
environment:
136+
SYNCSTORAGE_RS_IMAGE: app:build
126137
run-e2e-mysql-tests:
127138
steps:
128139
- run:
@@ -137,17 +148,6 @@ commands:
137148
environment:
138149
SYNCSTORAGE_RS_IMAGE: app:build
139150

140-
run-tokenserver-scripts-tests:
141-
steps:
142-
- run:
143-
name: Tokenserver scripts tests
144-
command: |
145-
# NOTE: Python3.12 requires `--break-system-packages`.
146-
# This command is run on the circleci/rust image, which is running python 3.10
147-
pip3 install -r tools/tokenserver/requirements.txt
148-
python3 tools/tokenserver/run_tests.py
149-
environment:
150-
SYNCSTORAGE_RS_IMAGE: app:build
151151

152152
run-e2e-spanner-tests:
153153
steps:
@@ -240,11 +240,11 @@ jobs:
240240
- make-test-dir
241241
- run-unit-tests
242242
- merge-unit-test-coverage
243-
- store-unit-test-results
244243
# if the above tests don't run tokenserver-db tests (i.e. using --workspace)
245244
# then run-tokenserver-scripts-tests will fail. These tests expect the db to be
246245
# configured already, and it appears unit-tests modify the db to the expected state
247-
- run-tokenserver-scripts-tests
246+
- run-tokenserver-integration-tests
247+
- store-test-results
248248
#- save-sccache-cache
249249
build-mysql-image:
250250
docker:

‎Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ PATH_TO_GRPC_CERT = ../server-syncstorage/local/lib/python2.7/site-packages/grpc
1616
WORKFLOW := build-deploy
1717
EPOCH_TIME := $(shell date +"%s")
1818
TEST_RESULTS_DIR ?= workflow/test-results
19-
2019
TEST_PROFILE := $(if $(CIRCLECI),ci,default)
2120
TEST_FILE_PREFIX := $(if $(CIRCLECI),$(CIRCLE_BUILD_NUM)__$(EPOCH_TIME)__$(CIRCLE_PROJECT_REPONAME)__$(WORKFLOW)__)
2221
UNIT_JUNIT_XML := $(TEST_RESULTS_DIR)/$(TEST_FILE_PREFIX)unit__results.xml
2322
UNIT_COVERAGE_JSON := $(TEST_RESULTS_DIR)/$(TEST_FILE_PREFIX)unit__coverage.json
23+
INTEGRATION_JUNIT_XML := $(TEST_RESULTS_DIR)/$(TEST_FILE_PREFIX)integration__results.xml
2424
SYNC_SYNCSTORAGE__DATABASE_URL ?= mysql://sample_user:sample_password@localhost/syncstorage_rs
2525
SYNC_TOKENSERVER__DATABASE_URL ?= mysql://sample_user:sample_password@localhost/tokenserver_rs
2626

@@ -61,7 +61,6 @@ python:
6161
python3 -m venv venv
6262
venv/bin/python -m pip install -r requirements.txt
6363

64-
6564
run_mysql: python
6665
PATH="./venv/bin:$(PATH)" \
6766
# See https://github.com/PyO3/pyo3/issues/1741 for discussion re: why we need to set the
@@ -100,4 +99,9 @@ test_with_coverage:
10099
exit $$exit_code
101100

102101
merge_coverage_results:
103-
cargo llvm-cov report --summary-only --json --output-path ${UNIT_COVERAGE_JSON}
102+
cargo llvm-cov report --summary-only --json --output-path ${UNIT_COVERAGE_JSON}
103+
104+
.ONESHELL:
105+
run_token_server_integration_tests:
106+
pip3 install -r tools/tokenserver/requirements.txt
107+
pytest tools/tokenserver --junit-xml=${INTEGRATION_JUNIT_XML}

‎tools/tokenserver/conftest.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import sys
2+
import os
3+
4+
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))

‎tools/tokenserver/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ sqlalchemy==1.4.46
66
testfixtures
77
tokenlib==2.0.0
88
PyBrowserID==0.14.0
9+
pytest==8.3.5
910
datadog
1011
backoff
1112

‎tools/tokenserver/run_tests.py

-25
This file was deleted.

‎tools/tokenserver/test_database.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -467,23 +467,23 @@ def test_first_seen_at(self):
467467
def test_build_old_range(self):
468468
params = dict()
469469
sql = self.database._build_old_user_query(None, params)
470-
self.assert_(sql.text.find("uid > :start") < 0)
471-
self.assert_(sql.text.find("uid < :end") < 0)
470+
self.assertTrue(sql.text.find("uid > :start") < 0)
471+
self.assertTrue(sql.text.find("uid < :end") < 0)
472472
self.assertIsNone(params.get("start"))
473473
self.assertIsNone(params.get("end"))
474474

475475
params = dict()
476476
rrange = (None, "abcd")
477477
sql = self.database._build_old_user_query(rrange, params)
478-
self.assert_(sql.text.find("uid > :start") < 0)
479-
self.assert_(sql.text.find("uid < :end") > 0)
478+
self.assertTrue(sql.text.find("uid > :start") < 0)
479+
self.assertTrue(sql.text.find("uid < :end") > 0)
480480
self.assertIsNone(params.get("start"))
481481
self.assertEqual(params.get("end"), rrange[1])
482482

483483
params = dict()
484484
rrange = ("1234", "abcd")
485485
sql = self.database._build_old_user_query(rrange, params)
486-
self.assert_(sql.text.find("uid > :start") > 0)
487-
self.assert_(sql.text.find("uid < :end") > 0)
486+
self.assertTrue(sql.text.find("uid > :start") > 0)
487+
self.assertTrue(sql.text.find("uid < :end") > 0)
488488
self.assertEqual(params.get("start"), rrange[0])
489489
self.assertEqual(params.get("end"), rrange[1])

0 commit comments

Comments
 (0)
Failed to load comments.