Repository navigation
ci(tests): Run the Python tests in parallel with pytest-xdist - #8764
Conversation
|
CI timings: baseline run 46518637735 (master test code, serial) vs. this PR, run 46556781944 (
Test counts match: Notes:
|
a3796ba to
57efc90
Compare
|
Before/after CI timings
One run each. Cells are pytest seconds / job seconds.
The wall clock comes from jobs this PR doesn't change. In the after run, Test counts match. |
Give each pytest-xdist worker its own ClickHouse database and Redis, run the test, test_distributed, and clickhouse-versions snuba-test jobs with four workers, and fix the tests that depended on file order or timing. Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
ClickHouse creates system.query_log on its first log flush, a few seconds after it starts. Under xdist the admin tests can run before that, and then the queries fail with UNKNOWN_TABLE. Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
Some RPC tests occasionally get an empty result right after inserting their rows when they run under pytest-xdist. When one fails, add the worker database's recent query_log and part_log rows and its active parts to the failure report, so the next failure shows whether the rows were there at query time and which database the query read. Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
6e2db04 to
0c57b40
Compare
The first captured failure read zero rows from a part that held the inserted rows, and the query text was cut off before its WHERE clause. Show the WHERE clause, the selected marks, and query condition cache hits so the next failure shows which filter dropped the rows. Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
… topic test_executor_consumer asserts that the first message on events-subscription-results is its own result. Under xdist the two files can run at the same time on different workers, so the combined test's result could arrive first. Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
…b runs _restore_tables() queries the worker's database before _drop_tables() would create it, so a worker whose first test used this fixture failed. Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
Every shard collects sentry's whole suite to find its -m share, so most of the job's runner time is repeated collection. Co-Authored-By: Joshua Li <14209781+joshuarli@users.noreply.github.com>
Review feedback: the implicitly concatenated fragments were hard to read.
Runs snuba's Python test jobs in parallel with pytest-xdist (
-n 4 --dist loadfile) to cut CI time. It builds on #8763, which made the per-test ClickHouse fixture cheaper.Per-worker isolation
tests/xdist_isolation.py, a pytest plugin loaded fromaddopts, sets per-worker environment variables beforesnuba.settingsis imported, so settings and subprocesses pick them up:gwNgets its own database,<base>_gwN. Table names, theDistributedengine's target, and replicated tables' ZooKeeper paths all include the database name.redis_dbflushes every client and a Redis Cluster only has DB 0, so each worker gets its own three-node Valkey cluster on ports7000+10Nto7002+10N(scripts/redis-test-clusters.sh). Outside cluster mode, each worker gets its own DB.test_combined_scheduler_and_executornow publishes to its own results topic, becausetest_executor_consumerexpects the first message onevents-subscription-resultsto be its own.Migration, multi-node, and initialization runs stay serial: they leave
SNUBA_TEST_WORKERSunset, which means-n 0, and the plugin does nothing without xdist.XDIST_WORKERSinci.ymlsets the worker count to match the runners' 4 vCPUs.Order-dependent tests
Some tests relied on state that other tests left behind, which xdist exposes:
_restore_tables()puts back the tables and migration status rows thatcustom_clickhouse_dbdrops.custom_clickhouse_dbdepends oncreate_databases, because_restore_tables()queries the worker's database before anything else would create it.tests.helpers.restore_modulereplacesimportlib.reloadteardowns ofsnuba.clusters.cluster, which left stale exception classes behind.defaultdatabase, or ontime.time()in a parameter.ShardedExecutor's test waits for its thread pool.sentryjob shardsWith API changes, the
sentryjob runs 4 shards instead of 16. Every shard collects Sentry's whole suite to find its-mshare, so most of the job's runner time was repeated collection. Without API changes it stays at 2 shards.Open question
Rarely, a test under
tests/web/rpcgets no rows back right after inserting them: ClickHouse reads 0 rows from a part that holds the inserted rows, so every granule was skipped before reading. The cause isn't known yet. To help find it,tests/web/rpc/conftest.pyadds the worker database's recent ClickHousequery_log,part_log, and active parts to a failed test's report.via @joshuarli.
--
View Session [Sentry]