Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -375,5 +375,26 @@ describe('Buffered Task Store', () => {
expect(await results[2]).toMatchObject(partialTasks[2]);
expect(await results[3]).toMatchObject(partialTasks[3]);
});

test(`updates the stateVersion`, async () => {
const taskStore = taskStoreMock.create({ stateVersion: 2 });
const bufferedStore = new BufferedTaskStore(taskStore, {});

const task = taskManagerMock.createTask();
const partialTask = {
id: task.id,
version: task.version,
status: 'running' as TaskStatus,
};

taskStore.bulkPartialUpdate.mockResolvedValue([asOk(partialTask)]);

expect(
await bufferedStore.partialUpdate(partialTask, { validate: false, doc: task })
).toMatchObject(partialTask);
expect(taskStore.bulkPartialUpdate).toHaveBeenCalledWith([
{ ...partialTask, stateVersion: 2 },
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ export class BufferedTaskStore implements Updatable {
options: { validate: boolean; doc: ConcreteTaskInstance }
): Promise<ConcreteTaskInstance> {
// merge the partial updates with the doc and validate
this.taskStore.taskValidator.getValidatedTaskInstanceForUpdating(
const { stateVersion } = this.taskStore.taskValidator.getValidatedTaskInstanceForUpdating(
{ ...options.doc, ...partialDoc },
{ validate: options.validate }
);

const result = await unwrapPromise(this.bufferedPartialUpdate(partialDoc));
const result = await unwrapPromise(
this.bufferedPartialUpdate({ ...partialDoc, ...(stateVersion ? { stateVersion } : {}) })
);

// merge the partial update result with the doc and validate
return this.taskStore.taskValidator.getValidatedTaskInstanceFromReading(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ import type { TaskStore } from './task_store';
interface TaskStoreOptions {
index?: string;
taskManagerId?: string;
stateVersion?: number;
}
export const taskStoreMock = {
create({ index = '', taskManagerId = '' }: TaskStoreOptions = {}) {
create({ index = '', taskManagerId = '', stateVersion }: TaskStoreOptions = {}) {
const mocked = {
taskValidator: {
getValidatedTaskInstanceFromReading: jest.fn().mockImplementation((task) => task),
getValidatedTaskInstanceForUpdating: jest.fn().mockImplementation((task) => task),
getValidatedTaskInstanceForUpdating: jest
.fn()
.mockImplementation((task) => ({ ...task, ...(stateVersion ? { stateVersion } : {}) })),
},
convertToSavedObjectIds: jest.fn(),
update: jest.fn(),
Expand Down