mariano / disque-php

PHP library for Disque, an in-memory, distributed job queue
MIT License
132 stars 19 forks source link

Fix tests depending on the global system time #21

Closed Revisor closed 8 years ago

Revisor commented 8 years ago

This fixes the issue found in #20.

There are three solutions to the race condition where time can move one second during the test and thus return a different scheduling delay:

  1. Accept both (delay) and (delay - 1) as valid results
  2. Freeze the time at the moment of the test
  3. Delete the tests depending on system time

The tests are useful, so 3. is wrong. 2. would be complicated and wouldn't test the real procedure. Returning 9 or 10 for a delay of 10 is a valid result that can occur even in real world. Thus I have decided to use solution 1.

Revisor commented 8 years ago

There are no other tests using DateTime() so I think only these three tests are affected.

Today I learned something new...