fuel / core

Fuel PHP Framework - The core of the Fuel v1 framework
http://fuelphp.com
813 stars 345 forks source link

In rare cases Test_Cli fails #971

Closed kenjis closed 12 years ago

kenjis commented 12 years ago

Test_Cli::test_exec_speed() and test_spawn_speed() fails in rare cases.

I've got a report on Mac OS X and I have failed once on Windows.

There was 1 failure:

1) Fuel\Core\Test_Cli::test_exec_speed
Failed asserting that 1337499484 matches expected 1337499483.

C:\Users\Kenji\work\fuelphp\fuel\core\tests\cli.php:30
C:\xampp\php\phpunit:46
WanWizard commented 12 years ago

I don't think those can be tested because they return a value relative to the machine you run the tests on.

kenjis commented 12 years ago

How about this?

        $start = microtime(true);
        exec('sleep 2');
        $stop = microtime(true);
        $time = $stop - $start;
        //echo $time, PHP_EOL;

        $this->assertEquals(2, round($time));

Edited: I changed (int) to round().

jschreuder commented 12 years ago

That isn't all that usefull and seriously slows down testing. In this case all you'd test is whether the output is of the expected type (float) and larger than 0. Everything else is environmental and indeed not testable.

kenjis commented 12 years ago

Current test code is below:

        $start = time();
        exec('sleep 2');
        $stop = time();

        $this->assertEquals($start + 2, $stop);

Why does my proposal seriously slow down testing? Only I do is to loose the test condition.

In current code, If start time were 1337499484.999, and it took 2.001 sec, then the test failed.

Of course, I don't think my proposal is good test. Just reduce the probability of fails. I don't know what should this test method test.

billmn commented 12 years ago

Up ... I think that the CLI speed is not testable, depends on the machine ...

On my netbook sometimes it fail