Skip to content

Commit 1b5d312

Browse files
eliasnaurdeadprogram
authored andcommitted
tests: de-flake goroutines test
1 parent 435ddc5 commit 1b5d312

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,12 @@ func optionsFromOSARCH(osarch string, sema chan struct{}) compileopts.Options {
424424
}
425425

426426
func runTest(name string, options compileopts.Options, t *testing.T, cmdArgs, environmentVars []string) {
427+
t.Helper()
427428
runTestWithConfig(name, t, options, cmdArgs, environmentVars)
428429
}
429430

430431
func runTestWithConfig(name string, t *testing.T, options compileopts.Options, cmdArgs, environmentVars []string) {
432+
t.Helper()
431433
// Get the expected output for this test.
432434
// Note: not using filepath.Join as it strips the path separator at the end
433435
// of the path.
@@ -876,6 +878,7 @@ func TestWasmExit(t *testing.T) {
876878

877879
// Check whether the output of a test equals the expected output.
878880
func checkOutput(t *testing.T, filename string, actual []byte) {
881+
t.Helper()
879882
expectedOutput, err := os.ReadFile(filename)
880883
if err != nil {
881884
t.Fatal("could not read output file:", err)
@@ -884,6 +887,7 @@ func checkOutput(t *testing.T, filename string, actual []byte) {
884887
}
885888

886889
func checkOutputData(t *testing.T, expectedOutput, actual []byte) {
890+
t.Helper()
887891
expectedOutput = bytes.ReplaceAll(expectedOutput, []byte("\r\n"), []byte("\n"))
888892
actual = bytes.ReplaceAll(actual, []byte("\r\n"), []byte("\n"))
889893

testdata/goroutines.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,13 @@ func testGoOnBuiltins() {
175175

176176
var once sync.Once
177177

178+
var waitChan = make(chan struct{})
179+
178180
func testGoOnInterface(f Itf) {
179181
go f.Nowait()
180182
time.Sleep(time.Millisecond)
181183
go f.Wait()
184+
<-waitChan
182185
time.Sleep(time.Millisecond * 2)
183186
println("done with 'go on interface'")
184187
}
@@ -204,6 +207,7 @@ func (f Foo) Nowait() {
204207

205208
func (f Foo) Wait() {
206209
println("called: Foo.Wait")
210+
close(waitChan)
207211
time.Sleep(time.Microsecond)
208212
println(" ...waited")
209213
}

0 commit comments

Comments
 (0)