Skip to content
Extraits de code Groupes Projets
Valider ce2dfe18 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Adding tests for related log importer PR here: https://github.com/piwik/piwik-log-analytics/pull/94

parent 48ababe8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -192,7 +192,7 @@ class ManySitesImportedLogs extends Fixture ...@@ -192,7 +192,7 @@ class ManySitesImportedLogs extends Fixture
* Logs a couple visits for the site we created and two new sites that do not * Logs a couple visits for the site we created and two new sites that do not
* exist yet. Visits are from Aug 12, 13 & 14 of 2012. * exist yet. Visits are from Aug 12, 13 & 14 of 2012.
*/ */
public function logVisitsWithDynamicResolver() public function logVisitsWithDynamicResolver($maxPayloadSize = 1)
{ {
$logFile = PIWIK_INCLUDE_PATH . '/tests/resources/access-logs/fake_logs_dynamic.log'; # log file $logFile = PIWIK_INCLUDE_PATH . '/tests/resources/access-logs/fake_logs_dynamic.log'; # log file
...@@ -201,8 +201,8 @@ class ManySitesImportedLogs extends Fixture ...@@ -201,8 +201,8 @@ class ManySitesImportedLogs extends Fixture
$opts = array('--add-sites-new-hosts' => false, $opts = array('--add-sites-new-hosts' => false,
'--enable-testmode' => false, '--enable-testmode' => false,
'--recorders' => '1', '--recorders' => '1',
'--recorder-max-payload-size' => '1'); '--recorder-max-payload-size' => $maxPayloadSize);
self::executeLogImporter($logFile, $opts); return implode("\n", self::executeLogImporter($logFile, $opts));
} }
/** /**
......
...@@ -8,11 +8,14 @@ ...@@ -8,11 +8,14 @@
namespace Piwik\Tests\System; namespace Piwik\Tests\System;
use Piwik\Access; use Piwik\Access;
use Piwik\Common;
use Piwik\Plugins\SitesManager\API; use Piwik\Plugins\SitesManager\API;
use Piwik\Tests\Framework\Fixture; use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\SystemTestCase; use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Tests\Fixtures\ManySitesImportedLogs; use Piwik\Tests\Fixtures\ManySitesImportedLogs;
use Piwik\Tests\Framework\TestingEnvironmentVariables; use Piwik\Tests\Framework\TestingEnvironmentVariables;
use Piwik\Tracker\Request;
use Piwik\Tracker\RequestSet;
/** /**
* Tests the log importer. * Tests the log importer.
...@@ -103,10 +106,15 @@ class ImportLogsTest extends SystemTestCase ...@@ -103,10 +106,15 @@ class ImportLogsTest extends SystemTestCase
/** /**
* NOTE: This test must be last since the new sites that get added are added in * NOTE: This test must be last since the new sites that get added are added in
* random order. * random order.
* NOTE: This test combines two tests in order to avoid executing the log importer another time.
* If the log importer were refactored, the invalid requests test could be a unit test in
* python.
*/ */
public function testDynamicResolverSitesCreated() public function test_LogImporter_CreatesSitesWhenDynamicResolverUsed_AndReportsOnInvalidRequests()
{ {
self::$fixture->logVisitsWithDynamicResolver(); $this->simulateInvalidTrackerRequest();
$output = self::$fixture->logVisitsWithDynamicResolver($maxPayloadSize = 3);
// reload access so new sites are viewable // reload access so new sites are viewable
Access::getInstance()->setSuperUserAccess(true); Access::getInstance()->setSuperUserAccess(true);
...@@ -120,6 +128,10 @@ class ImportLogsTest extends SystemTestCase ...@@ -120,6 +128,10 @@ class ImportLogsTest extends SystemTestCase
$whateverDotCom = API::getInstance()->getSitesIdFromSiteUrl('http://whatever.com'); $whateverDotCom = API::getInstance()->getSitesIdFromSiteUrl('http://whatever.com');
$this->assertEquals(1, count($whateverDotCom)); $this->assertEquals(1, count($whateverDotCom));
// make sure invalid requests are reported correctly
$this->assertContains('The Piwik tracker identified 2 invalid requests on lines: 10, 11', $output);
$this->assertContains("The following lines were not tracked by Piwik, either due to a malformed tracker request or error in the tracker:\n\n10, 11", $output);
} }
public function test_LogImporter_RetriesWhenServerFails() public function test_LogImporter_RetriesWhenServerFails()
...@@ -163,23 +175,53 @@ class ImportLogsTest extends SystemTestCase ...@@ -163,23 +175,53 @@ class ImportLogsTest extends SystemTestCase
{ {
$testingEnvironment = new TestingEnvironmentVariables(); $testingEnvironment = new TestingEnvironmentVariables();
$testingEnvironment->_triggerTrackerFailure = null; $testingEnvironment->_triggerTrackerFailure = null;
$testingEnvironment->_triggerInvalidRequests = null;
$testingEnvironment->save(); $testingEnvironment->save();
} }
private function simulateInvalidTrackerRequest()
{
$testEnvironment = new TestingEnvironmentVariables();
$testEnvironment->_triggerInvalidRequests = true;
$testEnvironment->save();
}
public static function provideContainerConfigBeforeClass() public static function provideContainerConfigBeforeClass()
{ {
$result = array(); $result = array();
$observers = array();
$testingEnvironment = new TestingEnvironmentVariables(); $testingEnvironment = new TestingEnvironmentVariables();
if ($testingEnvironment->_triggerTrackerFailure) { if ($testingEnvironment->_triggerTrackerFailure) {
$result['observers.global'] = \DI\add(array( $observers[] = array('Tracker.newHandler', function () {
array('Tracker.newHandler', function () { @http_response_code(500);
@http_response_code(500);
throw new \Exception("injected exception"); throw new \Exception("injected exception");
}) });
));
} }
if ($testingEnvironment->_triggerInvalidRequests) {
// we trigger an invalid request by checking for triggerInvalid=1 in a request, and if found replacing the
// request w/ a request that has an nonexistent idsite
$observers[] = array('Tracker.initRequestSet', function (RequestSet $requestSet) {
$requests = $requestSet->getRequests();
foreach ($requests as $index => $request) {
$url = $request->getParam('url');
if (strpos($url, 'triggerInvalid=1') !== false) {
$newParams = $request->getParams();
$newParams['idsite'] = 1000;
$requests[$index] = new Request($newParams);
}
}
$requestSet->setRequests($requests);
});
}
if (!empty($observers)) {
$result['observers.global'] = \DI\add($observers);
}
return $result; return $result;
} }
} }
......
...@@ -8,8 +8,8 @@ whatever.com 72.44.32.10 - - [12/Aug/2012:15:49:48 +0200] "GET /translations/ HT ...@@ -8,8 +8,8 @@ whatever.com 72.44.32.10 - - [12/Aug/2012:15:49:48 +0200] "GET /translations/ HT
piwik.net 175.41.192.09 - - [12/Aug/2012:22:56:45 +0200] "GET /docs/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0" piwik.net 175.41.192.09 - - [12/Aug/2012:22:56:45 +0200] "GET /docs/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (X11; Linux i686; rv:6.0) Gecko/20100101 Firefox/6.0"
piwik.net 175.41.192.09 - - [12/Aug/2012:23:00:42 +0200] "GET /docs/manage-users/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3" piwik.net 175.41.192.09 - - [12/Aug/2012:23:00:42 +0200] "GET /docs/manage-users/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3"
whatever.com 79.125.00.21 - - [13/Aug/2012:20:03:40 +0200] "GET /newsletter/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)" whatever.com 79.125.00.21 - - [13/Aug/2012:20:03:40 +0200] "GET /newsletter/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)"
whatever.com 175.41.192.34 - - [13/Aug/2012:21:59:50 +0200] "GET /faq/how-to/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)" whatever.com 175.41.192.34 - - [13/Aug/2012:21:59:50 +0200] "GET /faq/how-to/?triggerInvalid=1 HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)"
anothersite.com 175.41.192.34 - - [13/Aug/2012:22:01:17 +0200] "GET /faq/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (X11; U; Linux x86_64; fr-FR) AppleWebKit/534.7 (KHTML, like Gecko) Epiphany/2.30.6 Safari/534.7" anothersite.com 175.41.192.34 - - [13/Aug/2012:22:01:17 +0200] "GET /faq/?triggerInvalid=1 HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (X11; U; Linux x86_64; fr-FR) AppleWebKit/534.7 (KHTML, like Gecko) Epiphany/2.30.6 Safari/534.7"
anothersite.com 177.71.128.21 - - [13/Aug/2012:22:21:03 +0200] "GET /docs/manage-websites/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0" anothersite.com 177.71.128.21 - - [13/Aug/2012:22:21:03 +0200] "GET /docs/manage-websites/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0"
anothersite.com 177.71.128.21 - - [13/Aug/2012:22:21:28 +0200] "GET /intranet-analytics/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (X11; U; Linux x86_64; fr-FR) AppleWebKit/534.7 (KHTML, like Gecko) Epiphany/2.30.6 Safari/534.7" anothersite.com 177.71.128.21 - - [13/Aug/2012:22:21:28 +0200] "GET /intranet-analytics/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (X11; U; Linux x86_64; fr-FR) AppleWebKit/534.7 (KHTML, like Gecko) Epiphany/2.30.6 Safari/534.7"
whatever.com 177.71.128.21 - - [13/Aug/2012:22:22:08 +0200] "GET /blog/2012/08/survey-your-opinion-matters/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6" whatever.com 177.71.128.21 - - [13/Aug/2012:22:22:08 +0200] "GET /blog/2012/08/survey-your-opinion-matters/ HTTP/1.1" 200 3574 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1092.0 Safari/536.6"
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter