MCPcopy
hub / github.com/grafana/tempo / TestApp_RunStop

Function TestApp_RunStop

cmd/tempo/app/app_test.go:16–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestApp_RunStop(t *testing.T) {
17 tempDir, err := os.MkdirTemp("", "tempo-test-app-*")
18 require.NoError(t, err)
19
20 defer func() {
21 err := os.RemoveAll(tempDir)
22 require.NoError(t, err)
23 }()
24
25 config := NewDefaultConfig()
26 config.Target = BackendScheduler
27 config.Server.HTTPListenPort = util.MustGetFreePort()
28 config.Server.GRPCListenPort = util.MustGetFreePort() // not used in the test; set to ensure conflict-free start
29 config.StorageConfig.Trace.Backend = backend.Local
30 config.StorageConfig.Trace.Local.Path = filepath.Join(tempDir, "tempo")
31 config.StorageConfig.Trace.WAL.Filepath = filepath.Join(tempDir, "wal")
32 config.UsageReport.Enabled = false // speeds up the shutdown process
33
34 app, err := New(*config)
35 require.NoError(t, err)
36
37 // start Tempo
38 go func() {
39 require.NoError(t, app.Run())
40 }()
41
42 // check health endpoint is reachable
43 healthCheckURL := fmt.Sprintf("http://localhost:%d/ready", config.Server.HTTPListenPort)
44 require.Eventually(t, func() bool {
45 t.Log("Checking Tempo is up...")
46 // #nosec G107 -- nosemgrep: tainted-url-host
47 resp, httpErr := http.Get(healthCheckURL)
48 return httpErr == nil && resp.StatusCode == http.StatusOK
49 }, 30*time.Second, 1*time.Second)
50
51 // stop Tempo
52 app.Stop()
53
54 // check health endpoint is not reachable anymore
55 require.Eventually(t, func() bool {
56 t.Log("Checking Tempo is down...")
57 // #nosec G107 -- nosemgrep: tainted-url-host
58 _, httpErr := http.Get(healthCheckURL)
59 return httpErr != nil
60 }, 60*time.Second, 1*time.Second)
61}

Callers

nothing calls this directly

Calls 8

MustGetFreePortFunction · 0.92
NewDefaultConfigFunction · 0.85
NewFunction · 0.70
JoinMethod · 0.65
LogMethod · 0.65
GetMethod · 0.65
StopMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected