(Speaker: Glyph)
Because: distributed systems are hard, and they're now ubiquitous.
Signs you're building a distributed system:
- if
import requestsis in your code
For example:
In-game purchases with real money.
Uses threads to speed up payment process. Easy, right? But if one thread blocks other stuff: players can steal!
Okay, so: use a state machine to keep track of whether ppl owe money, or are in good standing. But alas: there's still a race condition that players can exploit for gamebux.
Okay, so: use thread locks!
But: how to test this?
-
Use a fake lock
- But: running code logic in sequence is never the same as running in parallel
-
Use end-to-end tests
- Good for discovering bugs, but not for reliably reproducing bugs
-
Simulate the passage of time
- Give race conditions a time window to show up.
- "verified fake"
twistedmodule- Lets you manually control the system clock advances.
- something about a
SynchronousTestCasemethod intwisted - "These results are 100% real"
(Aside: he's talking about 'concurrency' and 'futures' and 'defereds' and it's going over my head.)
- Simulate traffic on the network
- also using some
twistedmodule:treq.testing - Simulate web servers and clients, but with enough determinism in the behavior to be useful as a test.
- Can unit test server results, regardless of the order in which those events fire/return.
- also using some
(Aside: apparently await is something you can use, kind of like while. Not sure if this is twisted-specific.)