-
Notifications
You must be signed in to change notification settings - Fork 696
Move publishRetryMessage to end of processing loop to avoid duplicate retries #4966
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
base: stu/fix_job_retry
Are you sure you want to change the base?
Changes from all commits
3e24ec6
90874d7
11c1578
b5399f6
cba7bbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1698,6 +1698,7 @@ describe('Retry mechanism tests', () => { | |
|
|
||
| it('calls publishRetryMessage for each valid message when job is queued', async () => { | ||
| const messages = createTestMessages(3); | ||
| mockCreateRunner.mockResolvedValue(['i-12345', 'i-67890', 'i-abcdef']); // Create all requested runners | ||
|
|
||
| await scaleUpModule.scaleUp(messages); | ||
|
|
||
|
|
@@ -1749,15 +1750,16 @@ describe('Retry mechanism tests', () => { | |
| ); | ||
| }); | ||
|
|
||
| it('calls publishRetryMessage even when maximum runners is reached', async () => { | ||
| it('does not call publishRetryMessage when maximum runners is reached and messages are marked invalid', async () => { | ||
| process.env.RUNNERS_MAXIMUM_COUNT = '0'; // No runners can be created | ||
|
|
||
| const messages = createTestMessages(2); | ||
|
|
||
| await scaleUpModule.scaleUp(messages); | ||
|
|
||
| // publishRetryMessage should still be called even though no runners will be created | ||
| expect(mockPublishRetryMessage).toHaveBeenCalledTimes(2); | ||
| // publishRetryMessage should NOT be called because messages are marked as invalid | ||
| // Invalid messages go back to the SQS queue and will be retried there | ||
| expect(mockPublishRetryMessage).not.toHaveBeenCalled(); | ||
| expect(createRunner).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
|
|
@@ -1781,6 +1783,7 @@ describe('Retry mechanism tests', () => { | |
|
|
||
| it('calls publishRetryMessage when ENABLE_JOB_QUEUED_CHECK is false', async () => { | ||
| process.env.ENABLE_JOB_QUEUED_CHECK = 'false'; | ||
| mockCreateRunner.mockResolvedValue(['i-12345', 'i-67890']); // Create all requested runners | ||
|
|
||
| const messages = createTestMessages(2); | ||
|
|
||
|
|
@@ -1792,6 +1795,7 @@ describe('Retry mechanism tests', () => { | |
| }); | ||
|
|
||
| it('calls publishRetryMessage for each message in a multi-runner scenario', async () => { | ||
| mockCreateRunner.mockResolvedValue(['i-12345', 'i-67890', 'i-abcdef', 'i-11111', 'i-22222']); // Create all requested runners | ||
|
Member
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. @copilot why this line?
Contributor
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. Same reason - ensures all 5 requested runners are created so no messages are marked rejected. This tests that |
||
| const messages = createTestMessages(5); | ||
|
|
||
| await scaleUpModule.scaleUp(messages); | ||
|
|
@@ -1808,8 +1812,9 @@ describe('Retry mechanism tests', () => { | |
| }); | ||
| }); | ||
|
|
||
| it('calls publishRetryMessage before runner creation', async () => { | ||
| it('calls publishRetryMessage after runner creation', async () => { | ||
| const messages = createTestMessages(1); | ||
| mockCreateRunner.mockResolvedValue(['i-12345']); // Create the requested runner | ||
|
Member
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. @copilot why this line?
Contributor
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. Ensures the requested runner is created successfully. This test verifies the order of operations (runner creation before retry message publishing), and needs a successful creation to ensure the retry message is actually published. |
||
|
|
||
| const callOrder: string[] = []; | ||
| mockPublishRetryMessage.mockImplementation(() => { | ||
|
|
@@ -1823,7 +1828,7 @@ describe('Retry mechanism tests', () => { | |
|
|
||
| await scaleUpModule.scaleUp(messages); | ||
|
|
||
| expect(callOrder).toEqual(['publishRetryMessage', 'createRunner']); | ||
| expect(callOrder).toEqual(['createRunner', 'publishRetryMessage']); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
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.
@copilot why is this added?
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.
This ensures all 3 requested runners are created successfully. With the new behavior,
publishRetryMessageis only called for messages that aren't rejected. The default mock only creates 1 runner, so when 3 are requested, 2 messages would be marked rejected (creation failed) and wouldn't get retry messages. By mocking all 3 runners, we test that retry messages are published for all successfully processed messages.