Server: Implement timeout waiting for server to shut down (#33333)
* tests: Undo cleanup in goroutine Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Server: Implement timeout waiting for it to shut down Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package testinfra
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
@@ -9,6 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/fs"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
@@ -25,6 +27,8 @@ import (
|
||||
func StartGrafana(t *testing.T, grafDir, cfgPath string, sqlStore *sqlstore.SQLStore) string {
|
||||
t.Helper()
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
origSQLStore := registry.GetService(sqlstore.ServiceName)
|
||||
t.Cleanup(func() {
|
||||
registry.Register(origSQLStore)
|
||||
@@ -58,7 +62,11 @@ func StartGrafana(t *testing.T, grafDir, cfgPath string, sqlStore *sqlstore.SQLS
|
||||
}
|
||||
}()
|
||||
t.Cleanup(func() {
|
||||
go server.Shutdown("test cleanup")
|
||||
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
||||
defer cancel()
|
||||
if err := server.Shutdown(ctx, "test cleanup"); err != nil {
|
||||
t.Error("Timed out waiting on server to shut down")
|
||||
}
|
||||
})
|
||||
|
||||
// Wait for Grafana to be ready
|
||||
|
||||
Reference in New Issue
Block a user