Skip to content

Commit

Permalink
improve notify tests for smb
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Jan 24, 2022
1 parent 4475658 commit 73e37a1
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions apps/files_external/tests/Storage/SmbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function testNotifyGetChanges() {
$this->instance->unlink('/renamed.txt');
sleep(1); //time for all changes to be processed

/** @var IChange[] $changes */
$changes = [];
$count = 0;
// wait up to 10 seconds for incoming changes
Expand All @@ -115,14 +116,23 @@ public function testNotifyGetChanges() {
}
$notifyHandler->stop();

$expected = [
new Change(IChange::ADDED, 'newfile.txt'),
new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'),
new Change(IChange::REMOVED, 'renamed.txt')
];
// depending on the server environment, the initial create might be detected as a change instead
if ($changes[0]->getType() === IChange::MODIFIED) {
$expected = [
new Change(IChange::MODIFIED, 'newfile.txt'),
new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'),
new Change(IChange::REMOVED, 'renamed.txt')
];
} else {
$expected = [
new Change(IChange::ADDED, 'newfile.txt'),
new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'),
new Change(IChange::REMOVED, 'renamed.txt')
];
}

foreach ($expected as $expectedChange) {
$this->assertContains($expectedChange, $changes, 'Actual changes are:' . PHP_EOL . print_r($expected, true), false, false); // dont check object identity
$this->assertContains($expectedChange, $changes, "Expected changes are:\n" . print_r($expected, true) . "\nGot:\n" . print_r($changes, true), false, false); // dont check object identity
}
}

Expand All @@ -135,13 +145,18 @@ public function testNotifyListen() {

$result = null;

// since the notify handler buffers untill we start listening we will get the above changes
// since the notify handler buffers until we start listening we will get the above changes
$notifyHandler->listen(function (IChange $change) use (&$result) {
$result = $change;
return false;//stop listening
});

$this->assertEquals(new Change(IChange::ADDED, 'newfile.txt'), $result);
// depending on the server environment, the initial create might be detected as a change instead
if ($result->getType() === IChange::ADDED) {
$this->assertEquals(new Change(IChange::ADDED, 'newfile.txt'), $result);
} else {
$this->assertEquals(new Change(IChange::MODIFIED, 'newfile.txt'), $result);
}
}

public function testRenameRoot() {
Expand Down

0 comments on commit 73e37a1

Please sign in to comment.