Skip to content

Commit

Permalink
test: improve notify tests for smb
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Mar 8, 2024
1 parent ea8a774 commit d1c6e82
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 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->assertTrue(in_array($expectedChange, $changes), 'Actual changes are:' . PHP_EOL . print_r($changes, true) . PHP_EOL . 'Expected to find: ' . PHP_EOL . print_r($expectedChange, true));
$this->assertTrue(in_array($expectedChange, $changes), "Expected changes are:\n" . print_r($expected, true) . PHP_EOL . 'Expected to find: ' . PHP_EOL . print_r($expectedChange, true) . "\nGot:\n" . print_r($changes, true));
}
}

Expand All @@ -141,7 +151,12 @@ public function testNotifyListen() {
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 d1c6e82

Please sign in to comment.