From 4bafa85678c2d2631e68a74a3c8329736d87fa9a Mon Sep 17 00:00:00 2001 From: Benaka Moorthi Date: Sat, 18 May 2013 18:00:57 -0700 Subject: Get benchmarking system to work with new test structure and make it easier to run benchmarks through VisualPHPUnit. --- tests/PHPUnit/BenchmarkTestCase.php | 8 +++---- .../Benchmarks/ArchivingProcessBenchmark.php | 3 ++- .../OneSiteTwelveThousandVisitsOneYear.php | 3 +-- .../ThousandSitesTwelveVisitsEachOneDay.php | 2 +- tests/PHPUnit/IntegrationTestCase.php | 5 +++-- tests/lib/visualphpunit/app/controller/Home.php | 26 +++++++++++++++++++--- tests/lib/visualphpunit/app/view/home/index.html | 18 ++++++++++++++- 7 files changed, 51 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/PHPUnit/BenchmarkTestCase.php b/tests/PHPUnit/BenchmarkTestCase.php index ad1dfd379e..261e6fdbab 100755 --- a/tests/PHPUnit/BenchmarkTestCase.php +++ b/tests/PHPUnit/BenchmarkTestCase.php @@ -54,7 +54,7 @@ abstract class BenchmarkTestCase extends IntegrationTestCase } $createEmptyDatabase = $fixtureName != $installedFixture; - parent::_setUpBeforeClass($dbName, $createEmptyDatabase, $createConfig = false); + parent::_setUpBeforeClass($dbName, $createEmptyDatabase, $createConfig = false, $installPlugins = true); // if we created an empty database, setup the fixture if ($createEmptyDatabase) { @@ -75,14 +75,14 @@ abstract class BenchmarkTestCase extends IntegrationTestCase */ public static function getLocalTracker($idSite) { - $t = new Piwik_LocalTracker($idSite, IntegrationTestCase::getTrackerUrl()); + $t = new Piwik_LocalTracker($idSite, Test_Piwik_BaseFixture::getTrackerUrl()); $t->setUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729)"); $t->setBrowserLanguage('fr'); $t->setLocalTime('12:34:06'); $t->setResolution(1024, 768); $t->setBrowserHasCookies(true); $t->setPlugins($flash = true, $java = true, $director = false); - $t->setTokenAuth(self::getTokenAuth()); + $t->setTokenAuth(Test_Piwik_BaseFixture::getTokenAuth()); return $t; } } @@ -99,7 +99,7 @@ class Piwik_Test_Fixture_EmptyOneSite public function setUp() { // add one site - IntegrationTestCase::createWebsite( + Test_Piwik_BaseFixture::createWebsite( $this->date, $ecommerce = 1, $siteName = "Site #0", $siteUrl = "http://whatever.com/"); // add two goals diff --git a/tests/PHPUnit/Benchmarks/ArchivingProcessBenchmark.php b/tests/PHPUnit/Benchmarks/ArchivingProcessBenchmark.php index b84afff74c..ad5d4504f8 100755 --- a/tests/PHPUnit/Benchmarks/ArchivingProcessBenchmark.php +++ b/tests/PHPUnit/Benchmarks/ArchivingProcessBenchmark.php @@ -23,6 +23,7 @@ class ArchivingProcessBenchmark extends BenchmarkTestCase */ public function testArchivingProcess() { - Piwik_VisitsSummary_API::get(self::$fixture->idSite, self::$fixture->period, self::$fixture->date); + Piwik_VisitsSummary_API::getInstance()->get( + self::$fixture->idSite, self::$fixture->period, self::$fixture->date); } } diff --git a/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php b/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php index 619b288fad..1d7917dd08 100755 --- a/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php +++ b/tests/PHPUnit/Benchmarks/Fixtures/OneSiteTwelveThousandVisitsOneYear.php @@ -20,7 +20,7 @@ class Piwik_Test_Fixture_OneSiteTwelveThousandVisitsOneYear public function setUp() { // add one site - IntegrationTestCase::createWebsite( + Test_Piwik_BaseFixture::createWebsite( $this->date, $ecommerce = 1, $siteName = "Site #0", $siteUrl = "http://whatever.com/"); // add two goals @@ -39,7 +39,6 @@ class Piwik_Test_Fixture_OneSiteTwelveThousandVisitsOneYear $date = Piwik_Date::factory($this->date); for ($month = 0; $month != 12; ++$month) { for ($day = 0; $day != 25; ++$day) { - $hour = ($time * 31) / 60.0; $visitTimes[] = $date->addPeriod($month, 'MONTH')->addDay($day)->getDatetime(); } } diff --git a/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php b/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php index f42d87b6e4..637a83bb5d 100755 --- a/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php +++ b/tests/PHPUnit/Benchmarks/Fixtures/ThousandSitesTwelveVisitsEachOneDay.php @@ -23,7 +23,7 @@ class Piwik_Test_Fixture_ThousandSitesTwelvePageViewsEachOneDay // add one thousand sites $allIdSites = array(); for ($i = 0; $i < 1000; ++$i) { - $allIdSites[] = IntegrationTestCase::createWebsite($this->date, $ecommerce = 1, $siteName = "Site #$i"); + $allIdSites[] = Test_Piwik_BaseFixture::createWebsite($this->date, $ecommerce = 1, $siteName = "Site #$i"); } // add goals to 500 sites diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php index a3716970d3..5dae1def65 100755 --- a/tests/PHPUnit/IntegrationTestCase.php +++ b/tests/PHPUnit/IntegrationTestCase.php @@ -112,7 +112,7 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase * setupBeforeClass' implementation. Can be called by derived classes in case * they need to do some custom setup procedure. */ - public static function _setUpBeforeClass($dbName = false, $createEmptyDatabase = true, $createConfig = true) + public static function _setUpBeforeClass($dbName = false, $createEmptyDatabase = true, $createConfig = true, $installPlugins = null) { try { Piwik::$piwikUrlCache = ''; @@ -160,7 +160,8 @@ abstract class IntegrationTestCase extends PHPUnit_Framework_TestCase Piwik::setUserIsSuperUser(); Piwik_Tracker_Cache::deleteTrackerCache(); - self::installAndLoadPlugins( $installPlugins = $createEmptyDatabase); + if ($installPlugins === null) $installPlugins = $createEmptyDatabase; + self::installAndLoadPlugins( $installPlugins); $_GET = $_REQUEST = array(); diff --git a/tests/lib/visualphpunit/app/controller/Home.php b/tests/lib/visualphpunit/app/controller/Home.php index c6daf3bbd7..0d7e5184b7 100755 --- a/tests/lib/visualphpunit/app/controller/Home.php +++ b/tests/lib/visualphpunit/app/controller/Home.php @@ -50,6 +50,11 @@ class Home extends \app\core\Controller { $sandbox_errors = \app\lib\Library::retrieve('sandbox_errors'); $use_xml = \app\lib\Library::retrieve('xml_configuration_file'); $xhprof_installed = \app\lib\Library::isXHProfInstalled(); + + $tests_dir = dirname(dirname(dirname(dirname(__DIR__)))); + $benchmark_fixtures_dir = $tests_dir.'/PHPUnit/Benchmarks/Fixtures'; + $benchmark_fixtures = array_map('basename', glob($benchmark_fixtures_dir.'/*.php')); + return compact( 'create_snapshots', 'sandbox_errors', @@ -58,14 +63,15 @@ class Home extends \app\core\Controller { 'suites', 'test_directory', 'use_xml', - 'xhprof_installed' + 'xhprof_installed', + 'benchmark_fixtures' ); } $data = array(); if (!empty($request->data['data_keys']) && !empty($request->data['data_values'])) { - $data = array_combine($request->data['data_keys'], $request->data['data_values']); + $data = array_combine($request->data['data_keys'], $request->data['data_values']); } $tests = explode('|', $request->data['test_files']); @@ -94,6 +100,20 @@ class Home extends \app\core\Controller { } $use_xhprof = $request->data['use_xhprof']; + + // set benchmarking globals + if (count($tests) == 1 + && basename(dirname(reset($tests))) == 'Benchmarks') { + + if (!empty($request->data['benchmark_fixture'])) { + $parts = explode('.', $request->data['benchmark_fixture']); + $data['PIWIK_BENCHMARK_FIXTURE'] = $parts[0]; + } + + if (!empty($request->data['fixture_db_name'])) { + $data['PIWIK_BENCHMARK_DATABASE'] = $request->data['fixture_db_name']; + } + } list($results, $memory_stats, $xhprof_run_id) = ( $xml_config ) ? $vpu->run_with_xml($xml_config, $use_xhprof) @@ -110,7 +130,7 @@ class Home extends \app\core\Controller { if ( $request->data['sandbox_errors'] ) { restore_error_handler(); } - + $suites = $results['suites']; $stats = $results['stats']; $errors = $vpu->get_errors(); diff --git a/tests/lib/visualphpunit/app/view/home/index.html b/tests/lib/visualphpunit/app/view/home/index.html index a4559a3426..06cfd7f9e8 100755 --- a/tests/lib/visualphpunit/app/view/home/index.html +++ b/tests/lib/visualphpunit/app/view/home/index.html @@ -21,7 +21,6 @@ -