MDL-57147 phpunit: Check if time is greater than or equal to

Some windows only have 1/100 microtime resolution
so a lot of times it does not advance enough.
This commit is contained in:
Rajesh Taneja
2016-11-28 09:40:21 +08:00
parent 3eabedbb92
commit 96813571b1
+11 -5
View File
@@ -1786,6 +1786,12 @@ class core_cache_testcase extends advanced_testcase {
$this->assertArrayHasKey('cache_is_searchable', $cache->phpunit_get_store_implements());
}
/**
* Test static acceleration
*
* Note: All the assertGreaterThanOrEqual() in this test should be assertGreaterThan() be because of some microtime()
* resolution problems under some OSs / PHP versions, we are accepting equal as valid outcome. For more info see MDL-57147.
*/
public function test_static_acceleration() {
$instance = cache_config_testing::instance();
$instance->phpunit_add_definition('phpunit/accelerated', array(
@@ -1892,7 +1898,7 @@ class core_cache_testcase extends advanced_testcase {
$this->assertTrue($cache->set('b', $cacheableobject2));
$staticaccelerationreturntime = $cache->phpunit_static_acceleration_get('a')->propertytime;
$staticaccelerationreturntimeb = $cache->phpunit_static_acceleration_get('b')->propertytime;
$this->assertGreaterThan($startmicrotime, $staticaccelerationreturntime, 'Restore time of static must be newer.');
$this->assertGreaterThanOrEqual($startmicrotime, $staticaccelerationreturntime, 'Restore time of static must be newer.');
// Reset the static cache without resetting backing store.
$cache->phpunit_static_acceleration_purge();
@@ -1900,12 +1906,12 @@ class core_cache_testcase extends advanced_testcase {
// Get the value from the backend store, populating the static cache.
$cachevalue = $cache->get('a');
$this->assertInstanceOf('cache_phpunit_dummy_object', $cachevalue);
$this->assertGreaterThan($staticaccelerationreturntime, $cachevalue->propertytime);
$this->assertGreaterThanOrEqual($staticaccelerationreturntime, $cachevalue->propertytime);
$backingstorereturntime = $cachevalue->propertytime;
$results = $cache->get_many(array('b'));
$this->assertInstanceOf('cache_phpunit_dummy_object', $results['b']);
$this->assertGreaterThan($staticaccelerationreturntimeb, $results['b']->propertytime);
$this->assertGreaterThanOrEqual($staticaccelerationreturntimeb, $results['b']->propertytime);
$backingstorereturntimeb = $results['b']->propertytime;
// Obtain the value again and confirm that static cache is using wake_from_cache.
@@ -1913,11 +1919,11 @@ class core_cache_testcase extends advanced_testcase {
// value is stored serialized in the static acceleration cache.
$cachevalue = $cache->phpunit_static_acceleration_get('a');
$this->assertInstanceOf('cache_phpunit_dummy_object', $cachevalue);
$this->assertGreaterThan($backingstorereturntime, $cachevalue->propertytime);
$this->assertGreaterThanOrEqual($backingstorereturntime, $cachevalue->propertytime);
$results = $cache->get_many(array('b'));
$this->assertInstanceOf('cache_phpunit_dummy_object', $results['b']);
$this->assertGreaterThan($backingstorereturntimeb, $results['b']->propertytime);
$this->assertGreaterThanOrEqual($backingstorereturntimeb, $results['b']->propertytime);
/** @var cache_phpunit_application $cache */
$cache = cache::make('phpunit', 'accelerated2');