-
Notifications
You must be signed in to change notification settings - Fork 12k
[13.x] Promote nested data to top-level managed queue event #61209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+191
−10
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
35ecac5
Capture exception preview
timacdonald 458ff5f
Capture job name
timacdonald 00a5913
Remove redundant encoding modification
timacdonald 811cbeb
Fix tests
timacdonald c2d7db4
Formatting
timacdonald cbe4c03
Remove truncation
timacdonald 53ee2de
Restore improved truncation
timacdonald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -477,7 +477,8 @@ public function testItEmitsFailedJobEvents() | |
| $job = $queue->pop(); | ||
| $job->fail(); | ||
| Str::createUuidsUsingSequence([Uuid::fromString('00dc709e-90c4-70c2-87c8-9b7127d20e8f')]); | ||
| $failedJobProvider->log('cloud', 'default', ['payload' => 'here'], new RuntimeException('Whoops!')); | ||
| $line = __LINE__ + 1; | ||
| $failedJobProvider->log('cloud', 'default', json_encode(['payload' => 'here', 'displayName' => 'App\\Jobs\\ProcessPodcast']), new RuntimeException('Whoops!')); | ||
| Str::createUuidsNormally(); | ||
| $queue->pop(); | ||
|
|
||
|
|
@@ -495,9 +496,9 @@ public function testItEmitsFailedJobEvents() | |
| 'queue' => 'default', | ||
| 'started_at' => '2000-01-02 03:04:05.060708', | ||
| 'attempts' => 1, | ||
| 'payload' => [ | ||
| 'payload' => 'here', | ||
| ], | ||
| 'payload' => json_encode(['payload' => 'here', 'displayName' => 'App\\Jobs\\ProcessPodcast']), | ||
| 'exception_preview' => 'RuntimeException: Whoops! in '.__FILE__.':'.$line, | ||
| 'job_name' => 'App\\Jobs\\ProcessPodcast', | ||
| ], | ||
| [ | ||
| '_cloud_event' => 'queue', | ||
|
|
@@ -509,6 +510,128 @@ public function testItEmitsFailedJobEvents() | |
| ], $eventsFake->emitted); | ||
| } | ||
|
|
||
| public function testItEmitsFailedJobEventsWithExceptionPreviewWithMessage() | ||
| { | ||
| $this->travelTo('2000-01-02 03:04:05.060708'); | ||
| $eventsFake = $this->fakeEvents(); | ||
| [$queue, $agent] = $this->fakeQueue(); | ||
| $failerFake = $this->fakeFailer(); | ||
| $failedJobProvider = new FailedJobProvider($failerFake, $eventsFake, $this->app['encrypter']); | ||
| $failedJobProvider->setQueue($queue); | ||
| $this->app[FailedJobProvider::class] = $failedJobProvider; | ||
|
|
||
| $agent->pushJob(); | ||
| $job = $queue->pop(); | ||
| $job->fail(); | ||
| Str::createUuidsUsingSequence([Uuid::fromString('00dc709e-90c4-70c2-87c8-9b7127d20e8f')]); | ||
| $line = __LINE__ + 1; | ||
| $failedJobProvider->log('cloud', 'default', json_encode(['payload' => 'here']), new RuntimeException('Whoops!')); | ||
| Str::createUuidsNormally(); | ||
| $queue->pop(); | ||
|
|
||
| $this->assertSame( | ||
| 'RuntimeException: Whoops! in '.__FILE__.':'.$line, | ||
| $eventsFake->emitted[1]['exception_preview'], | ||
| ); | ||
| } | ||
|
|
||
| public function testItEmitsFailedJobEventsWithExceptionPreviewWithoutMessage() | ||
| { | ||
| $this->travelTo('2000-01-02 03:04:05.060708'); | ||
| $eventsFake = $this->fakeEvents(); | ||
| [$queue, $agent] = $this->fakeQueue(); | ||
| $failerFake = $this->fakeFailer(); | ||
| $failedJobProvider = new FailedJobProvider($failerFake, $eventsFake, $this->app['encrypter']); | ||
| $failedJobProvider->setQueue($queue); | ||
| $this->app[FailedJobProvider::class] = $failedJobProvider; | ||
|
|
||
| $agent->pushJob(); | ||
| $job = $queue->pop(); | ||
| $job->fail(); | ||
| Str::createUuidsUsingSequence([Uuid::fromString('00dc709e-90c4-70c2-87c8-9b7127d20e8f')]); | ||
| $line = __LINE__ + 1; | ||
| $failedJobProvider->log('cloud', 'default', json_encode(['payload' => 'here']), new RuntimeException); | ||
| Str::createUuidsNormally(); | ||
| $queue->pop(); | ||
|
|
||
| $this->assertSame( | ||
| 'RuntimeException in '.__FILE__.':'.$line, | ||
| $eventsFake->emitted[1]['exception_preview'], | ||
| ); | ||
| } | ||
|
|
||
| public function testItSanitizesInvalidUtf8InTheExceptionField() | ||
| { | ||
| $this->travelTo('2000-01-02 03:04:05.060708'); | ||
| $eventsFake = $this->fakeEvents(); | ||
| [$queue, $agent] = $this->fakeQueue(); | ||
| $failerFake = $this->fakeFailer(); | ||
| $failedJobProvider = new FailedJobProvider($failerFake, $eventsFake, $this->app['encrypter']); | ||
| $failedJobProvider->setQueue($queue); | ||
| $this->app[FailedJobProvider::class] = $failedJobProvider; | ||
|
|
||
| $agent->pushJob(); | ||
| $job = $queue->pop(); | ||
| $job->fail(); | ||
| Str::createUuidsUsingSequence([Uuid::fromString('00dc709e-90c4-70c2-87c8-9b7127d20e8f')]); | ||
| $failedJobProvider->log('cloud', 'default', json_encode(['payload' => 'here']), new RuntimeException("Bad byte: \xFF")); | ||
| Str::createUuidsNormally(); | ||
| $queue->pop(); | ||
|
|
||
| $this->assertTrue(mb_check_encoding($eventsFake->stream, 'UTF-8')); | ||
| $this->assertTrue(mb_check_encoding($eventsFake->emitted[1]['exception'], 'UTF-8')); | ||
| $this->assertStringContainsString('Bad byte: �', $eventsFake->emitted[1]['exception']); | ||
| $this->assertStringContainsString('Bad byte: �', $eventsFake->emitted[1]['exception_preview']); | ||
| } | ||
|
|
||
| public function testItEmitsFailedJobEventsWithJobDisplayName() | ||
| { | ||
| $this->travelTo('2000-01-02 03:04:05.060708'); | ||
| $eventsFake = $this->fakeEvents(); | ||
| [$queue, $agent] = $this->fakeQueue(); | ||
| $failerFake = $this->fakeFailer(); | ||
| $failedJobProvider = new FailedJobProvider($failerFake, $eventsFake, $this->app['encrypter']); | ||
| $failedJobProvider->setQueue($queue); | ||
| $this->app[FailedJobProvider::class] = $failedJobProvider; | ||
|
|
||
| $agent->pushJob(); | ||
| $job = $queue->pop(); | ||
| $job->fail(); | ||
| Str::createUuidsUsingSequence([Uuid::fromString('00dc709e-90c4-70c2-87c8-9b7127d20e8f')]); | ||
| $failedJobProvider->log('cloud', 'default', json_encode(['displayName' => 'App\\Jobs\\ProcessPodcast']), new RuntimeException('Whoops!')); | ||
| Str::createUuidsNormally(); | ||
| $queue->pop(); | ||
|
|
||
| $this->assertSame( | ||
| 'App\\Jobs\\ProcessPodcast', | ||
| $eventsFake->emitted[1]['job_name'], | ||
| ); | ||
| } | ||
|
|
||
| public function testItEmitsFailedJobEventsWithoutJobDisplayName() | ||
| { | ||
| $this->travelTo('2000-01-02 03:04:05.060708'); | ||
| $eventsFake = $this->fakeEvents(); | ||
| [$queue, $agent] = $this->fakeQueue(); | ||
| $failerFake = $this->fakeFailer(); | ||
| $failedJobProvider = new FailedJobProvider($failerFake, $eventsFake, $this->app['encrypter']); | ||
| $failedJobProvider->setQueue($queue); | ||
| $this->app[FailedJobProvider::class] = $failedJobProvider; | ||
|
|
||
| $agent->pushJob(); | ||
| $job = $queue->pop(); | ||
| $job->fail(); | ||
| Str::createUuidsUsingSequence([Uuid::fromString('00dc709e-90c4-70c2-87c8-9b7127d20e8f')]); | ||
| $failedJobProvider->log('cloud', 'default', json_encode(['payload' => 'here']), new RuntimeException('Whoops!')); | ||
| Str::createUuidsNormally(); | ||
| $queue->pop(); | ||
|
|
||
| $this->assertSame( | ||
| '', | ||
| $eventsFake->emitted[1]['job_name'], | ||
| ); | ||
| } | ||
|
|
||
| public function testItEmitsReleasedJobEvents() | ||
| { | ||
| $this->travelTo('2000-01-02 03:04:05.060708'); | ||
|
|
@@ -1638,13 +1761,20 @@ private function fakeEvents() | |
| return $this->app->instance(Events::class, new class('test-socket') extends Events | ||
| { | ||
| public array $emitted = []; | ||
| public string $stream = ''; | ||
|
|
||
| protected function connected(): bool | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| public function emitMany(array $payloads): void | ||
| protected function write(string $payload): void | ||
| { | ||
| $this->emitted = [ | ||
| ...$this->emitted, | ||
| ...$payloads, | ||
| ]; | ||
| $this->stream .= $payload; | ||
|
|
||
| foreach (explode("\n", rtrim($payload, "\n")) as $write) { | ||
| $this->emitted[] = json_decode($write, associative: true); | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This refactor allows us to see what was really sent to the socket after being encoded. This helps with our UTF-8 assertions. |
||
| } | ||
| }); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mb_convert_encodingis redundant here. Our event class handles converting everything to UTF-8.