Skip to content

Commit

Permalink
fix expectation + waitForTermination
Browse files Browse the repository at this point in the history
  • Loading branch information
medilies committed Aug 7, 2024
1 parent d180cc0 commit c873424
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.3, 8.2]
stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
name: P${{ matrix.php }} - ${{ matrix.os }}

steps:
- name: Checkout code
Expand All @@ -41,7 +40,7 @@ jobs:
- name: Install dependencies
run: |
composer i --no-interaction
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
composer update --prefer-dist --no-interaction
- name: List Installed Dependencies
run: composer show -D
Expand Down
16 changes: 16 additions & 0 deletions src/Dompurify/DompurifyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,21 @@ public function throwIfFailedOnTerm(): void
throw new ProcessFailedException($this->serviceProcess);
}

// ? interface
public function waitForTermination(int $timeout): void
{
$elapsed = 0;
$sleepInterval = 100; // Sleep for 100 milliseconds

while ($this->serviceProcess->isRunning() && $elapsed < $timeout) {
usleep($sleepInterval * 1000);
$elapsed += $sleepInterval;
}

if ($this->serviceProcess->isRunning()) {
throw new XsslessException('Process did not terminate within the given timeout');
}
}

// ========================================================================
}
5 changes: 2 additions & 3 deletions tests/Dompurify/DompurifyServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
));

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

0 comments on commit c873424

Please sign in to comment.