tools: Exit run-cts when the coverage page is closed

Change-Id: I70f3ffa40dcfe60cdee46bdf0f5db21370be1a3e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113861
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-12-13 15:56:39 +00:00 committed by Dawn LUCI CQ
parent 408ace6927
commit 97b05e169e
2 changed files with 16 additions and 1 deletions

View File

@ -30,6 +30,8 @@ import (
// StartServer starts a localhost http server to display the coverage data.
// Calls started() when the server is started, and then blocks until the context is cancelled.
func StartServer(ctx context.Context, port int, covData []byte, started func() error) error {
ctx, stop := context.WithCancel(ctx)
url := fmt.Sprintf("http://localhost:%v/index.html", port)
handler := http.NewServeMux()
handler.HandleFunc("/index.html", func(w http.ResponseWriter, r *http.Request) {
@ -65,6 +67,9 @@ func StartServer(ctx context.Context, port int, covData []byte, started func() e
defer f.Close()
io.Copy(w, f)
})
handler.HandleFunc("/viewer.closed", func(w http.ResponseWriter, r *http.Request) {
stop()
})
server := &http.Server{Addr: fmt.Sprint(":", port), Handler: handler}
go server.ListenAndServe()
@ -74,5 +79,11 @@ func StartServer(ctx context.Context, port int, covData []byte, started func() e
}
<-ctx.Done()
return server.Shutdown(ctx)
err := server.Shutdown(ctx)
switch err {
case nil, context.Canceled:
return nil
default:
return err
}
}

View File

@ -262,6 +262,10 @@
readOnly: true,
});
addEventListener('beforeunload', () => {
fetch("viewer.closed");
});
window.onload = function () {
el_source.doc.setValue("// Loading... ");
fetch("coverage.dat").then(response =>