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).
This commit is contained in:
Ayke van Laethem
2021-11-20 01:06:02 +01:00
committed by Ron Evans
parent 470cbd5f53
commit 1d2c17753a
6 changed files with 16 additions and 37 deletions
+6 -7
View File
@@ -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
}