Skip to content
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

fix: don't emit taskPending if task is skipped #555

Merged
merged 1 commit into from
Feb 22, 2019
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
12 changes: 7 additions & 5 deletions garden-service/src/task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ export class TaskGraph {
}

private async addTaskInternal(task: BaseTask) {
this.garden.events.emit("taskPending", {
addedAt: new Date(),
key: task.getKey(),
version: task.version,
})
await this.addNodeWithDependencies(task)
await this.rebuild()
if (this.index.getNode(task)) {
this.garden.events.emit("taskPending", {
addedAt: new Date(),
key: task.getKey(),
version: task.version,
})
}
}

private getNode(task: BaseTask): TaskNode | null {
Expand Down
22 changes: 22 additions & 0 deletions garden-service/test/src/task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,28 @@ describe("task-graph", () => {
])
})

it.only("should not emit a taskPending event when adding a task with a cached result", async () => {
const now = freezeTime()

const garden = await getGarden()
const graph = new TaskGraph(garden, garden.log)

const task = new TestTask(garden, "a", false)
await graph.addTask(task)
const result = await graph.processTasks()

// repeatedTask has the same baseKey and version as task, so its result is already cached
const repeatedTask = new TestTask(garden, "a", false)
await graph.addTask(repeatedTask)

expect(garden.events.log).to.eql([
{ name: "taskPending", payload: { addedAt: now, key: task.getKey(), version: task.version } },
{ name: "taskGraphProcessing", payload: { startedAt: now } },
{ name: "taskComplete", payload: result["a"] },
{ name: "taskGraphComplete", payload: { completedAt: now } },
])
})

it("should emit events when processing and completing a task", async () => {
const now = freezeTime()

Expand Down