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 Serial Deps #177

Merged
merged 1 commit into from
Sep 21, 2018
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
4 changes: 2 additions & 2 deletions mg/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func SerialDeps(fns ...interface{}) {
types := checkFns(fns)
ctx := context.Background()
for i := range fns {
runDeps(ctx, types[i:i], fns[i:i])
runDeps(ctx, types[i:i+1], fns[i:i+1])
}
}

Expand All @@ -68,7 +68,7 @@ func SerialDeps(fns ...interface{}) {
func SerialCtxDeps(ctx context.Context, fns ...interface{}) {
types := checkFns(fns)
for i := range fns {
runDeps(ctx, types[i:i], fns[i:i])
runDeps(ctx, types[i:i+1], fns[i:i+1])
}
}

Expand Down
22 changes: 22 additions & 0 deletions mg/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ func TestDepsOfDeps(t *testing.T) {
}
}

func TestSerialDeps(t *testing.T) {
ch := make(chan string, 3)
// this->f->g->h
h := func() {
ch <- "h"
}
g := func() {
ch <- "g"
}
f := func() {
SerialDeps(g, h)
ch <- "f"
}
Deps(f)

res := <-ch + <-ch + <-ch

if res != "ghf" {
t.Fatal("expected g then h then f to run, but got " + res)
}
}

func TestDepError(t *testing.T) {
// TODO: this test is ugly and relies on implementation details. It should
// be recreated as a full-stack test.
Expand Down