Skip to content

Commit 6157fb8

Browse files
committed
shell: deflake TestSourceFileContext
It was cancelling the context after firing the goroutine. If the host machine is busy enough, or if the user is unlucky enough, it could be that the fired goroutine finishes before the parent has cancelled the context. Thus leading to a nil dereference panic as we'd call .Error on a nil error. To fix this, remove the goroutine race condition, and stop assuming that the error will be non-nil.
1 parent 89c5621 commit 6157fb8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

shell/source_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ func TestSourceFileContext(t *testing.T) {
112112
}
113113

114114
ctx, cancel := context.WithCancel(context.Background())
115+
cancel()
115116
errc := make(chan error, 1)
116117
go func() {
117118
_, err := SourceFile(ctx, tf.Name())
118119
errc <- err
119120
}()
120-
cancel()
121121
err = <-errc
122122
want := "context canceled"
123-
if !strings.Contains(err.Error(), want) {
123+
if err == nil || !strings.Contains(err.Error(), want) {
124124
t.Fatalf("error %q does not match %q", err, want)
125125
}
126126
}

0 commit comments

Comments
 (0)