Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve notify tests for smb #30796

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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($changes, 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
Loading