Skip to content

Commit

Permalink
fixup! fix(imap): persist vanished messages immediately on EXAMINE co…
Browse files Browse the repository at this point in the history
…mmands
  • Loading branch information
st3iny committed Aug 27, 2024
1 parent 4108736 commit 47ca8ba
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 16 deletions.
42 changes: 42 additions & 0 deletions tests/Integration/Framework/Caching.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Mail\Tests\Integration\Framework;

use OC\Memcache\Factory;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\Profiler\IProfiler;
use OCP\Server;
use Psr\Log\LoggerInterface;

class Caching {
/**
* Force usage of a real cache as configured in system config. The original ICacheFactory
* service closure is hard-coded to always return an instance of ArrayCache when the global
* PHPUNIT_RUN is defined.
*/
public static function registerConfiguredCache(): void {
\OC::$server->registerService(
ICacheFactory::class,
function () {
$config = Server::get(IConfig::class);
return new Factory(
'mail-integration-tests',
Server::get(LoggerInterface::class),
Server::get(IProfiler::class),
$config->getSystemValue('memcache.local', null),
$config->getSystemValue('memcache.distributed', null),
$config->getSystemValue('memcache.locking', null),
$config->getSystemValueString('redis_log_file')
);
},
);
}
}
55 changes: 39 additions & 16 deletions tests/Integration/MailboxSynchronizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@

use Horde_Imap_Client;
use Horde_Imap_Client_Socket;
use OC\Memcache\ArrayCache;
use OC\Memcache\Factory;
use OC\Memcache\Redis;
use OCA\Mail\Account;
use OCA\Mail\Contracts\IMailManager;
use OCA\Mail\Controller\MailboxesController;
use OCA\Mail\Db\MessageMapper;
use OCA\Mail\Service\AccountService;
use OCA\Mail\Service\Sync\SyncService;
use OCA\Mail\Tests\Integration\Framework\Caching;
use OCA\Mail\Tests\Integration\Framework\ImapTest;
use OCA\Mail\Tests\Integration\Framework\ImapTestAccount;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IRequest;
use OCP\Profiler\IProfiler;
use OCP\Server;
Expand All @@ -43,27 +45,27 @@ class MailboxSynchronizationTest extends TestCase {
protected function setUp(): void {
parent::setUp();

// Simulate proper distributed cache via shared array cache instance
/*
// Force usage of a real cache. The original service closure is hard-coded to always return
// an instance of ArrayCache when the global PHPUNIT_RUN is defined.
\OC::$server->registerService(
ICacheFactory::class,
function () {
$cacheFactory = $this->getMockBuilder(Factory::class)
->setConstructorArgs([
'globalPrefix',
Server::get(LoggerInterface::class),
Server::get(IProfiler::class),
ArrayCache::class,
ArrayCache::class,
ArrayCache::class,
])
->setMethods(['createDistributed'])
->getMock();
$cacheFactory->method('createDistributed')
->willReturn(new ArrayCache());
return $cacheFactory;
$config = Server::get(IConfig::class);
return new Factory(
'mail-integration-tests',
Server::get(LoggerInterface::class),
Server::get(IProfiler::class),
$config->getSystemValue('memcache.local', null),
$config->getSystemValue('memcache.distributed', null),
$config->getSystemValue('memcache.locking', null),
$config->getSystemValueString('redis_log_file')
);
},
true,
);
*/
Caching::registerConfiguredCache();

$this->foldersController = new MailboxesController(
'mail',
Expand Down Expand Up @@ -250,6 +252,18 @@ public function testSyncVanishedMessage() {
}

public function testUnsolicitedVanishedMessage() {
$config = Server::get(IConfig::class);
$cacheClass = $config->getSystemValueString('memcache.distributed');
if (ltrim($cacheClass, '\\') !== Redis::class) {
$this->markTestSkipped('Redis not available. Found ' . $cacheClass);
}

// Just to be sure ...
$cache = Server::get(ICacheFactory::class)->createDistributed();
$this->assertInstanceOf(Redis::class, $cache);

$cache->clear();

$mailbox = 'INBOX';
$message = $this->getMessageBuilder()
->from('ralph@[email protected]')
Expand Down Expand Up @@ -284,6 +298,15 @@ public function testUnsolicitedVanishedMessage() {
[]
);

$syncService->syncMailbox(
new Account($this->account),
$inbox,
Horde_Imap_Client::SYNC_NEWMSGSUIDS | Horde_Imap_Client::SYNC_FLAGSUIDS | Horde_Imap_Client::SYNC_VANISHEDUIDS,
true,
null,
null,
);

// Assert that there are 2 messages and nothing changes when deleting a message externally
$messageMapper = Server::get(MessageMapper::class);
self::assertCount(2, $messageMapper->findAllUids($inbox));
Expand Down

0 comments on commit 47ca8ba

Please sign in to comment.