Skip to content

Commit 6db267c

Browse files
authored
Merge pull request #183 from php-enqueue/consumption-do-not-close-contexts
[consumption] Do not close context.
2 parents 6255d48 + 78e3642 commit 6db267c

8 files changed

+16
-56
lines changed

Diff for: pkg/enqueue/Consumption/QueueConsumer.php

-3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public function consume(ExtensionInterface $runtimeExtension = null)
149149
$context->setExecutionInterrupted(true);
150150

151151
$extension->onInterrupted($context);
152-
$this->psrContext->close();
153152

154153
return;
155154
} catch (\Exception $exception) {
@@ -158,10 +157,8 @@ public function consume(ExtensionInterface $runtimeExtension = null)
158157

159158
try {
160159
$this->onInterruptionByException($extension, $context);
161-
$this->psrContext->close();
162160
} catch (\Exception $e) {
163161
// for some reason finally does not work here on php5.5
164-
$this->psrContext->close();
165162

166163
throw $e;
167164
}

Diff for: pkg/enqueue/Symfony/Client/ConsumeMessagesCommand.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9797
$this->consumer->bind($queue, $this->processor);
9898
}
9999

100-
try {
101-
$this->consumer->consume($this->getRuntimeExtensions($input, $output));
102-
} finally {
103-
$this->consumer->getPsrContext()->close();
104-
}
100+
$this->consumer->consume($this->getRuntimeExtensions($input, $output));
105101
}
106102

107103
/**

Diff for: pkg/enqueue/Symfony/Consumption/ConsumeMessagesCommand.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
5656

5757
$runtimeExtensions = new ChainExtension($extensions);
5858

59-
try {
60-
$this->consumer->consume($runtimeExtensions);
61-
} finally {
62-
$this->consumer->getPsrContext()->close();
63-
}
59+
$this->consumer->consume($runtimeExtensions);
6460
}
6561
}

Diff for: pkg/enqueue/Symfony/Consumption/ContainerAwareConsumeMessagesCommand.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
8787

8888
$runtimeExtensions = new ChainExtension($extensions);
8989

90-
try {
91-
foreach ($queues as $queue) {
92-
$this->consumer->bind($queue, $processor);
93-
}
94-
95-
$this->consumer->consume($runtimeExtensions);
96-
} finally {
97-
$this->consumer->getPsrContext()->close();
90+
foreach ($queues as $queue) {
91+
$this->consumer->bind($queue, $processor);
9892
}
93+
94+
$this->consumer->consume($runtimeExtensions);
9995
}
10096
}

Diff for: pkg/enqueue/Tests/Consumption/QueueConsumerTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -652,13 +652,13 @@ public function testShouldAllowInterruptConsumingOnIdle()
652652
$queueConsumer->consume();
653653
}
654654

655-
public function testShouldCloseSessionWhenConsumptionInterrupted()
655+
public function testShouldNotCloseContextWhenConsumptionInterrupted()
656656
{
657657
$messageConsumerStub = $this->createMessageConsumerStub($message = null);
658658

659659
$contextStub = $this->createPsrContextStub($messageConsumerStub);
660660
$contextStub
661-
->expects($this->once())
661+
->expects($this->never())
662662
->method('close')
663663
;
664664

@@ -681,15 +681,15 @@ public function testShouldCloseSessionWhenConsumptionInterrupted()
681681
$queueConsumer->consume();
682682
}
683683

684-
public function testShouldCloseSessionWhenConsumptionInterruptedByException()
684+
public function testShouldNotCloseContextWhenConsumptionInterruptedByException()
685685
{
686686
$expectedException = new \Exception();
687687

688688
$messageConsumerStub = $this->createMessageConsumerStub($message = $this->createMessageMock());
689689

690690
$contextStub = $this->createPsrContextStub($messageConsumerStub);
691691
$contextStub
692-
->expects($this->once())
692+
->expects($this->never())
693693
->method('close')
694694
;
695695

Diff for: pkg/enqueue/Tests/Symfony/Client/ConsumeMessagesCommandTest.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function testShouldExecuteConsumptionAndUseDefaultQueueName()
9191

9292
$context = $this->createPsrContextMock();
9393
$context
94-
->expects($this->once())
94+
->expects($this->never())
9595
->method('close')
9696
;
9797

@@ -106,11 +106,6 @@ public function testShouldExecuteConsumptionAndUseDefaultQueueName()
106106
->method('consume')
107107
->with($this->isInstanceOf(ChainExtension::class))
108108
;
109-
$consumer
110-
->expects($this->once())
111-
->method('getPsrContext')
112-
->will($this->returnValue($context))
113-
;
114109

115110
$queueMetaRegistry = $this->createQueueMetaRegistry([
116111
'default' => [],
@@ -138,7 +133,7 @@ public function testShouldExecuteConsumptionAndUseCustomClientDestinationName()
138133

139134
$context = $this->createPsrContextMock();
140135
$context
141-
->expects($this->once())
136+
->expects($this->never())
142137
->method('close')
143138
;
144139

@@ -153,11 +148,6 @@ public function testShouldExecuteConsumptionAndUseCustomClientDestinationName()
153148
->method('consume')
154149
->with($this->isInstanceOf(ChainExtension::class))
155150
;
156-
$consumer
157-
->expects($this->once())
158-
->method('getPsrContext')
159-
->will($this->returnValue($context))
160-
;
161151

162152
$queueMetaRegistry = $this->createQueueMetaRegistry([
163153
'non-default-queue' => [],

Diff for: pkg/enqueue/Tests/Symfony/Consumption/ConsumeMessagesCommandTest.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testShouldExecuteConsumption()
4848
{
4949
$context = $this->createContextMock();
5050
$context
51-
->expects($this->once())
51+
->expects($this->never())
5252
->method('close')
5353
;
5454

@@ -58,11 +58,6 @@ public function testShouldExecuteConsumption()
5858
->method('consume')
5959
->with($this->isInstanceOf(ChainExtension::class))
6060
;
61-
$consumer
62-
->expects($this->once())
63-
->method('getPsrContext')
64-
->will($this->returnValue($context))
65-
;
6661

6762
$command = new ConsumeMessagesCommand($consumer);
6863

Diff for: pkg/enqueue/Tests/Symfony/Consumption/ContainerAwareConsumeMessagesCommandTest.php

+3-13
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ public function testThrowIfNeitherQueueOptionNorProcessorImplementsQueueSubscrib
9797
]);
9898
}
9999

100-
public function testShouldExecuteConsumptionWithExplisitlySetQueueViaQueueOption()
100+
public function testShouldExecuteConsumptionWithExplicitlySetQueueViaQueueOption()
101101
{
102102
$processor = $this->createProcessor();
103103

104104
$context = $this->createContextMock();
105105
$context
106-
->expects($this->once())
106+
->expects($this->never())
107107
->method('close')
108108
;
109109

@@ -118,11 +118,6 @@ public function testShouldExecuteConsumptionWithExplisitlySetQueueViaQueueOption
118118
->method('consume')
119119
->with($this->isInstanceOf(ChainExtension::class))
120120
;
121-
$consumer
122-
->expects($this->exactly(1))
123-
->method('getPsrContext')
124-
->will($this->returnValue($context))
125-
;
126121

127122
$container = new Container();
128123
$container->set('processor-service', $processor);
@@ -143,7 +138,7 @@ public function testShouldExecuteConsumptionWhenProcessorImplementsQueueSubscrib
143138

144139
$context = $this->createContextMock();
145140
$context
146-
->expects($this->once())
141+
->expects($this->never())
147142
->method('close')
148143
;
149144

@@ -163,11 +158,6 @@ public function testShouldExecuteConsumptionWhenProcessorImplementsQueueSubscrib
163158
->method('consume')
164159
->with($this->isInstanceOf(ChainExtension::class))
165160
;
166-
$consumer
167-
->expects($this->at(3))
168-
->method('getPsrContext')
169-
->will($this->returnValue($context))
170-
;
171161

172162
$container = new Container();
173163
$container->set('processor-service', $processor);

0 commit comments

Comments
 (0)