The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/pkg/server/module_server_test.go

71 lines
1.7 KiB

package server
import (
"context"
"errors"
"net/http"
"testing"
"time"
"github.com/grafana/grafana/pkg/api"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/modules"
"github.com/grafana/grafana/pkg/tests/testsuite"
"github.com/stretchr/testify/require"
)
func TestMain(m *testing.M) {
testsuite.Run(m)
}
func TestIntegrationWillRunInstrumentationServerWhenTargetHasNoHttpServer(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if db.IsTestDbSQLite() {
t.Skip("sqlite is not supported by the storage server target")
}
_, cfg := db.InitTestDBWithCfg(t)
cfg.HTTPPort = "3001"
cfg.GRPCServer.Network = "tcp"
cfg.GRPCServer.Address = "localhost:10000"
cfg.Target = []string{modules.StorageServer}
ms, err := InitializeModuleServer(cfg, Options{}, api.ServerOptions{})
require.NoError(t, err)
errChan := make(chan error, 1)
go func() {
time.Sleep(1 * time.Second)
errChan <- ms.Run()
}()
require.Eventually(t, func() bool {
client := http.Client{
Timeout: 1 * time.Second,
}
res, err := client.Get("http://localhost:3001/metrics")
if err != nil {
return false
}
defer func() {
if err := res.Body.Close(); err != nil {
t.Fatalf("failed to close response body: %v", err)
}
}()
return res.StatusCode == http.StatusOK
}, 10*time.Second, 1*time.Second)
err = ms.Shutdown(context.Background(), "test over")
require.NoError(t, err)
select {
case err := <-errChan:
if err != nil && !errors.Is(err, context.Canceled) {
t.Fatalf("unexpected error from module server: %v", err)
}
case <-time.After(10 * time.Second):
t.Fatal("timeout waiting for module server to shut down")
}
}