Skip to content

Commit

Permalink
Use keep_on_completion conditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasolson committed Jul 13, 2021
1 parent f567031 commit 9766368
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ describe('request utils', () => {
});
expect(params).toHaveProperty('keep_alive', '1m');
});

test('Uses `keep_on_completion` if enabled', async () => {
const mockUiSettingsClient = getMockUiSettingsClient({
[UI_SETTINGS.SEARCH_INCLUDE_FROZEN]: false,
});
const mockConfig = getMockSearchSessionsConfig({});
const params = await getDefaultAsyncSubmitParams(mockUiSettingsClient, mockConfig, {
sessionId: 'foo',
});
expect(params).toHaveProperty('keep_on_completion', true);
});

test('Does not use `keep_on_completion` if disabled', async () => {
const mockUiSettingsClient = getMockUiSettingsClient({
[UI_SETTINGS.SEARCH_INCLUDE_FROZEN]: false,
});
const mockConfig = getMockSearchSessionsConfig({
defaultExpiration: moment.duration(3, 'd'),
enabled: false,
});
const params = await getDefaultAsyncSubmitParams(mockUiSettingsClient, mockConfig, {
sessionId: 'foo',
});
expect(params).toHaveProperty('keep_on_completion', false);
});
});

describe('getDefaultAsyncGetParams', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ export async function getDefaultAsyncSubmitParams(
const keepAlive = searchSessionsConfig?.enabled
? `${searchSessionsConfig.defaultExpiration.asMilliseconds()}ms`
: '1m';

// Always return an ID, even if the request completes quickly
const keepOnCompletion = searchSessionsConfig?.enabled && !!options.sessionId;
return {
batched_reduce_size: 64,
keep_on_completion: !!options.sessionId, // Always return an ID, even if the request completes quickly
keep_on_completion: keepOnCompletion,
...getDefaultAsyncGetParams(options),
...(await getIgnoreThrottled(uiSettingsClient)),
...(await getDefaultSearchParams(uiSettingsClient)),
Expand Down

0 comments on commit 9766368

Please sign in to comment.