Skip to content

Commit

Permalink
[service] Ensure test service eventually connects to telemetry port o…
Browse files Browse the repository at this point in the history
…n restart (open-telemetry#7893)

There appears to be a flake in waiting for resources being released
within tests:

```
    service_test.go:345: 
        	Error Trace:	/home/runner/work/opentelemetry-collector/opentelemetry-collector/service/service_test.go:345
        	Error:      	Received unexpected error:
        	            	Get "http://localhost:8888/metrics": dial tcp [::1]:8888: connect: connection refused
        	Test:       	TestServiceTelemetryRestart
```
See test run:
https://github.com/open-telemetry/opentelemetry-collector/actions/runs/5267677421/jobs/9523273917?pr=7703
  • Loading branch information
MovieStoreGuy authored Jun 14, 2023
1 parent 9b803b4 commit 13242c3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,20 @@ func TestServiceTelemetryRestart(t *testing.T) {
require.NoError(t, srvTwo.Start(context.Background()))

// check telemetry server to ensure we get a response
// #nosec G107
resp, err = http.Get(telemetryURL)
assert.NoError(t, err)
require.Eventually(t,
func() bool {
// #nosec G107
resp, err = http.Get(telemetryURL)
return err == nil
},
500*time.Millisecond,
100*time.Millisecond,
"Must get a valid response from the service",
)
assert.Equal(t, http.StatusOK, resp.StatusCode)

// Shutdown the new service
require.NoError(t, srvTwo.Shutdown(context.Background()))
assert.NoError(t, srvTwo.Shutdown(context.Background()))
}

func assertResourceLabels(t *testing.T, res pcommon.Resource, expectedLabels map[string]labelValue) {
Expand Down

0 comments on commit 13242c3

Please sign in to comment.