Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiosmosis <diosmosis@users.noreply.github.com>2020-12-04 01:45:46 +0300
committerGitHub <noreply@github.com>2020-12-04 01:45:46 +0300
commit3908593cfee10792c5e4cc970f8227cefb23412e (patch)
treea37e924ca9bd74b7ce723488fd4cdb3305f38937 /plugins/CoreConsole
parentd81b5cf0426b029c1ac5cdbaa084d1e7f55e5d50 (diff)
segment invalidations must be paired w/ normal invalidations (#16845)
Diffstat (limited to 'plugins/CoreConsole')
-rw-r--r--plugins/CoreConsole/tests/System/ArchiveCronTest.php51
-rw-r--r--plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_day.xml18
-rw-r--r--plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_month.xml18
-rw-r--r--plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_week.xml18
-rw-r--r--plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_year.xml16
-rw-r--r--plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_singleMetric__ExamplePlugin.getExampleArchivedMetric_day.xml2
-rw-r--r--plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_singleMetric__ExamplePlugin.getExampleArchivedMetric_week.xml2
7 files changed, 123 insertions, 2 deletions
diff --git a/plugins/CoreConsole/tests/System/ArchiveCronTest.php b/plugins/CoreConsole/tests/System/ArchiveCronTest.php
index a3860198f5..35063a1951 100644
--- a/plugins/CoreConsole/tests/System/ArchiveCronTest.php
+++ b/plugins/CoreConsole/tests/System/ArchiveCronTest.php
@@ -8,6 +8,7 @@
namespace Piwik\Plugins\CoreConsole\tests\System;
use Piwik\CronArchive;
+use Piwik\Plugins\SegmentEditor\API;
use Psr\Container\ContainerInterface;
use Piwik\Archive\ArchiveInvalidator;
use Piwik\Common;
@@ -36,6 +37,9 @@ use Psr\Log\LoggerInterface;
*/
class ArchiveCronTest extends SystemTestCase
{
+ const NEW_SEGMENT = 'operatingSystemCode==IOS';
+ const NEW_SEGMENT_NAME = 'segmentForToday';
+
/**
* @var ManySitesImportedLogs
*/
@@ -48,6 +52,29 @@ class ArchiveCronTest extends SystemTestCase
Db::exec("UPDATE " . Common::prefixTable('site') . ' SET ts_created = \'2005-01-02 00:00:00\'');
}
+ private static function addNewSegmentToPast()
+ {
+ // add one segment and set it's created/updated time to some time in the past so we don't re-archive for it
+ Config::getInstance()->General['enable_browser_archiving_triggering'] = 0;
+ $idSegment = API::getInstance()->add(self::NEW_SEGMENT_NAME, self::NEW_SEGMENT, self::$fixture->idSite, $autoArchive = 1, $enabledAllUsers = 1);
+ Config::getInstance()->General['enable_browser_archiving_triggering'] = 1;
+ Db::exec("UPDATE " . Common::prefixTable('segment') . ' SET ts_created = \'2015-01-02 00:00:00\', ts_last_edit = \'2015-01-02 00:00:00\' WHERE idsegment = ' . $idSegment);
+ }
+
+ private static function trackVisitsForToday()
+ {
+ $startTime = Date::today()->addHour(12)->getDatetime();
+
+ $t = Fixture::getTracker(self::$fixture->idSite, $startTime);
+ $t->setUserAgent('Mozilla/5.0 (iPhone; CPU iPhone OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148');
+ $t->setUrl('http://awebsite.com/here/we/go');
+ Fixture::checkResponse($t->doTrackPageView('a page title'));
+
+ $t->setUrl('http://awebsite.com/another/page');
+ $t->setForceVisitDateTime(Date::factory($startTime)->addHour(1));
+ Fixture::checkResponse($t->doTrackPageView('a second page title'));
+ }
+
public function getApiForTesting()
{
$apiRequiringSegments = ['Goals.get', 'VisitFrequency.get'];
@@ -62,6 +89,12 @@ class ArchiveCronTest extends SystemTestCase
'testSuffix' => '_' . $segmentName));
}
+ $results[] = array('VisitsSummary.get', array('idSite' => 'all',
+ 'date' => 'today',
+ 'periods' => ['day', 'week', 'month', 'year'],
+ 'segment' => self::NEW_SEGMENT,
+ 'testSuffix' => '_' . self::NEW_SEGMENT_NAME));
+
// ExamplePlugin metric
$results[] = ['ExamplePlugin.getExampleArchivedMetric', [
'idSite' => 'all',
@@ -116,6 +149,12 @@ class ArchiveCronTest extends SystemTestCase
public function testArchivePhpCron()
{
+ self::$fixture->getTestEnvironment()->overrideConfig('General', 'enable_browser_archiving_triggering', 0);
+ self::$fixture->getTestEnvironment()->overrideConfig('General', 'browser_archiving_disabled_enforce', 1);
+
+ Config::getInstance()->General['enable_browser_archiving_triggering'] = 0;
+ Config::getInstance()->General['browser_archiving_disabled_enforce'] = 1;
+
// invalidate exampleplugin only archives in past
$invalidator = StaticContainer::get(ArchiveInvalidator::class);
$invalidator->markArchivesAsInvalidated(
@@ -135,6 +174,12 @@ class ArchiveCronTest extends SystemTestCase
Option::delete(CronArchive::CRON_INVALIDATION_TIME_OPTION_NAME);
$output = $this->runArchivePhpCron(); // have to run twice since we manually invalidate above
+ // add new segment w/ edited created/edit time so it will not trigger segment re-archiving, then track a visit
+ // so the segments will be archived w/ other invalidation
+ self::addNewSegmentToPast();
+ self::trackVisitsForToday();
+ $output = $this->runArchivePhpCron();
+
$expectedInvalidations = [];
$invalidationEntries = $this->getInvalidatedArchiveTableEntries();
$this->assertEquals($expectedInvalidations, $invalidationEntries);
@@ -164,6 +209,12 @@ class ArchiveCronTest extends SystemTestCase
*/
public function testArchivePhpCronWithSingleReportRearchive()
{
+ self::$fixture->getTestEnvironment()->overrideConfig('General', 'enable_browser_archiving_triggering', 0);
+ self::$fixture->getTestEnvironment()->overrideConfig('General', 'browser_archiving_disabled_enforce', 1);
+
+ Config::getInstance()->General['enable_browser_archiving_triggering'] = 0;
+ Config::getInstance()->General['browser_archiving_disabled_enforce'] = 1;
+
// invalidate a report so we get a partial archive (using the metric that gets incremented each time it is archived)
// (do it after the last run so we don't end up just re-using the ExamplePlugin archive)
$invalidator = StaticContainer::get(ArchiveInvalidator::class);
diff --git a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_day.xml b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_day.xml
new file mode 100644
index 0000000000..907663817a
--- /dev/null
+++ b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_day.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+ <result idSite="1">
+ <nb_uniq_visitors>1</nb_uniq_visitors>
+ <nb_users>0</nb_users>
+ <nb_visits>2</nb_visits>
+ <nb_actions>2</nb_actions>
+ <nb_visits_converted>2</nb_visits_converted>
+ <bounce_count>2</bounce_count>
+ <sum_visit_length>0</sum_visit_length>
+ <max_actions>1</max_actions>
+ <bounce_rate>100%</bounce_rate>
+ <nb_actions_per_visit>1</nb_actions_per_visit>
+ <avg_time_on_site>0</avg_time_on_site>
+ </result>
+ <result idSite="2" />
+ <result idSite="3" />
+</results> \ No newline at end of file
diff --git a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_month.xml b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_month.xml
new file mode 100644
index 0000000000..907663817a
--- /dev/null
+++ b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_month.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+ <result idSite="1">
+ <nb_uniq_visitors>1</nb_uniq_visitors>
+ <nb_users>0</nb_users>
+ <nb_visits>2</nb_visits>
+ <nb_actions>2</nb_actions>
+ <nb_visits_converted>2</nb_visits_converted>
+ <bounce_count>2</bounce_count>
+ <sum_visit_length>0</sum_visit_length>
+ <max_actions>1</max_actions>
+ <bounce_rate>100%</bounce_rate>
+ <nb_actions_per_visit>1</nb_actions_per_visit>
+ <avg_time_on_site>0</avg_time_on_site>
+ </result>
+ <result idSite="2" />
+ <result idSite="3" />
+</results> \ No newline at end of file
diff --git a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_week.xml b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_week.xml
new file mode 100644
index 0000000000..907663817a
--- /dev/null
+++ b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_week.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+ <result idSite="1">
+ <nb_uniq_visitors>1</nb_uniq_visitors>
+ <nb_users>0</nb_users>
+ <nb_visits>2</nb_visits>
+ <nb_actions>2</nb_actions>
+ <nb_visits_converted>2</nb_visits_converted>
+ <bounce_count>2</bounce_count>
+ <sum_visit_length>0</sum_visit_length>
+ <max_actions>1</max_actions>
+ <bounce_rate>100%</bounce_rate>
+ <nb_actions_per_visit>1</nb_actions_per_visit>
+ <avg_time_on_site>0</avg_time_on_site>
+ </result>
+ <result idSite="2" />
+ <result idSite="3" />
+</results> \ No newline at end of file
diff --git a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_year.xml b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_year.xml
new file mode 100644
index 0000000000..079f977d9b
--- /dev/null
+++ b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_segmentForToday_noOptions__VisitsSummary.get_year.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<results>
+ <result idSite="1">
+ <nb_visits>2</nb_visits>
+ <nb_actions>2</nb_actions>
+ <nb_visits_converted>2</nb_visits_converted>
+ <bounce_count>2</bounce_count>
+ <sum_visit_length>0</sum_visit_length>
+ <max_actions>1</max_actions>
+ <bounce_rate>100%</bounce_rate>
+ <nb_actions_per_visit>1</nb_actions_per_visit>
+ <avg_time_on_site>0</avg_time_on_site>
+ </result>
+ <result idSite="2" />
+ <result idSite="3" />
+</results> \ No newline at end of file
diff --git a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_singleMetric__ExamplePlugin.getExampleArchivedMetric_day.xml b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_singleMetric__ExamplePlugin.getExampleArchivedMetric_day.xml
index 8be8d54d20..77306ca768 100644
--- a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_singleMetric__ExamplePlugin.getExampleArchivedMetric_day.xml
+++ b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_singleMetric__ExamplePlugin.getExampleArchivedMetric_day.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<results>
<result idSite="1">
- <ExamplePlugin_example_metric>3382</ExamplePlugin_example_metric>
+ <ExamplePlugin_example_metric>0</ExamplePlugin_example_metric>
<ExamplePlugin_example_metric2>1</ExamplePlugin_example_metric2>
</result>
<result idSite="2" />
diff --git a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_singleMetric__ExamplePlugin.getExampleArchivedMetric_week.xml b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_singleMetric__ExamplePlugin.getExampleArchivedMetric_week.xml
index 8be8d54d20..77306ca768 100644
--- a/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_singleMetric__ExamplePlugin.getExampleArchivedMetric_week.xml
+++ b/plugins/CoreConsole/tests/System/expected/test_ArchiveCronTest_singleMetric__ExamplePlugin.getExampleArchivedMetric_week.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<results>
<result idSite="1">
- <ExamplePlugin_example_metric>3382</ExamplePlugin_example_metric>
+ <ExamplePlugin_example_metric>0</ExamplePlugin_example_metric>
<ExamplePlugin_example_metric2>1</ExamplePlugin_example_metric2>
</result>
<result idSite="2" />