tideways/php-xhprof-extension

Timer Tests (tideways_005.phpt) is flaky

Krinkle opened this issue · 1 comments

For the past few commits, this test is proving to be flaky. Failing or passing between builds for no apparent reason.

https://travis-ci.org/tideways/php-profiler-extension/builds

The failures are:

#  Job 506.6 (PHP 7.1)
002+ Failed sleep_10000_micro. Expected: 10000 microsecs. Actual: 13932 microsecs.
FAIL Tideways: Timer Tests [tests/tideways_005.phpt] 
...
Tideways: Timer Tests [tests/tideways_005.phpt]
# Job 505.1 (PHP 5.3)
002+ Failed sleep_10000_micro. Expected: 10000 microsecs. Actual: 12981 microsecs.

# Job 505.2 (PHP 5.4)
002+ Failed sleep_10000_micro. Expected: 10000 microsecs. Actual: 13162 microsecs.

# Job 505.3 (PHP 5.5)
002+ Failed sleep_10000_micro. Expected: 10000 microsecs. Actual: 12708 microsecs.

This test has always been flawky, becaus of the way it is setup. The problem is usually that usleep() isnt actually interrupted so often, which means it runs a little longer than defined, and this produces the problem. It depends on the platform how efficient this is, a better approach is to switch the usleep with a while(true) loop that exits after some time using microtime() comparisons. This uses more cpu but for a short timeframe thats ok and doesn't have the interrupt problem.