Sharding is not just for databases - shard your tests
I always thought sharding was a database thing.
You know the trick: sqlite3 has shit concurrency, but give each customer its own sqlite database and you suddenly scale better than the big boys. Domain sharding, technical sharding, whatever you want. You get the point.
But today AI taught me something new: you can shard TESTS too. Never seen this before and it is so fucking smart.
Problem: concurrent testing falls apart when tests touch data. You get flakes, locks, random failures, especially once you want to actually run the suite later in CI.
Solution I just designed: two shards.
- Shard 1: tests that contain data. Run sequential. Safe, boring, correct.
- Shard 2: everything else. Run extremely async. Fuck it, 48 playwright browsers at once. I have 64GB anyway.
Implementation is stupid simple: just add a decorator to your tests. That is all.
@shard(async=True) or @shard(async=False)
You can do whatever you want with it. Tag by domain, by speed, by flakiness, by browser need. The runner just splits and goes.
This project has a thousand tests so it actually matters. DevPlace has 4000 tests with no sharding yet, so I filed a ticket for that too.
What a time to be alive. Copy paste brain dump to Devii, ticket gets created, knowledge gets shared, tests go brrr.
Learn something new every day.
Comments
Ah, sharding. Takes me back. I was part of the team that did this for our project at previous company. IIRC we've had too many players on one server, so they redistributed them across four servers. I was the guy who had to make sure that the user profiles before && after the maintenance window were OK. We were doing it live, so fun stuff.
A guy was sitting && waiting on results && if he heard there were problems, he was ready to revert all the changes to undo any fuckups. Good times.
I believe that. It's actually nice if shit goes down huh.
Fortunately the team was good. Never had to revert things. I'm sure the users were happy.
/* Although I assure you every time they read that their beloved game will be unavailable due to maintenance they always bitched. Spoiled retards. */
Sometimes you think "Where are the normal people" and "Wut, this does not happen in someway at your job?".
Well... never happened while I was still there. But, the team was solid. Made all the work && preparations beforehand. Even practice runs, too. All that so when the real thing takes place, there won't be any problems.