diff options
author | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-07-06 03:15:23 +0400 |
---|---|---|
committer | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-07-06 03:15:23 +0400 |
commit | 3a3517e48823a4d7dc521e5a754c51ddbcf5d210 (patch) | |
tree | e7e137700c1764047ce140fb2a48657255191427 /tests | |
parent | 056909103fe9896432b2d1109b9fee04569b5a0a (diff) |
Refs #3124, add benchmark for MultiSites.getAll and benchmark fixture that adds 20,000 sites to the DB then tracks one pageview per site.
Diffstat (limited to 'tests')
3 files changed, 83 insertions, 1 deletions
diff --git a/tests/PHPUnit/Benchmarks/ArchiveQueryBenchmark.php b/tests/PHPUnit/Benchmarks/ArchiveQueryBenchmark.php index 414d04d977..e6305563cf 100644 --- a/tests/PHPUnit/Benchmarks/ArchiveQueryBenchmark.php +++ b/tests/PHPUnit/Benchmarks/ArchiveQueryBenchmark.php @@ -31,7 +31,7 @@ class ArchiveQueryBenchmark extends BenchmarkTestCase public function testArchivingProcess() { if ($this->archivingLaunched) { - echo "NOTE: Had to archive tables, memory results will not be accurate. Run again for better results."; + echo "NOTE: Had to archive data, memory results will not be accurate. Run again for better results."; } Piwik_ArchiveProcessor_Rules::$archivingDisabledByTests = true; diff --git a/tests/PHPUnit/Benchmarks/Fixtures/ManyThousandSitesOneVisitEach.php b/tests/PHPUnit/Benchmarks/Fixtures/ManyThousandSitesOneVisitEach.php new file mode 100644 index 0000000000..b58cde84a2 --- /dev/null +++ b/tests/PHPUnit/Benchmarks/Fixtures/ManyThousandSitesOneVisitEach.php @@ -0,0 +1,42 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +/** + * Reusable fixture. Adds 20,000 sites and tracks one pageview for each on one day. + */ +class Piwik_Test_Fixture_ManyThousandSitesOneVisitEach +{ + public $date = '2010-01-01'; + public $period = 'day'; + public $siteCount = 20000; + public $idSite = 'all'; + + public function setUp() + { + for ($i = 0; $i != $this->siteCount; ++$i) { + $idSite = Test_Piwik_BaseFixture::createWebsite( + $this->date, $ecommerce = 1, $siteName = "Site #$i", $siteUrl = "http://site$i.com/"); + + Piwik_Goals_API::getInstance()->addGoal($idSite, 'all', 'url', 'http', 'contains', false, 5); + } + + // track one visit for each site + $t = BenchmarkTestCase::getLocalTracker(1); + $t->setForceVisitDateTime(Piwik_Date::factory($this->date)->addHour(6)); + for ($idSite = 1; $idSite < $this->siteCount + 1; ++$idSite) { + $ip = "157.5.6.4"; + $t->setIp($ip); + $t->setNewVisitorId(); + + $t->setIdSite($idSite); + + $t->setUrl("http://site" . ($idSite - 1) . ".com/page.html"); + $t->doTrackPageView('page title'); + } + } +} diff --git a/tests/PHPUnit/Benchmarks/MultiSitesBenchmark.php b/tests/PHPUnit/Benchmarks/MultiSitesBenchmark.php new file mode 100644 index 0000000000..8ae47a4c1a --- /dev/null +++ b/tests/PHPUnit/Benchmarks/MultiSitesBenchmark.php @@ -0,0 +1,40 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/BenchmarkTestCase.php'; + +/** + * Tests MultiSites API. Should be used with ManyThousandSitesOneVisitEach benchmark fixture. + */ +class MultiSitesBenchmark extends BenchmarkTestCase +{ + private $archivingLaunched = false; + + public function setUp() + { + $archivingTables = Piwik_DataAccess_ArchiveTableCreator::getTablesArchivesInstalled(); + if (empty($archivingTables)) { + $this->archivingLaunched = true; + Piwik_VisitsSummary_API::getInstance()->get( + self::$fixture->idSite, self::$fixture->period, self::$fixture->date); + } + } + + /** + * @group Benchmarks + * @group ArchivingProcess + */ + public function testArchivingProcess() + { + if ($this->archivingLaunched) { + echo "NOTE: Had to archive data, memory results will not be accurate. Run again for better results."; + } + + Piwik_ArchiveProcessor_Rules::$archivingDisabledByTests = true; + Piwik_MultiSites_API::getInstance()->getAll(self::$fixture->period, self::$fixture->date); + } +} |