diff options
author | Nia Waldvogel <[email protected]> | 2022-01-18 12:17:43 -0500 |
---|---|---|
committer | Ron Evans <[email protected]> | 2022-01-18 19:29:29 +0100 |
commit | 7c3a22d289492dd5366b8e41133d9f0e1c323a7c (patch) | |
tree | 4aa6faed4c70b6b7b1ede7410d0cafcde6258045 /tests | |
parent | 2c7ea98ccf6f747f4b5abf2a5bb6c052f72aff7f (diff) | |
download | tinygo-7c3a22d289492dd5366b8e41133d9f0e1c323a7c.tar.gz tinygo-7c3a22d289492dd5366b8e41133d9f0e1c323a7c.zip |
wasmtest: fix resource cleanup and add logging
The chromedp context was not cancelled, so resources may have been leaking.
Additionally this waits for the browser to start before the timer starts, and extends the timeout to 20 seconds.
Logging from chromedp has also been enabled, which may help identify possible issues?
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wasm/chan_test.go | 3 | ||||
-rw-r--r-- | tests/wasm/event_test.go | 3 | ||||
-rw-r--r-- | tests/wasm/fmt_test.go | 3 | ||||
-rw-r--r-- | tests/wasm/fmtprint_test.go | 3 | ||||
-rw-r--r-- | tests/wasm/log_test.go | 3 | ||||
-rw-r--r-- | tests/wasm/setup_test.go | 19 |
6 files changed, 17 insertions, 17 deletions
diff --git a/tests/wasm/chan_test.go b/tests/wasm/chan_test.go index fe981974c..c22410f63 100644 --- a/tests/wasm/chan_test.go +++ b/tests/wasm/chan_test.go @@ -15,8 +15,7 @@ func TestChan(t *testing.T) { t.Fatal(err) } - ctx, cancel := chromectx() - defer cancel() + ctx := chromectx(t) err = chromedp.Run(ctx, chromedp.Navigate(server.URL+"/run?file=chan.wasm"), diff --git a/tests/wasm/event_test.go b/tests/wasm/event_test.go index a29a01c7e..5dabc707c 100644 --- a/tests/wasm/event_test.go +++ b/tests/wasm/event_test.go @@ -15,8 +15,7 @@ func TestEvent(t *testing.T) { t.Fatal(err) } - ctx, cancel := chromectx() - defer cancel() + ctx := chromectx(t) var log1, log2 string err = chromedp.Run(ctx, diff --git a/tests/wasm/fmt_test.go b/tests/wasm/fmt_test.go index d3695f072..cb88e36db 100644 --- a/tests/wasm/fmt_test.go +++ b/tests/wasm/fmt_test.go @@ -15,8 +15,7 @@ func TestFmt(t *testing.T) { t.Fatal(err) } - ctx, cancel := chromectx() - defer cancel() + ctx := chromectx(t) var log1 string err = chromedp.Run(ctx, diff --git a/tests/wasm/fmtprint_test.go b/tests/wasm/fmtprint_test.go index 3c7502399..ec83c77ff 100644 --- a/tests/wasm/fmtprint_test.go +++ b/tests/wasm/fmtprint_test.go @@ -15,8 +15,7 @@ func TestFmtprint(t *testing.T) { t.Fatal(err) } - ctx, cancel := chromectx() - defer cancel() + ctx := chromectx(t) var log1 string err = chromedp.Run(ctx, diff --git a/tests/wasm/log_test.go b/tests/wasm/log_test.go index 1f6c79fe9..ac747431a 100644 --- a/tests/wasm/log_test.go +++ b/tests/wasm/log_test.go @@ -15,8 +15,7 @@ func TestLog(t *testing.T) { t.Fatal(err) } - ctx, cancel := chromectx() - defer cancel() + ctx := chromectx(t) var log1 string err = chromedp.Run(ctx, diff --git a/tests/wasm/setup_test.go b/tests/wasm/setup_test.go index e5a18daf7..b56b6f336 100644 --- a/tests/wasm/setup_test.go +++ b/tests/wasm/setup_test.go @@ -32,16 +32,21 @@ func runargs(t *testing.T, args ...string) error { return nil } -func chromectx() (context.Context, context.CancelFunc) { - - var ctx context.Context - +func chromectx(t *testing.T) context.Context { // looks for locally installed Chrome - ctx, _ = chromedp.NewContext(context.Background()) + ctx, ccancel := chromedp.NewContext(context.Background(), chromedp.WithErrorf(t.Errorf), chromedp.WithDebugf(t.Logf), chromedp.WithLogf(t.Logf)) + t.Cleanup(ccancel) + + // Wait for browser to be ready. + err := chromedp.Run(ctx) + if err != nil { + t.Fatalf("failed to start browser: %s", err.Error()) + } - ctx, cancel := context.WithTimeout(ctx, 10*time.Second) + ctx, tcancel := context.WithTimeout(ctx, 30*time.Second) + t.Cleanup(tcancel) - return ctx, cancel + return ctx } func startServer(t *testing.T) (string, *httptest.Server) { |