endlessm / azafea

Service to track device activations and usage metrics
Mozilla Public License 2.0
10 stars 2 forks source link

Improve tests speed #141

Closed liZe closed 3 years ago

liZe commented 3 years ago

This pull request includes two commits.

  1. Use a very short timeout if we want to exit when the Redis queue is empty.
  2. Use simple code to check that no table is in database (only used for tests).
liZe commented 3 years ago

Tests were passing on my computer, but not on GitHub Actions. Why? The idea of using a short timeout was nice, but it didn’t work. Why? No error in the logs but no line added in the database, a stupid problem impossible to debug. Why?

Because we use Redis 5, and floats for timeouts are only accepted since … Redis 6.

So, after the third way, here is the fourth way: keep brpop for endless loops, and use rpop when we want to exit early. This solution is a bit more complicated, but the code is easy to understand, and it’s actually The Good Way™ to avoid a mandatory timeout.

Both cases are actually used in tests: we generally use early exits when we want to test the Redis queue, but we also test signals to stop Azafea running forever. We keep our 100% coverage 🎉.

Bonus: floats are now allowed for timeouts in Redis typing, if we ever want to use them: python/typeshed#4952.

Tests on my computer:

And tests are 2 times faster on GitHub actions.