Skip to content

Commit

Permalink
tools/flow: fix test race
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mpvl committed Apr 5, 2022
1 parent 583c11e commit a03817f
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions tools/flow/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,38 @@ func TestFlowValuePanic(t *testing.T) {
$id: "slow"
out: string
}
b: {
$id: "slow"
$after: a
out: string
}
}
`
ctx := cuecontext.New()
v := ctx.CompileString(f)

start := make(chan bool, 1)
ch := make(chan bool, 1)

cfg := &flow.Config{
Root: cue.ParsePath("root"),
UpdateFunc: func(c *flow.Controller, t *flow.Task) error {
ch <- true
return nil
},
}

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

defer func() { recover() }()

go func() {
start <- true
c.Run(context.TODO())
}()

<-start
go c.Run(context.TODO())

// Wait for the flow to be running
// The task sleeps for 10 Milliseconds
time.Sleep(5 * time.Millisecond)
// Should trigger a panic as the flow is not terminated
// Call Value amidst two task runs. This should trigger a panic as the flow
// is not terminated.
<-ch
c.Value()
<-ch

t.Errorf("Value() did not panic")
}

Expand Down

0 comments on commit a03817f

Please sign in to comment.