15 Isolating timelines
In this chapter
- Learn how to draw timeline diagrams from code.
- Understand how to read timeline diagrams to find bugs.
- Discover how to improve code design by reducing resources shared between timelines.
In this chapter, we will start using timeline diagrams to represent sequences of actions over time. They help us understand how our software runs. They are particularly useful in a distributed system, like when a web client talks to a web server. Timeline diagrams help us diagnose and predict bugs. We can then develop a solution.
There’s a bug!
MegaMart support is getting a lot of phone calls about the shopping cart showing the wrong total. The customers add stuff to their cart, it tells them it will cost $X, but when they check out, they are charged $Y. That’s no good, and the customers are not happy. Let’s see if we can debug this for them.
We can’t reproduce it when we click through slowly
The slow clickthrough seems to work. But clicking things quickly will result in a different outcome. Let’s check it out.
Now we can try to click twice fast
Customers told us the bug happened when they clicked quickly
We can reproduce the bug by clicking on the buy button twice very quickly. Let’s see that:
We tested it a few more times and got a variety of results
We ran the same scenario (add shoes twice fast) several times. We got these answers:
- $14**
- $16
- $22 ** the correct answer