- commit
- dd947e9ce56da82e1e889fa67af89cb36c7a9a15
- parent
- 902e724f8053380a05a2a336b5c1109b47ec5320
- author
- Dami <dami.etoile@gmail.com>
| M | internal/ | 52 | --------------------------- |
| A | internal/ | 58 | ++++++++++++++++++++++++++++++ |
@@ -7,7 +7,6 @@ import (
77 "io"88 "log/slog"99 "maps"10- "net"1110 "net/http"1211 "net/http/httptest"1312 "os"@@ -346,57 +345,6 @@ func TestOTLPFlushesInTheBackground(t *testing.T) {
346345 }347346 }348347 349-func TestOTLPCloseIsBounded(t *testing.T) {350- c := newCollector(t)351- c.delay = 2 * time.Second352- otlpSetup(t, OTLPConfig{Endpoint: c.srv.URL, Timeout: 100 * time.Millisecond})353- begin := time.Now()354- for range 100 {355- Start("sort").End() // never waits on the network356- }357- if d := time.Since(begin); d > 100*time.Millisecond {358- t.Errorf("100 spans took %v", d)359- }360- Close()361- if d := time.Since(begin); d > 1500*time.Millisecond {362- t.Errorf("Close with a stuck collector took %v", d)363- }364-}365-366-// An endpoint that can't be reached (an inherited OTEL_* variable naming367-// a collector that's gone) costs nothing at exit once a send has failed.368-func TestOTLPCloseSkipsADeadEndpoint(t *testing.T) {369- l, err := net.Listen("tcp", "127.0.0.1:0")370- if err != nil {371- t.Fatal(err)372- }373- dead := "http://" + l.Addr().String()374- l.Close() // nothing listens there now375- otlpSetup(t, OTLPConfig{Endpoint: dead, Timeout: 3 * time.Second})376- for range batchSize {377- Start("sort").End()378- }379- deadline := time.Now().Add(5 * time.Second)380- for {381- exp.mu.Lock()382- down := exp.down383- exp.mu.Unlock()384- if down {385- break386- }387- if time.Now().After(deadline) {388- t.Fatal("the failed send was never noticed")389- }390- time.Sleep(10 * time.Millisecond)391- }392- Start("sort").End()393- begin := time.Now()394- Close()395- if d := time.Since(begin); d > 200*time.Millisecond {396- t.Errorf("Close after a failed send took %v", d)397- }398-}399-400348 func TestOTLPOffSendsNothing(t *testing.T) {401349 c := newCollector(t)402350 t.Setenv("OTEL_EXPORTER_OTLP_ENDPOINT", c.srv.URL)@@ -0,0 +1,58 @@
1+package telemetry2+3+import (4+ "net"5+ "testing"6+ "time"7+)8+9+func TestOTLPCloseIsBounded(t *testing.T) {10+ c := newCollector(t)11+ c.delay = 2 * time.Second12+ otlpSetup(t, OTLPConfig{Endpoint: c.srv.URL, Timeout: 100 * time.Millisecond})13+ begin := time.Now()14+ for range 100 {15+ Start("sort").End() // never waits on the network16+ }17+ if d := time.Since(begin); d > 100*time.Millisecond {18+ t.Errorf("100 spans took %v", d)19+ }20+ Close()21+ if d := time.Since(begin); d > 1500*time.Millisecond {22+ t.Errorf("Close with a stuck collector took %v", d)23+ }24+}25+26+// An endpoint that can't be reached (an inherited OTEL_* variable naming27+// a collector that's gone) costs nothing at exit once a send has failed.28+func TestOTLPCloseSkipsADeadEndpoint(t *testing.T) {29+ l, err := net.Listen("tcp", "127.0.0.1:0")30+ if err != nil {31+ t.Fatal(err)32+ }33+ dead := "http://" + l.Addr().String()34+ l.Close() // nothing listens there now35+ otlpSetup(t, OTLPConfig{Endpoint: dead, Timeout: 3 * time.Second})36+ for range batchSize {37+ Start("sort").End()38+ }39+ deadline := time.Now().Add(5 * time.Second)40+ for {41+ exp.mu.Lock()42+ down := exp.down43+ exp.mu.Unlock()44+ if down {45+ break46+ }47+ if time.Now().After(deadline) {48+ t.Fatal("the failed send was never noticed")49+ }50+ time.Sleep(10 * time.Millisecond)51+ }52+ Start("sort").End()53+ begin := time.Now()54+ Close()55+ if d := time.Since(begin); d > 200*time.Millisecond {56+ t.Errorf("Close after a failed send took %v", d)57+ }58+}