From: Robin Appelman Date: Fri, 6 Jan 2017 15:11:18 +0000 (+0100) Subject: add notify self test X-Git-Tag: v12.0.0beta1~607^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=72eeb8fd2267f1a4d319372c455e3fbd0539976f;p=nextcloud-server.git add notify self test Signed-off-by: Robin Appelman --- diff --git a/apps/files_external/lib/Command/Notify.php b/apps/files_external/lib/Command/Notify.php index b317f5c0594..a55b16a45c4 100644 --- a/apps/files_external/lib/Command/Notify.php +++ b/apps/files_external/lib/Command/Notify.php @@ -28,8 +28,10 @@ use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Service\GlobalStoragesService; use OCP\Files\Notify\IChange; +use OCP\Files\Notify\INotifyHandler; use OCP\Files\Notify\IRenameChange; use OCP\Files\Storage\INotifyStorage; +use OCP\Files\Storage\IStorage; use OCP\Files\StorageNotAvailableException; use OCP\IDBConnection; use Symfony\Component\Console\Input\InputArgument; @@ -125,7 +127,9 @@ class Notify extends Base { $verbose = $input->getOption('verbose'); $path = trim($input->getOption('path'), '/'); - $storage->notify($path)->listen(function (IChange $change) use ($mount, $verbose, $output) { + $notifyHandler = $storage->notify($path); + $this->selfTest($storage, $notifyHandler, $verbose, $output); + $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) { if ($verbose) { $this->logUpdate($change, $output); } @@ -174,4 +178,35 @@ class Notify extends Base { $output->writeln($text); } + + private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) { + usleep(100 * 1000); //give time for the notify to start + $storage->file_put_contents('/.nc_test_file.txt', 'test content'); + $storage->mkdir('/.nc_test_folder'); + $storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content'); + $storage->unlink('/.nc_test_file.txt'); + $storage->unlink('/.nc_test_folder/subfile.txt'); + $storage->rmdir('/.nc_test_folder'); + usleep(100 * 1000); //time for all changes to be processed + + $foundRootChange = false; + $foundSubfolderChange = false; + + $changes = $notifyHandler->getChanges(); + foreach ($changes as $change) { + if ($change->getPath() === '/.nc_test_file.txt') { + $foundRootChange = true; + } else if ($change->getPath() === '/.nc_test_folder/subfile.txt') { + $foundSubfolderChange = true; + } + } + + if ($foundRootChange && $foundSubfolderChange && $verbose) { + $output->writeln('Self-test successful'); + } else if ($foundRootChange && !$foundSubfolderChange) { + $output->writeln('Error while running self-test, change is subfolder not detected'); + } else if (!$foundRootChange) { + $output->writeln('Error while running self-test, no changes detected'); + } + } }