MCPcopy
hub / github.com/tsenart/vegeta / TestTimeout

Function TestTimeout

lib/attack_test.go:112–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

110}
111
112func TestTimeout(t *testing.T) {
113 t.Parallel()
114 server := httptest.NewServer(
115 http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
116 <-time.After(20 * time.Millisecond)
117 }),
118 )
119 defer server.Close()
120 atk := NewAttacker(Timeout(10 * time.Millisecond))
121 tr := NewStaticTargeter(Target{Method: "GET", URL: server.URL})
122 res := atk.hit(tr, &attack{name: "", began: time.Now()})
123
124 want := "Client.Timeout exceeded while awaiting headers"
125 if got := res.Error; !strings.Contains(got, want) {
126 t.Fatalf("want: '%v' in '%v'", want, got)
127 }
128
129 if res.Latency == 0 {
130 t.Fatal("Latency wasn't captured with a timed-out result")
131 }
132}
133
134func TestLocalAddr(t *testing.T) {
135 t.Parallel()

Callers

nothing calls this directly

Calls 5

hitMethod · 0.95
NewAttackerFunction · 0.85
TimeoutFunction · 0.85
NewStaticTargeterFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected