Skip to content

Commit 90270ea

Browse files
authored
Disable Signal Handling During Test Execution to Prevent SIGINT Interference (#569)
* add failing test * feat: add signal interceptor configuration to polling metadata * enable feature * restore signal handlers on consumer shutdown * fix amqp * clean
1 parent 98b12b6 commit 90270ea

11 files changed

+119
-171
lines changed

packages/Ecotone/src/Messaging/Endpoint/ConsumerInterceptor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ interface ConsumerInterceptor
2121
*/
2222
public function onStartup(): void;
2323

24+
/**
25+
* Do some one time action when the consumer is shutting down
26+
*/
27+
public function onShutdown(): void;
28+
2429
/**
2530
* should this consumer be stopped before next run
2631
*/
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ecotone\Messaging\Endpoint;
6+
7+
use Throwable;
8+
9+
/**
10+
* licence Apache-2.0
11+
*/
12+
trait ConsumerInterceptorTrait
13+
{
14+
public function onStartup(): void {}
15+
16+
public function onShutdown(): void {}
17+
18+
public function shouldBeStopped(): bool {
19+
return false;
20+
}
21+
22+
public function shouldBeThrown(Throwable $exception): bool
23+
{
24+
return false;
25+
}
26+
27+
public function preRun(): void {
28+
29+
}
30+
31+
/**
32+
* Called after each run
33+
*/
34+
public function postRun(?Throwable $unhandledFailure): void
35+
{}
36+
37+
/**
38+
* Called after each sending message to request channel
39+
*/
40+
public function postSend(): void
41+
{}
42+
}

packages/Ecotone/src/Messaging/Endpoint/Interceptor/ConnectionExceptionRetryInterceptor.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Ecotone\Messaging\Endpoint\Interceptor;
66

77
use Ecotone\Messaging\Endpoint\ConsumerInterceptor;
8+
use Ecotone\Messaging\Endpoint\ConsumerInterceptorTrait;
89
use Ecotone\Messaging\Endpoint\PollingConsumer\ConnectionException;
910
use Ecotone\Messaging\Handler\Recoverability\RetryTemplateBuilder;
1011
use Ecotone\Messaging\Scheduling\Duration;
@@ -17,6 +18,7 @@
1718
*/
1819
class ConnectionExceptionRetryInterceptor implements ConsumerInterceptor
1920
{
21+
use ConsumerInterceptorTrait;
2022
private int $currentNumberOfRetries = 0;
2123
private ?\Ecotone\Messaging\Handler\Recoverability\RetryTemplate $retryTemplate;
2224

@@ -33,14 +35,6 @@ public function onStartup(): void
3335
$this->currentNumberOfRetries = 0;
3436
}
3537

36-
/**
37-
* @inheritDoc
38-
*/
39-
public function shouldBeStopped(): bool
40-
{
41-
return false;
42-
}
43-
4438
/**
4539
* @inheritDoc
4640
*/
@@ -87,11 +81,4 @@ public function postRun(?Throwable $unhandledFailure): void
8781

8882
$this->currentNumberOfRetries = 0;
8983
}
90-
91-
/**
92-
* @inheritDoc
93-
*/
94-
public function postSend(): void
95-
{
96-
}
9784
}

packages/Ecotone/src/Messaging/Endpoint/Interceptor/FinishWhenNoMessagesInterceptor.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Ecotone\Messaging\Endpoint\Interceptor;
66

77
use Ecotone\Messaging\Endpoint\ConsumerInterceptor;
8+
use Ecotone\Messaging\Endpoint\ConsumerInterceptorTrait;
89
use Ecotone\Messaging\Scheduling\DatePoint;
910
use Ecotone\Messaging\Scheduling\Duration;
1011
use Ecotone\Messaging\Scheduling\EcotoneClockInterface;
@@ -15,6 +16,7 @@
1516
*/
1617
class FinishWhenNoMessagesInterceptor implements ConsumerInterceptor
1718
{
19+
use ConsumerInterceptorTrait;
1820
private bool $shouldBeStopped = false;
1921
private ?DatePoint $lastTimeMessageWasReceived;
2022

@@ -38,14 +40,6 @@ public function preRun(): void
3840
$this->shouldBeStopped = true;
3941
}
4042

41-
/**
42-
* @inheritDoc
43-
*/
44-
public function shouldBeThrown(Throwable $exception): bool
45-
{
46-
return false;
47-
}
48-
4943
/**
5044
* @inheritDoc
5145
*/
@@ -62,13 +56,6 @@ public function shouldBeStopped(): bool
6256
return $this->shouldBeStopped;
6357
}
6458

65-
/**
66-
* @inheritDoc
67-
*/
68-
public function postRun(?Throwable $unhandledFailure): void
69-
{
70-
}
71-
7259
/**
7360
* @inheritDoc
7461
*/

packages/Ecotone/src/Messaging/Endpoint/Interceptor/LimitConsumedMessagesInterceptor.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Ecotone\Messaging\Endpoint\Interceptor;
66

77
use Ecotone\Messaging\Endpoint\ConsumerInterceptor;
8+
use Ecotone\Messaging\Endpoint\ConsumerInterceptorTrait;
89
use Throwable;
910

1011
/**
@@ -17,6 +18,7 @@
1718
*/
1819
class LimitConsumedMessagesInterceptor implements ConsumerInterceptor
1920
{
21+
use ConsumerInterceptorTrait;
2022
private bool $shouldBeStopped = false;
2123

2224
private int $currentConsumedMessages = 0;
@@ -41,21 +43,6 @@ public function onStartup(): void
4143
$this->shouldBeStopped = false;
4244
}
4345

44-
/**
45-
* @inheritDoc
46-
*/
47-
public function preRun(): void
48-
{
49-
}
50-
51-
/**
52-
* @inheritDoc
53-
*/
54-
public function shouldBeThrown(Throwable $exception): bool
55-
{
56-
return false;
57-
}
58-
5946
/**
6047
* @inheritDoc
6148
*/

packages/Ecotone/src/Messaging/Endpoint/Interceptor/LimitExecutionAmountInterceptor.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Ecotone\Messaging\Endpoint\Interceptor;
66

77
use Ecotone\Messaging\Endpoint\ConsumerInterceptor;
8+
use Ecotone\Messaging\Endpoint\ConsumerInterceptorTrait;
89
use Throwable;
910

1011
/**
@@ -17,6 +18,8 @@
1718
*/
1819
class LimitExecutionAmountInterceptor implements ConsumerInterceptor
1920
{
21+
use ConsumerInterceptorTrait;
22+
2023
private bool $shouldBeStopped = false;
2124

2225
private int $currentExecutionAmount = 0;
@@ -41,21 +44,6 @@ public function onStartup(): void
4144
$this->shouldBeStopped = false;
4245
}
4346

44-
/**
45-
* @inheritDoc
46-
*/
47-
public function preRun(): void
48-
{
49-
}
50-
51-
/**
52-
* @inheritDoc
53-
*/
54-
public function shouldBeThrown(Throwable $exception): bool
55-
{
56-
return false;
57-
}
58-
5947
/**
6048
* @inheritDoc
6149
*/
@@ -72,11 +60,4 @@ public function postRun(?Throwable $unhandledFailure): void
7260
$this->currentExecutionAmount++;
7361
$this->shouldBeStopped = $this->currentExecutionAmount >= $this->executionLimit;
7462
}
75-
76-
/**
77-
* @inheritDoc
78-
*/
79-
public function postSend(): void
80-
{
81-
}
8263
}

packages/Ecotone/src/Messaging/Endpoint/Interceptor/LimitMemoryUsageInterceptor.php

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Ecotone\Messaging\Config\ConfigurationException;
88
use Ecotone\Messaging\Endpoint\ConsumerInterceptor;
9+
use Ecotone\Messaging\Endpoint\ConsumerInterceptorTrait;
910
use Throwable;
1011

1112
/**
@@ -18,6 +19,7 @@
1819
*/
1920
class LimitMemoryUsageInterceptor implements ConsumerInterceptor
2021
{
22+
use ConsumerInterceptorTrait;
2123
private int $memoryLimitInMegaBytes;
2224

2325
/**
@@ -34,13 +36,6 @@ public function __construct(int $memoryLimitInMegaBytes)
3436
$this->memoryLimitInMegaBytes = $memoryLimitInMegaBytes * 1024 * 1024;
3537
}
3638

37-
/**
38-
* @inheritDoc
39-
*/
40-
public function onStartup(): void
41-
{
42-
}
43-
4439
/**
4540
* @inheritDoc
4641
*/
@@ -52,33 +47,4 @@ public function shouldBeStopped(): bool
5247

5348
return memory_get_usage(true) >= $this->memoryLimitInMegaBytes;
5449
}
55-
56-
/**
57-
* @inheritDoc
58-
*/
59-
public function shouldBeThrown(Throwable $exception): bool
60-
{
61-
return false;
62-
}
63-
64-
/**
65-
* @inheritDoc
66-
*/
67-
public function preRun(): void
68-
{
69-
}
70-
71-
/**
72-
* @inheritDoc
73-
*/
74-
public function postRun(?Throwable $unhandledFailure): void
75-
{
76-
}
77-
78-
/**
79-
* @inheritDoc
80-
*/
81-
public function postSend(): void
82-
{
83-
}
8450
}

0 commit comments

Comments
 (0)