aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-11-20 01:06:02 +0100
committerRon Evans <[email protected]>2021-11-21 12:17:34 +0100
commit1d2c17753a9a7353a5ef753de7b002d5e625a6d3 (patch)
tree71bc457ba410fb0e844438b80c937a4af3854e78 /tests
parent470cbd5f53070c10a0f920ae9a82f9a0e4f75a9d (diff)
downloadtinygo-1d2c17753a9a7353a5ef753de7b002d5e625a6d3.tar.gz
tinygo-1d2c17753a9a7353a5ef753de7b002d5e625a6d3.zip
tests: improve wasm tests slightly
These wasm tests weren't passing in GitHub Actions and also weren't passing on my laptop. I'm not sure why, I think there are a few race conditions that are going on. This commit attempts to fix this at least to a degree: - The context deadline is increased from 5 seconds to 10 seconds. - The tests are not running in parallel anymore. - Some `Sleep` calls were removed, they do not appear to be necessary (and if they were, sleeping is the wrong solution to solve race conditions). Overall the tests are taking a few seconds more, but on the other hand they seem to be passing more reliable. At least for me, on my laptop (and hopefully also in CI).
Diffstat (limited to 'tests')
-rw-r--r--tests/wasm/chan_test.go7
-rw-r--r--tests/wasm/event_test.go9
-rw-r--r--tests/wasm/fmt_test.go8
-rw-r--r--tests/wasm/fmtprint_test.go8
-rw-r--r--tests/wasm/log_test.go8
-rw-r--r--tests/wasm/setup_test.go13
6 files changed, 16 insertions, 37 deletions
diff --git a/tests/wasm/chan_test.go b/tests/wasm/chan_test.go
index e44d7ebe4..fe981974c 100644
--- a/tests/wasm/chan_test.go
+++ b/tests/wasm/chan_test.go
@@ -2,23 +2,20 @@ package wasm
import (
"testing"
- "time"
"github.com/chromedp/chromedp"
)
func TestChan(t *testing.T) {
- t.Parallel()
-
wasmTmpDir, server := startServer(t)
- err := run("tinygo build -o " + wasmTmpDir + "/chan.wasm -target wasm testdata/chan.go")
+ err := run(t, "tinygo build -o "+wasmTmpDir+"/chan.wasm -target wasm testdata/chan.go")
if err != nil {
t.Fatal(err)
}
- ctx, cancel := chromectx(5 * time.Second)
+ ctx, cancel := chromectx()
defer cancel()
err = chromedp.Run(ctx,
diff --git a/tests/wasm/event_test.go b/tests/wasm/event_test.go
index 038a500a3..a29a01c7e 100644
--- a/tests/wasm/event_test.go
+++ b/tests/wasm/event_test.go
@@ -2,35 +2,30 @@ package wasm
import (
"testing"
- "time"
"github.com/chromedp/chromedp"
)
func TestEvent(t *testing.T) {
- t.Parallel()
-
wasmTmpDir, server := startServer(t)
- err := run("tinygo build -o " + wasmTmpDir + "/event.wasm -target wasm testdata/event.go")
+ err := run(t, "tinygo build -o "+wasmTmpDir+"/event.wasm -target wasm testdata/event.go")
if err != nil {
t.Fatal(err)
}
- ctx, cancel := chromectx(5 * time.Second)
+ ctx, cancel := chromectx()
defer cancel()
var log1, log2 string
err = chromedp.Run(ctx,
chromedp.Navigate(server.URL+"/run?file=event.wasm"),
chromedp.WaitVisible("#log"),
- chromedp.Sleep(time.Second),
chromedp.InnerHTML("#log", &log1),
waitLog(`1
4`),
chromedp.Click("#testbtn"),
- chromedp.Sleep(time.Second),
chromedp.InnerHTML("#log", &log2),
waitLog(`1
4
diff --git a/tests/wasm/fmt_test.go b/tests/wasm/fmt_test.go
index f9f2f77b1..d3695f072 100644
--- a/tests/wasm/fmt_test.go
+++ b/tests/wasm/fmt_test.go
@@ -2,29 +2,25 @@ package wasm
import (
"testing"
- "time"
"github.com/chromedp/chromedp"
)
func TestFmt(t *testing.T) {
- t.Parallel()
-
wasmTmpDir, server := startServer(t)
- err := run("tinygo build -o " + wasmTmpDir + "/fmt.wasm -target wasm testdata/fmt.go")
+ err := run(t, "tinygo build -o "+wasmTmpDir+"/fmt.wasm -target wasm testdata/fmt.go")
if err != nil {
t.Fatal(err)
}
- ctx, cancel := chromectx(5 * time.Second)
+ ctx, cancel := chromectx()
defer cancel()
var log1 string
err = chromedp.Run(ctx,
chromedp.Navigate(server.URL+"/run?file=fmt.wasm"),
- chromedp.Sleep(time.Second),
chromedp.InnerHTML("#log", &log1),
waitLog(`did not panic`),
)
diff --git a/tests/wasm/fmtprint_test.go b/tests/wasm/fmtprint_test.go
index 90825ba08..3c7502399 100644
--- a/tests/wasm/fmtprint_test.go
+++ b/tests/wasm/fmtprint_test.go
@@ -2,29 +2,25 @@ package wasm
import (
"testing"
- "time"
"github.com/chromedp/chromedp"
)
func TestFmtprint(t *testing.T) {
- t.Parallel()
-
wasmTmpDir, server := startServer(t)
- err := run("tinygo build -o " + wasmTmpDir + "/fmtprint.wasm -target wasm testdata/fmtprint.go")
+ err := run(t, "tinygo build -o "+wasmTmpDir+"/fmtprint.wasm -target wasm testdata/fmtprint.go")
if err != nil {
t.Fatal(err)
}
- ctx, cancel := chromectx(5 * time.Second)
+ ctx, cancel := chromectx()
defer cancel()
var log1 string
err = chromedp.Run(ctx,
chromedp.Navigate(server.URL+"/run?file=fmtprint.wasm"),
- chromedp.Sleep(time.Second),
chromedp.InnerHTML("#log", &log1),
waitLog(`test from fmtprint 1
test from fmtprint 2
diff --git a/tests/wasm/log_test.go b/tests/wasm/log_test.go
index fae4c670b..1f6c79fe9 100644
--- a/tests/wasm/log_test.go
+++ b/tests/wasm/log_test.go
@@ -2,29 +2,25 @@ package wasm
import (
"testing"
- "time"
"github.com/chromedp/chromedp"
)
func TestLog(t *testing.T) {
- t.Parallel()
-
wasmTmpDir, server := startServer(t)
- err := run("tinygo build -o " + wasmTmpDir + "/log.wasm -target wasm testdata/log.go")
+ err := run(t, "tinygo build -o "+wasmTmpDir+"/log.wasm -target wasm testdata/log.go")
if err != nil {
t.Fatal(err)
}
- ctx, cancel := chromectx(5 * time.Second)
+ ctx, cancel := chromectx()
defer cancel()
var log1 string
err = chromedp.Run(ctx,
chromedp.Navigate(server.URL+"/run?file=log.wasm"),
- chromedp.Sleep(time.Second),
chromedp.InnerHTML("#log", &log1),
waitLogRe(`^..../../.. ..:..:.. log 1
..../../.. ..:..:.. log 2
diff --git a/tests/wasm/setup_test.go b/tests/wasm/setup_test.go
index 0071076c2..e5a18daf7 100644
--- a/tests/wasm/setup_test.go
+++ b/tests/wasm/setup_test.go
@@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
- "log"
"net/http"
"net/http/httptest"
"os/exec"
@@ -18,29 +17,29 @@ import (
"github.com/chromedp/chromedp"
)
-func run(cmdline string) error {
+func run(t *testing.T, cmdline string) error {
args := strings.Fields(cmdline)
- return runargs(args...)
+ return runargs(t, args...)
}
-func runargs(args ...string) error {
+func runargs(t *testing.T, args ...string) error {
cmd := exec.Command(args[0], args[1:]...)
b, err := cmd.CombinedOutput()
- log.Printf("Command: %s; err=%v; full output:\n%s", strings.Join(args, " "), err, b)
+ t.Logf("Command: %s; err=%v; full output:\n%s", strings.Join(args, " "), err, b)
if err != nil {
return err
}
return nil
}
-func chromectx(timeout time.Duration) (context.Context, context.CancelFunc) {
+func chromectx() (context.Context, context.CancelFunc) {
var ctx context.Context
// looks for locally installed Chrome
ctx, _ = chromedp.NewContext(context.Background())
- ctx, cancel := context.WithTimeout(ctx, timeout)
+ ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
return ctx, cancel
}