MDL-48595 logstore_standard: Fixing unit tests comparing performance
authorDavid Monllao <davidm@moodle.com>
Thu, 12 Mar 2015 05:52:17 +0000 (13:52 +0800)
committerDavid Monllao <davidm@moodle.com>
Thu, 12 Mar 2015 06:17:29 +0000 (14:17 +0800)
Adding also an extra userid checking as databases
may include userid = 0 records.

admin/tool/log/store/standard/tests/store_test.php
report/log/classes/table_log.php

index 0ff4f6a..730714d 100644 (file)
@@ -261,13 +261,16 @@ class logstore_standard_store_testcase extends advanced_testcase {
         // Look for non-linear memory usage for the iterator version.
         $mem = memory_get_usage();
         $events = $store->get_events_select('', array(), '', 0, 0);
-        $delta1 = memory_get_usage() - $mem;
-        $events = $store->get_events_select_iterator('', array(), '', 0, 0);
-        $delta2 = memory_get_usage() - $mem;
-        $this->assertInstanceOf('\Traversable', $events);
-        $events->close();
+        $arraymemusage = memory_get_usage() - $mem;
+
+        $mem = memory_get_usage();
+        $eventsit = $store->get_events_select_iterator('', array(), '', 0, 0);
+        $eventsit->close();
+        $itmemusage = memory_get_usage() - $mem;
+
+        $this->assertInstanceOf('\Traversable', $eventsit);
 
-        $this->assertLessThan($delta1 / 10, $delta2);
+        $this->assertLessThan($arraymemusage / 10, $itmemusage);
 
         set_config('enabled_stores', '', 'tool_log');
         get_log_manager(true);
index 25ac3df..0b17739 100644 (file)
@@ -127,6 +127,10 @@ class report_log_table_log extends table_sql {
     protected function get_user_fullname($userid) {
         global $DB;
 
+        if (empty($userid)) {
+            return false;
+        }
+
         if (!empty($this->userfullnames[$userid])) {
             return $this->userfullnames[$userid];
         }