Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
kahirokunn committed Jun 19, 2024
1 parent 8189114 commit 3c3b5d9
Showing 1 changed file with 49 additions and 78 deletions.
127 changes: 49 additions & 78 deletions packages/kubekit-client/test/task_manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,23 @@ describe('TaskManager', () => {
const taskCallbacks = Array.from({ length: 100 }, () => vi.fn());
const finalTaskCallback = vi.fn();
const num = 100;
const key = TaskManager.getKey({
apiVersion: 'v1',
kind: 'Namespace',
metadata: {
name: 'name1',
},
});

for (let i = 0; i < num; i++) {
taskManager.addTask({
key: TaskManager.getKey({
apiVersion: 'v1',
kind: 'Namespace',
metadata: {
name: 'name1',
},
}),
key,
task: createTask('namespace1', 'name1', 0, taskCallbacks[i]),
});
}

taskManager.addTask({
key: TaskManager.getKey({
apiVersion: 'v1',
kind: 'Namespace',
metadata: {
name: 'name1',
},
}),
key,
task: createTask('namespace1', 'name1', 0, finalTaskCallback),
});

Expand All @@ -111,30 +106,24 @@ describe('TaskManager', () => {
const taskCallbacks = Array.from({ length: 100 }, () => vi.fn());
const finalTaskCallback = vi.fn();
const num = 100;
const key = TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
});

for (let i = 0; i < num; i++) {
taskManager.addTask({
key: TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
}),
key,
task: createTask('namespace1', 'name1', 0, taskCallbacks[i]),
});
}

taskManager.addTask({
key: TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
}),
key,
task: createTask('namespace1', 'name1', 0, finalTaskCallback),
});

Expand All @@ -150,28 +139,22 @@ describe('TaskManager', () => {
const taskManager = new TaskManager();
const task1Callback = vi.fn();
const task2Callback = vi.fn();
const key = TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
});

taskManager.addTask({
key: TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
}),
key,
task: task1Callback,
});

taskManager.addTask({
key: TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
}),
key,
task: task2Callback,
});

Expand All @@ -184,27 +167,21 @@ describe('TaskManager', () => {
wait: 10,
});
const taskCallback = vi.fn();
const key = TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
});

taskManager.addTask({
key: TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
}),
key,
task: createTask('namespace1', 'name1', 50, taskCallback),
});
taskManager.addTask({
key: TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
}),
key,
task: createTask('namespace1', 'name1', 50, taskCallback),
});

Expand Down Expand Up @@ -266,30 +243,24 @@ describe('TaskManager', () => {
const taskManager = new TaskManager();
const task1Callback = vi.fn();
const task2Callback = vi.fn();
const key = TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
});

taskManager.addTask({
key: TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
}),
key,
task: () => {
task1Callback();
return Promise.reject(new Error('Task failed'));
},
});
taskManager.addTask({
key: TaskManager.getKey({
apiVersion: 'v1',
kind: 'Pod',
metadata: {
namespace: 'namespace1',
name: 'name1',
},
}),
key,
task: createTask('namespace1', 'name1', 1, task2Callback),
});

Expand Down

0 comments on commit 3c3b5d9

Please sign in to comment.