mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-19 12:04:03 +00:00
tests: de-flake goroutines test
This commit is contained in:
@@ -424,10 +424,12 @@ func optionsFromOSARCH(osarch string, sema chan struct{}) compileopts.Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runTest(name string, options compileopts.Options, t *testing.T, cmdArgs, environmentVars []string) {
|
func runTest(name string, options compileopts.Options, t *testing.T, cmdArgs, environmentVars []string) {
|
||||||
|
t.Helper()
|
||||||
runTestWithConfig(name, t, options, cmdArgs, environmentVars)
|
runTestWithConfig(name, t, options, cmdArgs, environmentVars)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTestWithConfig(name string, t *testing.T, options compileopts.Options, cmdArgs, environmentVars []string) {
|
func runTestWithConfig(name string, t *testing.T, options compileopts.Options, cmdArgs, environmentVars []string) {
|
||||||
|
t.Helper()
|
||||||
// Get the expected output for this test.
|
// Get the expected output for this test.
|
||||||
// Note: not using filepath.Join as it strips the path separator at the end
|
// Note: not using filepath.Join as it strips the path separator at the end
|
||||||
// of the path.
|
// of the path.
|
||||||
@@ -876,6 +878,7 @@ func TestWasmExit(t *testing.T) {
|
|||||||
|
|
||||||
// Check whether the output of a test equals the expected output.
|
// Check whether the output of a test equals the expected output.
|
||||||
func checkOutput(t *testing.T, filename string, actual []byte) {
|
func checkOutput(t *testing.T, filename string, actual []byte) {
|
||||||
|
t.Helper()
|
||||||
expectedOutput, err := os.ReadFile(filename)
|
expectedOutput, err := os.ReadFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("could not read output file:", err)
|
t.Fatal("could not read output file:", err)
|
||||||
@@ -884,6 +887,7 @@ func checkOutput(t *testing.T, filename string, actual []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkOutputData(t *testing.T, expectedOutput, actual []byte) {
|
func checkOutputData(t *testing.T, expectedOutput, actual []byte) {
|
||||||
|
t.Helper()
|
||||||
expectedOutput = bytes.ReplaceAll(expectedOutput, []byte("\r\n"), []byte("\n"))
|
expectedOutput = bytes.ReplaceAll(expectedOutput, []byte("\r\n"), []byte("\n"))
|
||||||
actual = bytes.ReplaceAll(actual, []byte("\r\n"), []byte("\n"))
|
actual = bytes.ReplaceAll(actual, []byte("\r\n"), []byte("\n"))
|
||||||
|
|
||||||
|
|||||||
Vendored
+4
@@ -175,10 +175,13 @@ func testGoOnBuiltins() {
|
|||||||
|
|
||||||
var once sync.Once
|
var once sync.Once
|
||||||
|
|
||||||
|
var waitChan = make(chan struct{})
|
||||||
|
|
||||||
func testGoOnInterface(f Itf) {
|
func testGoOnInterface(f Itf) {
|
||||||
go f.Nowait()
|
go f.Nowait()
|
||||||
time.Sleep(time.Millisecond)
|
time.Sleep(time.Millisecond)
|
||||||
go f.Wait()
|
go f.Wait()
|
||||||
|
<-waitChan
|
||||||
time.Sleep(time.Millisecond * 2)
|
time.Sleep(time.Millisecond * 2)
|
||||||
println("done with 'go on interface'")
|
println("done with 'go on interface'")
|
||||||
}
|
}
|
||||||
@@ -204,6 +207,7 @@ func (f Foo) Nowait() {
|
|||||||
|
|
||||||
func (f Foo) Wait() {
|
func (f Foo) Wait() {
|
||||||
println("called: Foo.Wait")
|
println("called: Foo.Wait")
|
||||||
|
close(waitChan)
|
||||||
time.Sleep(time.Microsecond)
|
time.Sleep(time.Microsecond)
|
||||||
println(" ...waited")
|
println(" ...waited")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user