From a975393897926d7ec1ec44aaa94a9ab64a5f1149 Mon Sep 17 00:00:00 2001 From: Clem Blanco Date: Wed, 4 Oct 2023 00:10:32 +0200 Subject: [PATCH 1/5] fix: undeleted messages --- src/Sub/Queue/Jobs/SnsEventDispatcherJob.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php b/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php index 507e9c3..af71256 100644 --- a/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php +++ b/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php @@ -21,6 +21,7 @@ public function fire() 'message delivery is disabled for your SQS subscription.', $this->job); } + $this->release(); return; } @@ -29,6 +30,8 @@ public function fire() 'payload' => json_decode($this->snsMessage(), true), 'subject' => $this->snsSubject(), ]); + + $this->delete(); } } From 95e222d50b6796aeede523ed55187a149fa2420a Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 3 Oct 2023 22:10:43 +0000 Subject: [PATCH 2/5] Apply fixes from StyleCI --- src/Sub/Queue/Jobs/SnsEventDispatcherJob.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php b/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php index af71256..7c03740 100644 --- a/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php +++ b/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php @@ -22,6 +22,7 @@ public function fire() } $this->release(); + return; } From 1c31cb4ad4eb5aecbb2e9ad56e762bbf39d65a33 Mon Sep 17 00:00:00 2001 From: clemblanco Date: Wed, 4 Oct 2023 01:10:58 +0200 Subject: [PATCH 3/5] WIP --- src/Sub/Queue/Jobs/SnsEventDispatcherJob.php | 4 ++ .../Queue/Jobs/SnsEventDispatcherJobTest.php | 40 ++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php b/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php index 7c03740..22bacbf 100644 --- a/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php +++ b/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php @@ -33,7 +33,11 @@ public function fire() ]); $this->delete(); + + return; } + + $this->release(); } /** diff --git a/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php b/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php index e82180f..6b1781b 100644 --- a/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php +++ b/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php @@ -113,7 +113,7 @@ public function it_will_handle_empty_messages_with_a_subject() } /** @test */ - public function it_will_not_handle_raw_notification_messages() + public function it_will_not_handle_raw_notification_messages_and_release_the_message_onto_the_queue() { Log::shouldReceive('error')->once()->with( m::pattern('/^SqsSnsQueue: Invalid SNS payload/'), @@ -122,32 +122,60 @@ public function it_will_not_handle_raw_notification_messages() $this->mockedJobData = $this->mockedRawNotificationMessage()['Messages'][0]; - $this->getJob()->fire(); + $job = $this->getJob(); + $job->shouldNotReceive('delete'); + $job->shouldReceive('release')->once(); + + $job->fire(); Event::assertNothingDispatched(); } /** @test */ - public function it_will_not_handle_messages_where_the_event_name_to_trigger_cannot_be_resolved() + public function it_will_not_handle_messages_where_the_event_name_to_trigger_cannot_be_resolved_and_release_the_message_onto_the_queue() { $this->mockedJobData = $this->mockedRichNotificationMessage([ 'TopicArn' => '', 'Subject' => '', ])['Messages'][0]; - $this->getJob()->fire(); + $job = $this->getJob(); + $job->shouldNotReceive('delete'); + $job->shouldReceive('release')->once(); + + $job->fire(); Event::assertNothingDispatched(); } + /** @test */ + public function it_will_delete_the_message_from_the_queue_when_it_managed_to_dispatch_an_event() + { + $this->mockedJobData = $this->mockedRichNotificationMessage([ + 'TopicArn' => 'TopicArn:123456', + ])['Messages'][0]; + + $job = $this->getJob(); + $job->shouldReceive('delete')->once(); + + $job->fire(); + + Event::assertDispatched('TopicArn:123456'); + } + + /** @return SnsEventDispatcherJob|\Mockery\LegacyMockInterface */ protected function getJob() { - return new SnsEventDispatcherJob( + $mock = m::mock(SnsEventDispatcherJob::class, [ $this->app, m::mock(SqsClient::class), $this->mockedJobData, 'connection-name', 'https://sqs.someregion.amazonaws.com/1234567891011/pubsub-events' - ); + ])->makePartial(); + + $mock->shouldReceive('delete', 'release')->byDefault(); + + return $mock; } } From da71b269adc8f096f52b38af0342c4cf085a2f27 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Tue, 3 Oct 2023 23:11:12 +0000 Subject: [PATCH 4/5] Apply fixes from StyleCI --- tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php b/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php index 6b1781b..53aa589 100644 --- a/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php +++ b/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php @@ -171,7 +171,7 @@ protected function getJob() m::mock(SqsClient::class), $this->mockedJobData, 'connection-name', - 'https://sqs.someregion.amazonaws.com/1234567891011/pubsub-events' + 'https://sqs.someregion.amazonaws.com/1234567891011/pubsub-events', ])->makePartial(); $mock->shouldReceive('delete', 'release')->byDefault(); From 27055c3c22377f47e3576d5015302f0ab46b5460 Mon Sep 17 00:00:00 2001 From: clemblanco Date: Wed, 4 Oct 2023 09:13:49 +0200 Subject: [PATCH 5/5] WIP --- src/Sub/Queue/Jobs/SnsEventDispatcherJob.php | 6 +----- tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php b/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php index 22bacbf..7e2905e 100644 --- a/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php +++ b/src/Sub/Queue/Jobs/SnsEventDispatcherJob.php @@ -31,13 +31,9 @@ public function fire() 'payload' => json_decode($this->snsMessage(), true), 'subject' => $this->snsSubject(), ]); - - $this->delete(); - - return; } - $this->release(); + $this->delete(); } /** diff --git a/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php b/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php index 53aa589..fcc3b2c 100644 --- a/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php +++ b/tests/Sub/Queue/Jobs/SnsEventDispatcherJobTest.php @@ -132,7 +132,7 @@ public function it_will_not_handle_raw_notification_messages_and_release_the_mes } /** @test */ - public function it_will_not_handle_messages_where_the_event_name_to_trigger_cannot_be_resolved_and_release_the_message_onto_the_queue() + public function it_will_not_handle_messages_where_the_event_name_to_trigger_cannot_be_resolved_and_delete_the_message_from_the_queue() { $this->mockedJobData = $this->mockedRichNotificationMessage([ 'TopicArn' => '', @@ -140,8 +140,8 @@ public function it_will_not_handle_messages_where_the_event_name_to_trigger_cann ])['Messages'][0]; $job = $this->getJob(); - $job->shouldNotReceive('delete'); - $job->shouldReceive('release')->once(); + $job->shouldReceive('delete')->once(); + $job->shouldNotReceive('release'); $job->fire();