diff options
author | Justin Velluppillai <justin@innocraft.com> | 2021-08-30 00:55:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-30 00:55:34 +0300 |
commit | 5d4925d6cde7a71ebeafeddf47357f9455dc9647 (patch) | |
tree | 5c9f7795d716dad59d6b0338d1221577887228cf /tests/PHPUnit/Integration | |
parent | c2ab6e589636fdbe0b550486b4a9ac61cbfa37bc (diff) |
If a usable archive exists and the invalidation is for a specific plugin, delete the invalidation (#17918)
* If a usable archive exists and the invalidation is for a specific plugin, delete the invalidation so it doesn't stay for ever
* Improve logging text and add a simple test
* Minor improvements from code review
Diffstat (limited to 'tests/PHPUnit/Integration')
-rw-r--r-- | tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php b/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php index 70ce73e8f8..a2e6a488a2 100644 --- a/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php +++ b/tests/PHPUnit/Integration/CronArchive/QueueConsumerTest.php @@ -504,6 +504,82 @@ class QueueConsumerTest extends IntegrationTestCase $this->assertEquals(0, $count); } + + + public function test_pluginInvalidationDeletedIfUsableArchiveExists() + { + Fixture::createWebsite('2015-02-03'); + + // force archiving so we don't skip those without visits + Piwik::addAction('Archiving.getIdSitesToArchiveWhenNoVisits', function (&$idSites) { + $idSites[] = 1; + }); + + $cronArchive = new MockCronArchive(); + $cronArchive->init(); + + $archiveFilter = $this->makeTestArchiveFilter(); + + $queueConsumer = new QueueConsumer( + StaticContainer::get(LoggerInterface::class), + new FixedSiteIds([1]), + 3, + 24, + new Model(), + new SegmentArchiving('beginning_of_time'), + $cronArchive, + new RequestParser(true), + $archiveFilter + ); + + Date::$now = strtotime('2018-03-04 01:00:00'); + + $invalidations = [ + ['idarchive' => 1, 'name' => "done.Actions", 'idsite' => 1, 'date1' => '2018-03-04', 'date2' => '2018-03-04', 'period' => 1, 'report' => null], + ['idarchive' => 1, 'name' => 'done', 'idsite' => 1, 'date1' => '2018-03-04', 'date2' => '2018-03-04', 'period' => 3, 'report' => null], + ]; + + shuffle($invalidations); + + $this->insertInvalidations($invalidations); + + $usableArchive = ['idarchive' => 1, 'name' => 'done', 'idsite' => 1, 'date1' => '2018-03-04', 'date2' => '2018-03-04', 'period' => 1, 'ts_archived' => Date::now()->getDatetime(), 'value' => 3.0]; + $this->insertArchive($usableArchive); + + $iteratedInvalidations = []; + while (true) { + $next = $queueConsumer->getNextArchivesToProcess(); + if ($next === null) { + break; + } + + foreach ($next as &$item) { + $this->simulateJobStart($item['idinvalidation']); + + unset($item['periodObj']); + unset($item['idinvalidation']); + unset($item['ts_invalidated']); + } + + $iteratedInvalidations[] = $next; + } + + $expectedInvalidationsFound = [ + array( + ['idarchive' => '1', 'idsite' => '1', 'date1' => '2018-03-04', 'date2' => '2018-03-04', 'period' => '3', 'name' => 'done', 'report' => null, 'plugin' => null, 'segment' => '', 'ts_started' => null, 'status' => '0'] + ), + array() + ]; + + $this->assertEquals($expectedInvalidationsFound, $iteratedInvalidations, "Invalidations inserted:\n" . var_export($invalidations, true)); + + // check that our plugin invalidation is no longer in the invalidations table + $count = Db::fetchOne('SELECT COUNT(*) FROM ' . Common::prefixTable('archive_invalidations') . ' WHERE name = ?', [ + "done.Actions", + ]); + $this->assertEquals(0, $count); + } + public function test_skipSegmentsToday() { Date::$now = strtotime('2018-03-04 01:00:00'); @@ -680,6 +756,25 @@ class QueueConsumerTest extends IntegrationTestCase } } + private function insertArchive(array $archive) + { + $table = ArchiveTableCreator::getNumericTable(Date::now()); + + $bind = [ + $archive['idarchive'], + $archive['name'], + $archive['idsite'], + $archive['date1'], + $archive['date2'], + $archive['period'], + $archive['ts_archived'], + $archive['value'] + ]; + + Db::query("INSERT INTO `$table` (idarchive, name, idsite, date1, date2, period, ts_archived, value) + VALUES (?, ?, ?, ?, ?, ?, ?, ?)", $bind); + } + public function test_canSkipArchiveBecauseNoPoint_returnsTrueIfDateRangeHasNoVisits() { Fixture::createWebsite('2010-04-06'); |