-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslow_test.go
42 lines (36 loc) · 926 Bytes
/
slow_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//go:build integration
package hmetrics
import (
"io"
"net/http"
"net/http/httptest"
"os"
"sync/atomic"
"testing"
"time"
)
func TestBasicSending(t *testing.T) {
var receivedAtomic uint64
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
_, _ = io.ReadAll(r.Body)
atomic.AddUint64(&receivedAtomic, 1)
}))
os.Setenv(EnvKeyEndpoint, ts.URL)
SetHTTPTimeout(100 * time.Millisecond)
SetMetricsPostInterval(time.Second)
SetResetFailureBackoffTo(100 * time.Millisecond)
SetMaxFailureBackoff(2 * time.Second)
SetResetFailureBackoffAfter(2 * time.Second)
SetHTTPClient(ts.Client())
Spawn(func(e error) { t.Error(e) })
time.Sleep(3 * time.Second)
received := atomic.LoadUint64(&receivedAtomic)
t.Logf("server received %d requests", received)
if received == 0 {
t.Fail()
}
}