22/28
Part 5 of 6 · The worked exampleLearn and do

Test it against a slow version that is too simple to be wrong

The fast queue has three heaps, lease numbers and stale entries. Each is a place for a bug. A good way to test it is to compare it with a brute-force version: the same rules, written as plainly as possible, with no attempt at speed.

The brute-force queue keeps one list of tasks in enqueue order, each a dict with its state, its ready_at and its dependencies. A reserve scans the list from the start and takes the first task that is waiting, has cooled down, and has every dependency done. There's no heap to get out of order and no stale entry to skip.

In the editor, write brute_reserve, the slow reserve over a plain list of task dicts in enqueue order. It takes the first task that may go now and marks it reserved.