From: Andrew Nicols Date: Wed, 2 Aug 2017 06:23:57 +0000 (+0800) Subject: MDL-59642 stats: Correct random unit test failure X-Git-Tag: v3.4.0-beta~482^2 X-Git-Url: http://git.moodle.org/gw?p=moodle.git;a=commitdiff_plain;h=d504e9207c4e3f41344b56017233880051fd0de5;ds=sidebyside MDL-59642 stats: Correct random unit test failure The unit test was creating four events, and then relying on them being retrieved in the order in which they were created. I've modified the test to: * ensure timecreated are spaced apart; and * add an order by timecreated when fetching them. --- diff --git a/lib/tests/statslib_test.php b/lib/tests/statslib_test.php index 66089a40644..31b99d10a47 100644 --- a/lib/tests/statslib_test.php +++ b/lib/tests/statslib_test.php @@ -337,15 +337,29 @@ class core_statslib_testcase extends advanced_testcase { $this->assertEquals($firstoldtime, stats_get_start_from('daily')); + $time = time() - 5; \core_tests\event\create_executed::create(array('context' => context_system::instance()))->trigger(); + $DB->set_field('logstore_standard_log', 'timecreated', $time++, [ + 'eventname' => '\\core_tests\\event\\create_executed', + ]); + \core_tests\event\read_executed::create(array('context' => context_system::instance()))->trigger(); + $DB->set_field('logstore_standard_log', 'timecreated', $time++, [ + 'eventname' => '\\core_tests\\event\\read_executed', + ]); + \core_tests\event\update_executed::create(array('context' => context_system::instance()))->trigger(); + $DB->set_field('logstore_standard_log', 'timecreated', $time++, [ + 'eventname' => '\\core_tests\\event\\update_executed', + ]); + \core_tests\event\delete_executed::create(array('context' => context_system::instance()))->trigger(); + $DB->set_field('logstore_standard_log', 'timecreated', $time++, [ + 'eventname' => '\\core_tests\\event\\delete_executed', + ]); - // Fake the origin of events. $DB->set_field('logstore_standard_log', 'origin', 'web', array()); - - $logs = $DB->get_records('logstore_standard_log'); + $logs = $DB->get_records('logstore_standard_log', null, 'timecreated ASC'); $this->assertCount(4, $logs); $firstnew = reset($logs);