test(kuberuntime): deflake TestRecordOperation

Avoid using hard-coded port

Signed-off-by: knight42 <anonymousknight96@gmail.com>
This commit is contained in:
knight42 2020-09-05 13:36:20 +08:00
parent 0f466ba177
commit c6f9b402fb
No known key found for this signature in database
GPG Key ID: 1040B69865E7D86C

View File

@ -34,17 +34,16 @@ func TestRecordOperation(t *testing.T) {
legacyregistry.MustRegister(metrics.RuntimeOperationsDuration) legacyregistry.MustRegister(metrics.RuntimeOperationsDuration)
legacyregistry.MustRegister(metrics.RuntimeOperationsErrors) legacyregistry.MustRegister(metrics.RuntimeOperationsErrors)
temporalServer := "127.0.0.1:1234" l, err := net.Listen("tcp", "127.0.0.1:0")
l, err := net.Listen("tcp", temporalServer)
assert.NoError(t, err) assert.NoError(t, err)
defer l.Close() defer l.Close()
prometheusURL := "http://" + temporalServer + "/metrics" prometheusURL := "http://" + l.Addr().String() + "/metrics"
mux := http.NewServeMux() mux := http.NewServeMux()
//lint:ignore SA1019 ignore deprecated warning until we move off of global registries //lint:ignore SA1019 ignore deprecated warning until we move off of global registries
mux.Handle("/metrics", legacyregistry.Handler()) mux.Handle("/metrics", legacyregistry.Handler())
server := &http.Server{ server := &http.Server{
Addr: temporalServer, Addr: l.Addr().String(),
Handler: mux, Handler: mux,
} }
go func() { go func() {