Skip to content

Commit a03817f

Browse files
committed
tools/flow: fix test race
The test would sometimes not generate the panic as Value could race. Signed-off-by: Marcel van Lohuizen <mpvl@golang.org> Change-Id: I215cbfec66c21229b8a4a968e141dec1b46ba507 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/535802 Unity-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Paul Jolly <paul@myitcv.io> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
1 parent 583c11e commit a03817f

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

tools/flow/flow_test.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,38 @@ func TestFlowValuePanic(t *testing.T) {
101101
$id: "slow"
102102
out: string
103103
}
104+
b: {
105+
$id: "slow"
106+
$after: a
107+
out: string
108+
}
104109
}
105110
`
106111
ctx := cuecontext.New()
107112
v := ctx.CompileString(f)
108113

109-
start := make(chan bool, 1)
114+
ch := make(chan bool, 1)
115+
116+
cfg := &flow.Config{
117+
Root: cue.ParsePath("root"),
118+
UpdateFunc: func(c *flow.Controller, t *flow.Task) error {
119+
ch <- true
120+
return nil
121+
},
122+
}
110123

111-
cfg := &flow.Config{Root: cue.ParsePath("root")}
112124
c := flow.New(cfg, v, taskFunc)
113125

114126
defer func() { recover() }()
115127

116-
go func() {
117-
start <- true
118-
c.Run(context.TODO())
119-
}()
120-
121-
<-start
128+
go c.Run(context.TODO())
122129

123-
// Wait for the flow to be running
124-
// The task sleeps for 10 Milliseconds
125-
time.Sleep(5 * time.Millisecond)
126-
// Should trigger a panic as the flow is not terminated
130+
// Call Value amidst two task runs. This should trigger a panic as the flow
131+
// is not terminated.
132+
<-ch
127133
c.Value()
134+
<-ch
135+
128136
t.Errorf("Value() did not panic")
129137
}
130138

0 commit comments

Comments
 (0)