Skip to content

Commit 19f4aeb

Browse files
committed
fix: Fix file listener tests
Signed-off-by: Marcel Klehr <[email protected]>
1 parent a8fb342 commit 19f4aeb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/ClassifierTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use OCA\Recognize\BackgroundJobs\ClassifyMovinetJob;
77
use OCA\Recognize\BackgroundJobs\ClassifyMusicnnJob;
88
use OCA\Recognize\BackgroundJobs\ClusterFacesJob;
9+
use OCA\Recognize\BackgroundJobs\ProcessFsActionsJob;
910
use OCA\Recognize\BackgroundJobs\SchedulerJob;
1011
use OCA\Recognize\BackgroundJobs\StorageCrawlJob;
1112
use OCA\Recognize\Classifiers\Audio\MusicnnClassifier;
@@ -153,37 +154,51 @@ public function testFileListener(string $ignoreFileName) : void {
153154
$storageId = $this->testFile->getMountPoint()->getNumericStorageId();
154155
$rootId = $this->testFile->getMountPoint()->getStorageRootId();
155156

157+
$this->runFsActionJobs();
156158
self::assertCount(1, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'one element should have been added to imagenet queue');
157159

158160
$this->testFile->delete();
159161

162+
$this->runFsActionJobs();
160163
self::assertCount(0, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'entry should have been removed from imagenet queue');
161164

162165
$ignoreFile->delete();
163166

167+
$this->runFsActionJobs();
164168
self::assertCount(1, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'one element should have been added to imagenet queue after deleting ignore file');
165169

166170
$ignoreFile = $this->userFolder->newFile('/test/' . $ignoreFileName, '');
167171

172+
$this->runFsActionJobs();
168173
self::assertCount(0, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'entry should have been removed from imagenet queue after creating ignore file');
169174

170175
$this->ignoredFile->move($this->userFolder->getPath() . '/alpine-2.jpg');
171176

177+
$this->runFsActionJobs();
172178
self::assertCount(1, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'one element should have been added to imagenet queue after moving it out of ignored territory');
173179

174180
$ignoreFile->move($this->userFolder->getPath() . '/' . $ignoreFileName);
175181

182+
$this->runFsActionJobs();
176183
self::assertCount(0, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'entry should have been removed from imagenet queue after moving ignore file');
177184

178185
$ignoreFile->move($this->userFolder->getPath() . '/test/' . $ignoreFileName);
179186

187+
$this->runFsActionJobs();
180188
self::assertCount(1, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'one element should have been added to imagenet queue after moving ignore file');
181189

182190
$this->ignoredFile->move($this->userFolder->getPath() . '/test/ignore/alpine-2.jpg');
183191

192+
$this->runFsActionJobs();
184193
self::assertCount(0, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'entry should have been removed from imagenet queue after moving it into ignored territory');
185194
}
186195

196+
private function runFsActionJobs() {
197+
while ($job = $this->jobList->getNext(jobClasses:[ProcessFsActionsJob::class])) {
198+
$job->start($this->jobList);
199+
}
200+
}
201+
187202
/**
188203
* @dataProvider ignoreImageFilesProvider
189204
* @return void
@@ -206,34 +221,42 @@ public function testFileListenerWithFolder(string $ignoreFileName) : void {
206221
$storageId = $this->testFile->getMountPoint()->getNumericStorageId();
207222
$rootId = $this->testFile->getMountPoint()->getStorageRootId();
208223

224+
$this->runFsActionJobs();
209225
self::assertCount(1, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'one element should have been added to imagenet queue');
210226

211227
$folder->delete();
212228

229+
$this->runFsActionJobs();
213230
self::assertCount(0, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'entry should have been removed from imagenet queue');
214231

215232
$ignoreFile->delete();
216233

234+
$this->runFsActionJobs();
217235
self::assertCount(1, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'one element should have been added to imagenet queue after deleting ignore file');
218236

219237
$ignoreFile = $this->userFolder->newFile('/test/' . $ignoreFileName, '');
220238

239+
$this->runFsActionJobs();
221240
self::assertCount(0, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'entry should have been removed from imagenet queue after creating ignore file');
222241

223242
$ignoredFolder->move($this->userFolder->getPath() . '/folder2');
224243

244+
$this->runFsActionJobs();
225245
self::assertCount(1, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'one element should have been added to imagenet queue after moving it out of ignored territory');
226246

227247
$ignoreFile->move($this->userFolder->getPath() . '/' . $ignoreFileName);
228248

249+
$this->runFsActionJobs();
229250
self::assertCount(0, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'entry should have been removed from imagenet queue after moving ignore file');
230251

231252
$ignoreFile->move($this->userFolder->getPath() . '/test/' . $ignoreFileName);
232253

254+
$this->runFsActionJobs();
233255
self::assertCount(1, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'one element should have been added to imagenet queue after moving ignore file');
234256

235257
$ignoredFolder->move($this->userFolder->getPath() . '/test/ignore/folder');
236258

259+
$this->runFsActionJobs();
237260
self::assertCount(0, $this->queue->getFromQueue(ImagenetClassifier::MODEL_NAME, $storageId, $rootId, 100), 'entry should have been removed from imagenet queue after moving it into ignored territory');
238261
}
239262

0 commit comments

Comments
 (0)