Galactic Games lets you challenge someone and play them live. Unit tests cover a lot of it: 8 checks for the relay, 21 for accounts, the lobby and results, and 178 for the Knife Duels game logic. None of them prove that two real people can play a match. For that I wanted a test that does exactly what two players do.
The setup
- Start the Worker locally and open two headless Edge windows, driven over the Chrome DevTools Protocol.
- Sign up two fresh accounts and put each one's login token into its own browser.
- Queue both players for a match and wait for them to meet.
- Check that both screens agree on the game state, then close the host's browser and check that the match survives.
Three things that got in the way
The browser blocked the connection. Newer builds refuse a page's WebSocket to
127.0.0.1 unless the private network checks are turned off with a launch flag. The first runs
failed before a single message was sent.
Injecting the login did not stick. Adding the token with a script that runs on every new document did not survive navigation. Setting it from a page on the same origin did.
Two browsers starve each other. With no GPU, both windows render the 3D game in software on the same machine. The game ran at about a fifth of real speed, so the other player looked seconds behind. That lag only exists in the test. Every wait had to be generous, and in headless runs the frame loop uses a plain 16 ms timer.
The lesson
An end to end test measures the test machine as well as the game. Before chasing a lag bug, check whether the lag is in the product or in the two browsers fighting over one CPU.