Skip to content

Commit

Permalink
Only block on chan if non-nil
Browse files Browse the repository at this point in the history
  • Loading branch information
crobert-1 committed Feb 1, 2024
1 parent f62a49c commit a84c4e6
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions exporter/splunkhecexporter/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ func (c *capturingData) ServeHTTP(w http.ResponseWriter, r *http.Request) {
panic(err)
}
go func() {
c.receivedRequest <- receivedRequest{body, r.Header}
if c.receivedRequest != nil {
c.receivedRequest <- receivedRequest{body, r.Header}
}
}()
w.WriteHeader(c.statusCode)
}
Expand Down Expand Up @@ -236,8 +238,6 @@ func runMetricsExport(cfg *Config, metrics pmetric.Metrics, expectedBatchesNum i
assert.NoError(t, err)
assert.NoError(t, exporter.Start(context.Background(), componenttest.NewNopHost()))
defer func() {
// Read from channel so that the goroutine running the send operation can exit successfully
_ = <-capture.receivedRequest
assert.NoError(t, exporter.Shutdown(context.Background()))
}()

Expand Down Expand Up @@ -1268,7 +1268,7 @@ func Test_PushMetricsData_Summary_NaN_Sum(t *testing.T) {
func TestReceiveMetricsWithCompression(t *testing.T) {
cfg := NewFactory().CreateDefaultConfig().(*Config)
cfg.MaxContentLengthMetrics = 1800
request, err := runMetricsExport(cfg, createMetricsData(1, 100), 1, false, t)
request, err := runMetricsExport(cfg, createMetricsData(1, 100), 2, false, t)
assert.NoError(t, err)
assert.Equal(t, "gzip", request[0].headers.Get("Content-Encoding"))
assert.NotEqual(t, "", request)
Expand Down Expand Up @@ -1365,8 +1365,7 @@ func TestInvalidURL(t *testing.T) {
}

func TestHeartbeatStartupFailed(t *testing.T) {
rr := make(chan receivedRequest)
capture := capturingData{receivedRequest: rr, statusCode: 403}
capture := capturingData{statusCode: 403}
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(err)
Expand Down Expand Up @@ -1398,8 +1397,6 @@ func TestHeartbeatStartupFailed(t *testing.T) {
assert.NoError(t, err)
// The exporter's name is "" while generating default params
assert.EqualError(t, exporter.Start(context.Background(), componenttest.NewNopHost()), ": heartbeat on startup failed: HTTP 403 \"Forbidden\"")
// Read from channel so that the goroutine running the send operation can exit successfully
_ = <-capture.receivedRequest
assert.NoError(t, exporter.Shutdown(context.Background()))
}

Expand Down Expand Up @@ -1440,8 +1437,7 @@ func TestHeartbeatStartupPass_Disabled(t *testing.T) {
}

func TestHeartbeatStartupPass(t *testing.T) {
rr := make(chan receivedRequest)
capture := capturingData{receivedRequest: rr, statusCode: 200}
capture := capturingData{statusCode: 200}
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(err)
Expand Down Expand Up @@ -1472,8 +1468,6 @@ func TestHeartbeatStartupPass(t *testing.T) {
exporter, err := factory.CreateTracesExporter(context.Background(), params, cfg)
assert.NoError(t, err)
assert.NoError(t, exporter.Start(context.Background(), componenttest.NewNopHost()))
// Read from channel so that the goroutine running the send operation can exit successfully
_ = <-capture.receivedRequest
assert.NoError(t, exporter.Shutdown(context.Background()))
}

Expand Down

0 comments on commit a84c4e6

Please sign in to comment.