@@ -11,32 +11,22 @@ import (
11
11
"github.com/stretchr/testify/require"
12
12
"net/http"
13
13
"testing"
14
- "time"
15
14
)
16
15
17
16
func TestServer_StartStop (t * testing.T ) {
18
17
// We don't use the helper NewForTests, because we want to control stopping ourselves.
19
18
srv , err := baseserver .New ("server_test" , baseserver .WithHTTPPort (8765 ), baseserver .WithGRPCPort (8766 ))
20
19
require .NoError (t , err )
20
+ baseserver .StartServerForTests (t , srv )
21
21
22
- go func () {
23
- require .NoError (t , srv .ListenAndServe ())
24
- }()
25
-
26
- baseserver .WaitForServerToBeReachable (t , srv , 3 * time .Second )
27
22
require .Equal (t , "http://localhost:8765" , srv .HTTPAddress ())
28
23
require .Equal (t , "localhost:8766" , srv .GRPCAddress ())
29
24
require .NoError (t , srv .Close ())
30
25
}
31
26
32
27
func TestServer_ServesReady (t * testing.T ) {
33
28
srv := baseserver .NewForTests (t )
34
-
35
- go func (t * testing.T ) {
36
- require .NoError (t , srv .ListenAndServe ())
37
- }(t )
38
-
39
- baseserver .WaitForServerToBeReachable (t , srv , 3 * time .Second )
29
+ baseserver .StartServerForTests (t , srv )
40
30
41
31
readyURL := fmt .Sprintf ("%s/ready" , srv .HTTPAddress ())
42
32
resp , err := http .Get (readyURL )
@@ -47,11 +37,7 @@ func TestServer_ServesReady(t *testing.T) {
47
37
func TestServer_ServesMetricsEndpointWithDefaultConfig (t * testing.T ) {
48
38
srv := baseserver .NewForTests (t )
49
39
50
- go func (t * testing.T ) {
51
- require .NoError (t , srv .ListenAndServe ())
52
- }(t )
53
-
54
- baseserver .WaitForServerToBeReachable (t , srv , 3 * time .Second )
40
+ baseserver .StartServerForTests (t , srv )
55
41
56
42
readyUR := fmt .Sprintf ("%s/metrics" , srv .HTTPAddress ())
57
43
resp , err := http .Get (readyUR )
@@ -65,11 +51,7 @@ func TestServer_ServesMetricsEndpointWithCustomMetricsConfig(t *testing.T) {
65
51
baseserver .WithMetricsRegistry (registry ),
66
52
)
67
53
68
- go func (t * testing.T ) {
69
- require .NoError (t , srv .ListenAndServe ())
70
- }(t )
71
-
72
- baseserver .WaitForServerToBeReachable (t , srv , 3 * time .Second )
54
+ baseserver .StartServerForTests (t , srv )
73
55
74
56
readyUR := fmt .Sprintf ("%s/metrics" , srv .HTTPAddress ())
75
57
resp , err := http .Get (readyUR )
0 commit comments