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?
Этот коммит содержится в:
родитель
2c7ea98ccf
коммит
7c3a22d289
6 изменённых файлов: 17 добавлений и 17 удалений
|
@ -15,8 +15,7 @@ func TestChan(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := chromectx()
|
ctx := chromectx(t)
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
err = chromedp.Run(ctx,
|
err = chromedp.Run(ctx,
|
||||||
chromedp.Navigate(server.URL+"/run?file=chan.wasm"),
|
chromedp.Navigate(server.URL+"/run?file=chan.wasm"),
|
||||||
|
|
|
@ -15,8 +15,7 @@ func TestEvent(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := chromectx()
|
ctx := chromectx(t)
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
var log1, log2 string
|
var log1, log2 string
|
||||||
err = chromedp.Run(ctx,
|
err = chromedp.Run(ctx,
|
||||||
|
|
|
@ -15,8 +15,7 @@ func TestFmt(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := chromectx()
|
ctx := chromectx(t)
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
var log1 string
|
var log1 string
|
||||||
err = chromedp.Run(ctx,
|
err = chromedp.Run(ctx,
|
||||||
|
|
|
@ -15,8 +15,7 @@ func TestFmtprint(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := chromectx()
|
ctx := chromectx(t)
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
var log1 string
|
var log1 string
|
||||||
err = chromedp.Run(ctx,
|
err = chromedp.Run(ctx,
|
||||||
|
|
|
@ -15,8 +15,7 @@ func TestLog(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := chromectx()
|
ctx := chromectx(t)
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
var log1 string
|
var log1 string
|
||||||
err = chromedp.Run(ctx,
|
err = chromedp.Run(ctx,
|
||||||
|
|
|
@ -32,16 +32,21 @@ func runargs(t *testing.T, args ...string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func chromectx() (context.Context, context.CancelFunc) {
|
func chromectx(t *testing.T) context.Context {
|
||||||
|
|
||||||
var ctx context.Context
|
|
||||||
|
|
||||||
// looks for locally installed Chrome
|
// 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)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
// Wait for browser to be ready.
|
||||||
|
err := chromedp.Run(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to start browser: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
return ctx, cancel
|
ctx, tcancel := context.WithTimeout(ctx, 30*time.Second)
|
||||||
|
t.Cleanup(tcancel)
|
||||||
|
|
||||||
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func startServer(t *testing.T) (string, *httptest.Server) {
|
func startServer(t *testing.T) (string, *httptest.Server) {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче