-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
engine_test.go
88 lines (75 loc) · 2.03 KB
/
engine_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package core
import (
"errors"
"testing"
"github.com/vercel/turbo/cli/internal/fs"
"github.com/vercel/turbo/cli/internal/graph"
"github.com/vercel/turbo/cli/internal/workspace"
"gotest.tools/v3/assert"
"github.com/pyr-sh/dag"
)
func TestShortCircuiting(t *testing.T) {
var workspaceGraph dag.AcyclicGraph
workspaceGraph.Add("a")
workspaceGraph.Add("b")
workspaceGraph.Add("c")
// Dependencies: a -> b -> c
workspaceGraph.Connect(dag.BasicEdge("a", "b"))
workspaceGraph.Connect(dag.BasicEdge("b", "c"))
buildTask := &fs.BookkeepingTaskDefinition{}
err := buildTask.UnmarshalJSON([]byte("{\"dependsOn\": [\"^build\"]}"))
assert.NilError(t, err, "BookkeepingTaskDefinition unmarshall")
pipeline := map[string]fs.BookkeepingTaskDefinition{
"build": *buildTask,
}
p := NewEngine(&graph.CompleteGraph{
WorkspaceGraph: workspaceGraph,
Pipeline: pipeline,
TaskDefinitions: map[string]*fs.TaskDefinition{},
WorkspaceInfos: workspace.Catalog{
PackageJSONs: map[string]*fs.PackageJSON{
"//": {},
"a": {},
"b": {},
"c": {},
},
TurboConfigs: map[string]*fs.TurboJSON{
"//": {
Pipeline: pipeline,
},
},
},
}, false)
p.AddTask("build")
err = p.Prepare(&EngineBuildingOptions{
Packages: []string{"a", "b", "c"},
TaskNames: []string{"build"},
TasksOnly: false,
})
if err != nil {
t.Fatalf("%v", err)
}
executed := map[string]bool{
"a#build": false,
"b#build": false,
"c#build": false,
}
expectedErr := errors.New("an error occurred")
// b#build is going to error, we expect to not execute a#build, which depends on b
testVisitor := func(taskID string) error {
println(taskID)
executed[taskID] = true
if taskID == "b#build" {
return StopExecution(expectedErr)
}
return nil
}
errs := p.Execute(testVisitor, EngineExecutionOptions{
Concurrency: 10,
})
assert.Equal(t, len(errs), 1)
assert.Equal(t, errs[0], expectedErr)
assert.Equal(t, executed["c#build"], true)
assert.Equal(t, executed["b#build"], true)
assert.Equal(t, executed["a#build"], false)
}