Skip to content

Commit

Permalink
Add support for sigquit (#9)
Browse files Browse the repository at this point in the history
* add support for sigquit
* Update CHANGELOG.md

Co-authored-by: Alessandro Lai <[email protected]>

---------

Co-authored-by: Gabriele 'gabricom' Colombera <[email protected]>
Co-authored-by: Alessandro Lai <[email protected]>
  • Loading branch information
3 people authored Aug 23, 2023
1 parent f0de1d9 commit 0095f18
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## Unreleased
* ...

## 1.2.1 [2023-08-23]
* Adds support for SIGQUIT signal (needed to support php-fpm-alpine docker images which overrides STOPSIGNAL ([Official Dockerfile](https://github.com/docker-library/php/blob/master/8.2/alpine3.18/fpm/Dockerfile#L259)))

## 1.2.0 [2023-04-03]
* Drop support to PHP 7.3
* Drop support to EOL Symfony versions (3.x, 4.0 to 4.3, 5.0 to 5.3)
Expand Down
3 changes: 2 additions & 1 deletion bin/terminable-loop-command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ _term() {
wait $CHILD
}

trap _term TERM
trap _term TERM SIGTERM
trap _term QUIT SIGQUIT

while true; do
$@ &
Expand Down
31 changes: 24 additions & 7 deletions tests/E2E/TerminateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ public function commandLineProvider(): array
];
}

public function testSigTermDuringCommandBody(): void
/**
* @dataProvider provideSignals
*/
public function testSignalsDuringCommandBody(int $signal, int $exitCode): void
{
$process = new Process([
self::BASH_COMMAND,
Expand All @@ -73,18 +76,21 @@ public function testSigTermDuringCommandBody(): void
$process->start();

sleep(1);
$process->signal(SIGTERM);
$process->signal($signal);

$process->wait();

$this->assertCommandIsFound($process);
$this->assertStringContainsString('Starting ' . self::STUB_COMMAND, $process->getOutput());
$this->assertStringNotContainsString('Signal received, skipping execution', $process->getOutput());
$this->assertStringContainsString('Slept 0 second(s)', $process->getOutput());
$this->assertSame(143, $process->getExitCode());
$this->assertSame($exitCode, $process->getExitCode());
}

public function testSigTermDuringSleep(): void
/**
* @dataProvider provideSignals
*/
public function testSigTermDuringSleep(int $signal, int $exitCode): void
{
$process = new Process([
self::BASH_COMMAND,
Expand All @@ -99,15 +105,26 @@ public function testSigTermDuringSleep(): void
$process->start();

sleep(1);
$process->signal(SIGTERM);
$process->signal($signal);

$process->wait();

$this->assertCommandIsFound($process);
$this->assertStringContainsString('Starting ' . self::STUB_COMMAND, $process->getOutput());
$this->assertStringNotContainsString('Signal received, skipping execution', $process->getOutput());
$this->assertMatchesRegularExpression('/Slept (0|1) second\(s\)/', $process->getOutput());
$this->assertSame(143, $process->getExitCode());
$this->assertRegExp('/Slept (0|1) second\(s\)/', $process->getOutput());
$this->assertSame($exitCode, $process->getExitCode());
}

/**
* @return array<array{int,int}>
*/
public function provideSignals(): array
{
return [
[SIGTERM, 143],
[SIGQUIT, 131],
];
}

/**
Expand Down

0 comments on commit 0095f18

Please sign in to comment.