Skip to content

Commit 3c972af

Browse files
committed
fix expectation + waitForTermination
1 parent d180cc0 commit 3c972af

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Dompurify/DompurifyService.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,21 @@ public function throwIfFailedOnTerm(): void
113113
throw new ProcessFailedException($this->serviceProcess);
114114
}
115115

116+
// ? interface
117+
public function waitForTermination(int $timeout): void
118+
{
119+
$elapsed = 0;
120+
$sleepInterval = 100; // Sleep for 100 milliseconds
121+
122+
while ($this->serviceProcess->isRunning() && $elapsed < $timeout) {
123+
usleep($sleepInterval * 1000);
124+
$elapsed += $sleepInterval;
125+
}
126+
127+
if ($this->serviceProcess->isRunning()) {
128+
throw new XsslessException('Process did not terminate within the given timeout');
129+
}
130+
}
131+
116132
// ========================================================================
117133
}

tests/Dompurify/DompurifyServiceTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
));
7171

7272
expect(fn () => $service->start())->toThrow(ProcessFailedException::class);
73-
expect($service->serviceProcess->getTermSignal())->toBe(127);
74-
// TODO: fix https://github.com/medilies/xssless/actions/runs/10283025153/job/28455979969
75-
// TODO: wait for signal
73+
$service->waitForTermination(2000);
74+
expect($service->serviceProcess->getExitCode())->toBe(127);
7675
});

0 commit comments

Comments
 (0)