Skip to content

Commit e94b262

Browse files
icewind1991backportbot[bot]
authored andcommitted
test: improve notify tests for smb
Signed-off-by: Robin Appelman <robin@icewind.nl> [skip ci]
1 parent 8700a3f commit e94b262

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

apps/files_external/tests/Storage/SmbTest.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function testNotifyGetChanges() {
105105
$this->instance->unlink('/renamed.txt');
106106
sleep(1); //time for all changes to be processed
107107

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

118-
$expected = [
119-
new Change(IChange::ADDED, 'newfile.txt'),
120-
new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'),
121-
new Change(IChange::REMOVED, 'renamed.txt')
122-
];
119+
// depending on the server environment, the initial create might be detected as a change instead
120+
if ($changes[0]->getType() === IChange::MODIFIED) {
121+
$expected = [
122+
new Change(IChange::MODIFIED, 'newfile.txt'),
123+
new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'),
124+
new Change(IChange::REMOVED, 'renamed.txt')
125+
];
126+
} else {
127+
$expected = [
128+
new Change(IChange::ADDED, 'newfile.txt'),
129+
new RenameChange(IChange::RENAMED, 'newfile.txt', 'renamed.txt'),
130+
new Change(IChange::REMOVED, 'renamed.txt')
131+
];
132+
}
123133

124134
foreach ($expected as $expectedChange) {
125-
$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));
135+
$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));
126136
}
127137
}
128138

@@ -141,7 +151,12 @@ public function testNotifyListen() {
141151
return false;//stop listening
142152
});
143153

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

147162
public function testRenameRoot() {

0 commit comments

Comments
 (0)