Skip to content

Commit 4e71e79

Browse files
committed
RunnableQueue - fixed bug
1 parent 51e6cc4 commit 4e71e79

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/Process/Runnable/RunnableQueue.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,13 @@ public function cancelAll(): void
129129
$deferred->promise()->cancel(); // @phpstan-ignore-line
130130
}
131131

132+
$runningDeferreds = [];
132133
foreach ($this->running as $running) { // phpcs:ignore
133-
[, $deferred] = $this->running->getInfo();
134+
[,$deferred] = $this->running->getInfo();
135+
$runningDeferreds[] = $deferred;
136+
}
137+
138+
foreach ($runningDeferreds as $deferred) {
134139
$deferred->promise()->cancel(); // @phpstan-ignore-line
135140
}
136141
}

tests/PHPStan/Process/Runnable/RunnableQueueTest.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ public function testCancel(): void
125125
public function testCancelAll(): void
126126
{
127127
$logger = new RunnableQueueLoggerStub();
128-
$queue = new RunnableQueue($logger, 4);
128+
$queue = new RunnableQueue($logger, 6);
129129
$one = new RunnableStub('1');
130130
$two = new RunnableStub('2');
131131
$three = new RunnableStub('3');
132132
$queue->queue($one, 3);
133133
$queue->queue($two, 2);
134134
$queue->queue($three, 3);
135135

136-
$this->assertSame(5, $queue->getQueueSize());
137-
$this->assertSame(3, $queue->getRunningSize());
136+
$this->assertSame(3, $queue->getQueueSize());
137+
$this->assertSame(5, $queue->getRunningSize());
138138

139139
$queue->cancelAll();
140140
$this->assertSame(0, $queue->getQueueSize());
@@ -145,19 +145,18 @@ public function testCancelAll(): void
145145
1 => 'Removing top item from queue - new size is 3',
146146
2 => 'Running process 1',
147147
3 => 'Queue not full - looking at first item in the queue',
148-
4 => 'Canot remote first item from the queue - it has size 2, current queue size is 3, new size would be 5',
149-
5 => 'Queue not full - looking at first item in the queue',
150-
6 => 'Canot remote first item from the queue - it has size 2, current queue size is 3, new size would be 5',
151-
7 => 'Process 1 finished unsuccessfully: Runnable 1 canceled',
152-
8 => 'Queue not full - looking at first item in the queue',
153-
9 => 'Removing top item from queue - new size is 2',
154-
10 => 'Running process 2',
155-
11 => 'Process 2 finished unsuccessfully: Runnable 2 canceled',
156-
12 => 'Queue not full - looking at first item in the queue',
157-
13 => 'Removing top item from queue - new size is 3',
158-
14 => 'Running process 3',
159-
15 => 'Process 3 finished unsuccessfully: Runnable 3 canceled',
160-
16 => 'Queue empty',
148+
4 => 'Removing top item from queue - new size is 5',
149+
5 => 'Running process 2',
150+
6 => 'Queue not full - looking at first item in the queue',
151+
7 => 'Canot remote first item from the queue - it has size 3, current queue size is 5, new size would be 8',
152+
8 => 'Process 1 finished unsuccessfully: Runnable 1 canceled',
153+
9 => 'Queue not full - looking at first item in the queue',
154+
10 => 'Removing top item from queue - new size is 5',
155+
11 => 'Running process 3',
156+
12 => 'Process 3 finished unsuccessfully: Runnable 3 canceled',
157+
13 => 'Queue empty',
158+
14 => 'Process 2 finished unsuccessfully: Runnable 2 canceled',
159+
15 => 'Queue empty',
161160
], $logger->getMessages());
162161
}
163162

0 commit comments

Comments
 (0)