From 56554b56911a1aacc155e0f837ddd12671db2f84 Mon Sep 17 00:00:00 2001 From: mattab Date: Tue, 7 May 2013 17:00:00 +1200 Subject: Fixes #3927 Adding future look ahead window to the SQL trying to detect the current visitor + fixing small bug discovered (in the tests) as a result of this fix --- tests/PHPUnit/BaseFixture.php | 30 ++++++++++++++++++++++ tests/PHPUnit/Fixtures/ManySitesImportedLogs.php | 29 --------------------- tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php | 5 +++- .../Integration/ManyVisitorsOneWebsiteTest.php | 3 +-- tests/PHPUnit/IntegrationTestCase.php | 8 +++++- tests/PHPUnit/Plugins/SegmentEditorTest.php | 16 +++++++----- 6 files changed, 52 insertions(+), 39 deletions(-) (limited to 'tests') diff --git a/tests/PHPUnit/BaseFixture.php b/tests/PHPUnit/BaseFixture.php index d9fc108698..8b1253299e 100644 --- a/tests/PHPUnit/BaseFixture.php +++ b/tests/PHPUnit/BaseFixture.php @@ -325,4 +325,34 @@ abstract class Test_Piwik_BaseFixture extends PHPUnit_Framework_Assert throw new Exception("gunzip failed($return): " . implode("\n", $output)); } } + + protected static function executeLogImporter($logFile, $options) + { + $python = Piwik_Common::isWindows() ? "C:\Python27\python.exe" : 'python'; + + // create the command + $cmd = $python + . ' "' . PIWIK_INCLUDE_PATH . '/misc/log-analytics/import_logs.py" ' # script loc + . '-ddd ' // debug + . '--url="' . self::getRootUrl() . 'tests/PHPUnit/proxy/" ' # proxy so that piwik uses test config files + ; + + foreach ($options as $name => $value) { + $cmd .= $name; + if ($value !== false) { + $cmd .= '="' . $value . '"'; + } + $cmd .= ' '; + } + + $cmd .= '"' . $logFile . '" 2>&1'; + + // run the command + exec($cmd, $output, $result); + if ($result !== 0) { + throw new Exception("log importer failed: " . implode("\n", $output) . "\n\ncommand used: $cmd"); + } + + return $output; + } } diff --git a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php index 80d0036a7d..43562844f6 100644 --- a/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php +++ b/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php @@ -136,33 +136,4 @@ class Test_Piwik_Fixture_ManySitesImportedLogs extends Test_Piwik_BaseFixture self::executeLogImporter($logFile, $opts); } - private static function executeLogImporter($logFile, $options) - { - $python = Piwik_Common::isWindows() ? "C:\Python27\python.exe" : 'python'; - - // create the command - $cmd = $python - . ' "' . PIWIK_INCLUDE_PATH . '/misc/log-analytics/import_logs.py" ' # script loc - . '-ddd ' // debug - . '--url="' . self::getRootUrl() . 'tests/PHPUnit/proxy/" ' # proxy so that piwik uses test config files - ; - - foreach ($options as $name => $value) { - $cmd .= $name; - if ($value !== false) { - $cmd .= '="' . $value . '"'; - } - $cmd .= ' '; - } - - $cmd .= '"' . $logFile . '" 2>&1'; - - // run the command - exec($cmd, $output, $result); - if ($result !== 0) { - throw new Exception("log importer failed: " . implode("\n", $output) . "\n\ncommand used: $cmd"); - } - - return $output; - } } diff --git a/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php b/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php index 88cd783ae1..07d4d9dde6 100644 --- a/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php +++ b/tests/PHPUnit/Fixtures/ManyVisitsWithGeoIP.php @@ -67,6 +67,9 @@ class Test_Piwik_Fixture_ManyVisitsWithGeoIP extends Test_Piwik_BaseFixture private function trackVisits($visitorCount, $setIp = false, $useLocal = true, $doBulk = false) { + static $calledCounter = 0; + $calledCounter++; + $dateTime = $this->dateTime; $idSite = $this->idSite; @@ -77,7 +80,7 @@ class Test_Piwik_Fixture_ManyVisitsWithGeoIP extends Test_Piwik_BaseFixture $t->setTokenAuth(self::getTokenAuth()); } for ($i = 0; $i != $visitorCount; ++$i) { - $t->setVisitorId( substr(md5($i + 1000), 0, $t::LENGTH_VISITOR_ID)); + $t->setVisitorId( substr(md5($i + $calledCounter * 1000), 0, $t::LENGTH_VISITOR_ID)); if ($setIp) { $t->setIp(current($this->ips)); next($this->ips); diff --git a/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php b/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php index c8ee83e0a7..95c30bce13 100755 --- a/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php +++ b/tests/PHPUnit/Integration/ManyVisitorsOneWebsiteTest.php @@ -77,6 +77,5 @@ class Test_Piwik_Integration_ManyVisitorsOneWebsiteTest extends IntegrationTestC } } -Test_Piwik_Integration_ManyVisitorsOneWebsiteTest::$fixture - = new Test_Piwik_Fixture_ManyVisitsWithGeoIP(); +Test_Piwik_Integration_ManyVisitorsOneWebsiteTest::$fixture = new Test_Piwik_Fixture_ManyVisitsWithGeoIP(); diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php index e7958db543..e4ca79e01f 100755 --- a/tests/PHPUnit/IntegrationTestCase.php +++ b/tests/PHPUnit/IntegrationTestCase.php @@ -158,6 +158,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase // We need to be SU to create websites for tests Piwik::setUserIsSuperUser(); + Piwik_Tracker_Cache::deleteTrackerCache(); self::installAndLoadPlugins( $installPlugins = $createEmptyDatabase); @@ -681,7 +682,11 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase protected function _testApiUrl($testName, $apiId, $requestUrl) { - $isLiveMustDeleteDates = strpos($requestUrl, 'Live.getLastVisits') !== false; + $isTestLogImportReverseChronological = strpos($testName, 'ImportedInRandomOrderTest') === false; + $isLiveMustDeleteDates = strpos($requestUrl, 'Live.getLastVisits') !== false + // except for that particular test that we care about dates! + && $isTestLogImportReverseChronological; + $request = new Piwik_API_Request($requestUrl); $dateTime = Piwik_Common::getRequestVar('date', '', 'string', Piwik_Common::getArrayFromQueryString($requestUrl)); @@ -1106,4 +1111,5 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase Piwik_TablePartitioning::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload = true); } + } diff --git a/tests/PHPUnit/Plugins/SegmentEditorTest.php b/tests/PHPUnit/Plugins/SegmentEditorTest.php index 89e215ea4c..f5e83d5c42 100644 --- a/tests/PHPUnit/Plugins/SegmentEditorTest.php +++ b/tests/PHPUnit/Plugins/SegmentEditorTest.php @@ -88,16 +88,20 @@ class SegmentEditorTest extends DatabaseTestCase $this->assertEquals($segment, $expected); // There is a segment to process for this particular site - $segments = Piwik_SegmentEditor_API::getInstance()->getSegmentsToAutoArchive($idSite); + $segments = Piwik_SegmentEditor_API::getInstance()->getAll($idSite, $autoArchived = true); unset($segments[0]['ts_created']); $this->assertEquals($segments, array($expected)); - // There is no segment to process across all sites - $segments = Piwik_SegmentEditor_API::getInstance()->getSegmentsToAutoArchive(); - $this->assertEquals($segments, array()); - // There is no segment to process for a non existing site - $segments = Piwik_SegmentEditor_API::getInstance()->getSegmentsToAutoArchive(33); + try { + $segments = Piwik_SegmentEditor_API::getInstance()->getAll(33, $autoArchived = true); + $this->fail(); + } catch(Exception $e) { + // expected + } + + // There is no segment to process across all sites + $segments = Piwik_SegmentEditor_API::getInstance()->getAll($idSite = false, $autoArchived = true); $this->assertEquals($segments, array()); } -- cgit v1.2.3