MCPcopy Index your code
hub / github.com/cortexlabs/cortex / TestHandlerSuccessTCP

Function TestHandlerSuccessTCP

pkg/probe/handler_test.go:45–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestHandlerSuccessTCP(t *testing.T) {
46 t.Parallel()
47
48 log := newLogger(t)
49 defer func() { _ = log.Sync() }()
50
51 var userHandler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
52 w.WriteHeader(http.StatusOK)
53 }
54 server := httptest.NewServer(userHandler)
55
56 pb := probe.NewDefaultProbe(server.URL, log)
57 handler := generateHandler(pb)
58
59 r := httptest.NewRequest(http.MethodGet, "http://fake.cortex.dev/healthz", nil)
60 w := httptest.NewRecorder()
61
62 stopper := pb.StartProbing()
63 defer func() {
64 stopper <- struct{}{}
65 }()
66
67 for {
68 if pb.HasRunOnce() {
69 break
70 }
71 time.Sleep(time.Second)
72 }
73
74 handler(w, r)
75
76 require.Equal(t, http.StatusOK, w.Code)
77 require.Equal(t, "healthy", w.Body.String())
78}
79
80func TestHandlerSuccessHTTP(t *testing.T) {
81 t.Parallel()

Callers

nothing calls this directly

Calls 8

NewDefaultProbeFunction · 0.92
generateHandlerFunction · 0.85
handlerFunction · 0.85
StartProbingMethod · 0.80
HasRunOnceMethod · 0.80
EqualMethod · 0.80
newLoggerFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected