-
Notifications
You must be signed in to change notification settings - Fork 0
feat!: support Update_Delete_Cache and Swap_Delete_Cache jobs instead of TilesSeeding (MAPCO-11709) #77
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
Merged
feat!: support Update_Delete_Cache and Swap_Delete_Cache jobs instead of TilesSeeding (MAPCO-11709) #77
Changes from all commits
Commits
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
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
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
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
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
115 changes: 115 additions & 0 deletions
115
tests/integration/tasks/deleteCache/taskManager.spec.ts
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 |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import nock, { cleanAll, isDone, pendingMocks } from 'nock'; | ||
| import { OperationStatus } from '@map-colonies/mc-priority-queue'; | ||
| import { StatusCodes as httpStatusCodes } from 'http-status-codes'; | ||
| import { trace } from '@opentelemetry/api'; | ||
| import { jsLogger } from '@map-colonies/js-logger'; | ||
| import { initConfig } from '../../../../src/common/config'; | ||
| import { configMock } from '../../../mocks/configMock'; | ||
| import { getApp } from '../../../../src/app'; | ||
| import type { IJobManagerConfig, IJobDefinitionsConfig } from '../../../../src/common/interfaces'; | ||
| import { getDeleteCacheJobMock, getTaskMock } from '../../../mocks/jobMocks'; | ||
| import { calculateJobPercentage } from '../../../../src/utils/jobUtils'; | ||
| import { SERVICES } from '../../../../src/common/constants'; | ||
| import { registerExternalValues } from '../../../../src/containerConfig'; | ||
| import { TasksRequestSender } from '../helpers/requestSender'; | ||
| import { getTestContainerConfig, resetContainer } from '../helpers/containerConfig'; | ||
|
|
||
| describe('tasks', function () { | ||
| let requestSender: TasksRequestSender; | ||
| let jobManagerConfigMock: IJobManagerConfig; | ||
| let jobDefinitionsConfig: IJobDefinitionsConfig; | ||
|
|
||
| beforeAll(async function () { | ||
| await initConfig(true); | ||
| }); | ||
|
|
||
| beforeEach(async function () { | ||
| const [app] = await getApp({ | ||
| override: [...(await getTestContainerConfig())], | ||
| useChild: true, | ||
| }); | ||
|
|
||
| await registerExternalValues({ | ||
| override: [ | ||
| { token: SERVICES.LOGGER, provider: { useValue: await jsLogger({ enabled: false }) } }, | ||
| { token: SERVICES.CONFIG, provider: { useValue: configMock } }, | ||
| { token: SERVICES.TRACER, provider: { useValue: trace.getTracer('testTracer') } }, | ||
| ], | ||
| }); | ||
|
|
||
| requestSender = new TasksRequestSender(app); | ||
| jobManagerConfigMock = configMock.get('jobManagement.config') as unknown as IJobManagerConfig; | ||
| jobDefinitionsConfig = configMock.get('jobDefinitions') as IJobDefinitionsConfig; | ||
| cleanAll(); | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| resetContainer(); | ||
| jest.restoreAllMocks(); | ||
| if (!isDone()) { | ||
| throw new Error(`Not all nock interceptors were used: ${JSON.stringify(pendingMocks())}`); | ||
| } | ||
| }); | ||
|
|
||
| const deleteCacheJobTypes = [{ jobTypeKey: 'updateCacheDeletion' as const }, { jobTypeKey: 'swapCacheDeletion' as const }]; | ||
|
|
||
| describe('Happy Path', function () { | ||
| it.each(deleteCacheJobTypes)( | ||
| 'should return 200 when getting completed but not last tiles-deletion task - $jobTypeKey', | ||
| async ({ jobTypeKey }) => { | ||
| // mocks | ||
| const mockJob = getDeleteCacheJobMock(jobDefinitionsConfig.jobs[jobTypeKey]); | ||
| const mockTask = getTaskMock(mockJob.id, { type: jobDefinitionsConfig.tasks.tilesDeletion, status: OperationStatus.COMPLETED }); | ||
| nock(jobManagerConfigMock.jobManagerBaseUrl).post('/tasks/find', { id: mockTask.id }).reply(httpStatusCodes.OK, [mockTask]); | ||
| nock(jobManagerConfigMock.jobManagerBaseUrl) | ||
| .get(`/jobs/${mockJob.id}`) | ||
| .query({ shouldReturnTasks: false }) | ||
| .reply(httpStatusCodes.OK, mockJob); | ||
| const taskPercentage = calculateJobPercentage(mockJob.completedTasks, mockJob.taskCount); | ||
| nock(jobManagerConfigMock.jobManagerBaseUrl).put(`/jobs/${mockJob.id}`, { percentage: taskPercentage }).reply(httpStatusCodes.OK); | ||
| // action | ||
| const response = await requestSender.handleTaskNotification(mockTask.id); | ||
| // expectation | ||
| expect(response.status).toBe(httpStatusCodes.OK); | ||
| expect(response).toSatisfyApiSpec(); | ||
| } | ||
| ); | ||
|
|
||
| it.each(deleteCacheJobTypes)('should return 200 when getting last completed tiles-deletion task - $jobTypeKey', async ({ jobTypeKey }) => { | ||
| // mocks | ||
| const mockJob = getDeleteCacheJobMock(jobDefinitionsConfig.jobs[jobTypeKey], { completedTasks: 5, taskCount: 5 }); | ||
| const mockTask = getTaskMock(mockJob.id, { type: jobDefinitionsConfig.tasks.tilesDeletion, status: OperationStatus.COMPLETED }); | ||
| nock(jobManagerConfigMock.jobManagerBaseUrl).post('/tasks/find', { id: mockTask.id }).reply(httpStatusCodes.OK, [mockTask]); | ||
| nock(jobManagerConfigMock.jobManagerBaseUrl).get(`/jobs/${mockJob.id}`).query({ shouldReturnTasks: false }).reply(httpStatusCodes.OK, mockJob); | ||
| nock(jobManagerConfigMock.jobManagerBaseUrl) | ||
| .put(`/jobs/${mockJob.id}`, { percentage: 100, status: OperationStatus.COMPLETED }) | ||
| .reply(httpStatusCodes.OK); | ||
| // action | ||
| const response = await requestSender.handleTaskNotification(mockTask.id); | ||
| // expectation | ||
| expect(response.status).toBe(httpStatusCodes.OK); | ||
| expect(response).toSatisfyApiSpec(); | ||
| }); | ||
|
|
||
| it.each(deleteCacheJobTypes)( | ||
| 'should return 200 and fail the job when getting failed tiles-deletion task - $jobTypeKey', | ||
| async ({ jobTypeKey }) => { | ||
| // mocks | ||
| const reason = 'Tiles deletion failed due to storage error'; | ||
| const mockJob = getDeleteCacheJobMock(jobDefinitionsConfig.jobs[jobTypeKey]); | ||
| const mockTask = getTaskMock(mockJob.id, { type: jobDefinitionsConfig.tasks.tilesDeletion, status: OperationStatus.FAILED, reason }); | ||
| nock(jobManagerConfigMock.jobManagerBaseUrl).post('/tasks/find', { id: mockTask.id }).reply(httpStatusCodes.OK, [mockTask]); | ||
| nock(jobManagerConfigMock.jobManagerBaseUrl) | ||
| .get(`/jobs/${mockJob.id}`) | ||
| .query({ shouldReturnTasks: false }) | ||
| .reply(httpStatusCodes.OK, mockJob); | ||
| nock(jobManagerConfigMock.jobManagerBaseUrl).put(`/jobs/${mockJob.id}`, { status: OperationStatus.FAILED, reason }).reply(httpStatusCodes.OK); | ||
| // action | ||
| const response = await requestSender.handleTaskNotification(mockTask.id); | ||
| // expectation | ||
| expect(response.status).toBe(httpStatusCodes.OK); | ||
| expect(response).toSatisfyApiSpec(); | ||
| } | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.