Skip to content

Commit

Permalink
fix: fixed another dependency calculation bug
Browse files Browse the repository at this point in the history
Fixes #407.

Before this commit, getDependantsForModule was calculating the
dependants of the module's service/task dependencies instead of the
dependants of the module's services and tasks.

Adapted the task helper tests to cover this case too.

Also added some more debug/silly-level log statements.
  • Loading branch information
thsig authored and edvald committed Dec 4, 2018
1 parent 4a8428c commit 99df5d9
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 13 deletions.
8 changes: 2 additions & 6 deletions garden-service/src/dependency-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,10 @@ export class DependencyGraph {
* Returns all build and runtime dependants of module and its services & tasks (recursively).
*/
async getDependantsForModule(module: Module, filterFn?: DependencyRelationFilterFn): Promise<DependencyRelations> {
const runtimeDependencies = uniq(module.serviceDependencyNames.concat(module.taskDependencyNames))
const serviceNames = runtimeDependencies.filter(d => this.serviceMap[d])
const taskNames = runtimeDependencies.filter(d => this.taskMap[d])

return this.mergeRelations(... await Bluebird.all([
this.getDependants("build", module.name, true, filterFn),
this.getDependantsForMany("service", serviceNames, true, filterFn),
this.getDependantsForMany("task", taskNames, true, filterFn),
this.getDependantsForMany("service", module.serviceNames, true, filterFn),
this.getDependantsForMany("task", module.taskNames, true, filterFn),
]))
}

Expand Down
7 changes: 5 additions & 2 deletions garden-service/src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ export async function processServices(
export async function processModules(
{ garden, log, modules, watch, handler, changeHandler }: ProcessModulesParams,
): Promise<ProcessResults> {

log.debug("Starting processModules")

// Let the user know if any modules are linked to a local path
const linkedModulesMsg = modules
.filter(m => isModuleLinked(m, garden))
Expand Down Expand Up @@ -95,7 +98,7 @@ export async function processModules(
changeHandler = handler
}

const watcher = new FSWatcher(garden)
const watcher = new FSWatcher(garden, log)

const restartPromise = new Promise(async (resolve) => {
await watcher.watchModules(modules,
Expand All @@ -107,7 +110,7 @@ export async function processModules(
}

if (changedModule) {
log.debug({ msg: `Files changed for module ${changedModule.name}` })
log.silly({ msg: `Files changed for module ${changedModule.name}` })

await Bluebird.map(changeHandler!(changedModule), (task) => garden.addTask(task))
}
Expand Down
4 changes: 4 additions & 0 deletions garden-service/src/task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export class TaskGraph {

// this.taskDependencyCache will already have been populated at this point (happens in addTaskInternal).
for (const node of taskNodes) {
/**
* We set the list of dependency nodes to the intersection of the set of nodes in this.index with
* the node's task's dependencies (from configuration).
*/
node.clear()
const taskDeps = this.taskDependencyCache[node.getKey()] || new Set()
node.setDependencies(taskNodes.filter(n => taskDeps.has(n.getBaseKey())))
Expand Down
5 changes: 4 additions & 1 deletion garden-service/src/tasks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ export async function getTasksForModule(
const taskTasks = tasks
.map(task => new TaskTask({ garden, log, task, force, forceBuild }))

return [...buildTasks, ...deployTasks, ...taskTasks]
const outputTasks = [...buildTasks, ...deployTasks, ...taskTasks]
log.silly(`getTasksForModule called for module ${module.name}, returning the following tasks:`)
log.silly(` ${outputTasks.map(t => t.getBaseKey()).join(", ")}`)

return outputTasks
}

export async function getHotReloadModuleNames(garden: Garden, hotReloadServiceNames: string[]): Promise<Set<string>> {
Expand Down
5 changes: 4 additions & 1 deletion garden-service/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import { Module } from "./types/module"
import { getIgnorer, scanDirectory } from "./util/util"
import { MODULE_CONFIG_FILENAME } from "./constants"
import { Garden } from "./garden"
import { LogEntry } from "./logger/log-entry"

export type ChangeHandler = (module: Module | null, configChanged: boolean) => Promise<void>

export class FSWatcher {
private watcher

constructor(private garden: Garden) {
constructor(private garden: Garden, private log: LogEntry) {
}

async watchModules(modules: Module[], changeHandler: ChangeHandler) {
Expand Down Expand Up @@ -53,6 +54,8 @@ export class FSWatcher {

return async (filePath: string) => {

this.log.debug("Start of changeHandler")

const filename = basename(filePath)
if (filename === "garden.yml" || filename === ".gitignore" || filename === ".gardenignore") {
await this.invalidateCachedForAll()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
Dockerfile
garden.yml
app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM scratch
ADD . /
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module:
description: Service dependant 2
name: service-dependant2
type: container
services:
- name: service-dependant2
ports:
- name: http
containerPort: 8080
ingresses:
- path: /dependant
port: http
dependencies:
- good-morning
tasks:
- name: dependant-task2
command: [echo, dependant-task2]
dependencies:
- service-dependant2
5 changes: 3 additions & 2 deletions garden-service/test/src/task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe("task-graph", () => {

const garden = await getGarden()
const graph = new TaskGraph(garden, garden.log)
const task = new TestTask(garden, "a", { throwError: true })
const task = new TestTask(garden, "a", false, { throwError: true })

await graph.addTask(task)
const result = await graph.processTasks()
Expand Down Expand Up @@ -217,7 +217,8 @@ describe("task-graph", () => {
const repeatTaskC = new TestTask(garden, "c", true, { ...repeatOpts, dependencies: [repeatTaskB], id: "c2" })

const repeatTaskAforced = new TestTask(garden, "a", true, { ...repeatOpts, dependencies: [], id: "a2f" })
const repeatTaskBforced = new TestTask(garden, "b", true, { ...repeatOpts, dependencies: [repeatTaskA], id: "b2f" })
const repeatTaskBforced = new TestTask(garden, "b", true,
{ ...repeatOpts, dependencies: [repeatTaskA], id: "b2f" })

await graph.addTask(repeatTaskBforced)
await graph.addTask(repeatTaskAforced)
Expand Down
29 changes: 28 additions & 1 deletion garden-service/test/src/tasks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ describe("TaskHelpers", () => {

"deploy.service-dependant",
"task.dependant-task",

"deploy.service-dependant2",
"task.dependant-task2",
].sort(),
withDependencies: [
"build.build-dependency",
Expand All @@ -90,6 +93,11 @@ describe("TaskHelpers", () => {
"push.service-dependant",
"deploy.service-dependant",
"task.dependant-task",

"build.service-dependant2",
"push.service-dependant2",
"deploy.service-dependant2",
"task.dependant-task2",
].sort(),
},
{
Expand All @@ -104,6 +112,9 @@ describe("TaskHelpers", () => {

"deploy.service-dependant",
"task.dependant-task",

"deploy.service-dependant2",
"task.dependant-task2",
].sort(),
withDependencies: [
"build.build-dependency",
Expand All @@ -121,6 +132,11 @@ describe("TaskHelpers", () => {
"push.service-dependant",
"deploy.service-dependant",
"task.dependant-task",

"build.service-dependant2",
"push.service-dependant2",
"deploy.service-dependant2",
"task.dependant-task2",
].sort(),
},
{
Expand Down Expand Up @@ -181,12 +197,23 @@ describe("TaskHelpers", () => {
},
{
moduleName: "good-morning",
withoutDependencies: ["deploy.service-dependant", "task.dependant-task"],
withoutDependencies: [
"deploy.service-dependant",
"task.dependant-task",

"deploy.service-dependant2",
"task.dependant-task2",
].sort(),
withDependencies: [
"build.service-dependant",
"push.service-dependant",
"deploy.service-dependant",
"task.dependant-task",

"build.service-dependant2",
"push.service-dependant2",
"deploy.service-dependant2",
"task.dependant-task2",
].sort(),
},
{
Expand Down

0 comments on commit 99df5d9

Please sign in to comment.