Skip to content

Commit 42567f2

Browse files
authored
test(TestMetadataFetcher): wait for invalidation channel to be closed (elastic#17259)
avoid goroutine leak
1 parent 9b880fd commit 42567f2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

internal/sourcemap/metadata_fetcher_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func TestMetadataFetcher(t *testing.T) {
128128

129129
exporter := &manualExporter{}
130130
tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sdktrace.NewSimpleSpanProcessor(exporter)))
131-
fetcher, _ := NewMetadataFetcher(ctx, esClient, ".apm-source-map", tp, logptest.NewTestingLogger(t, ""))
131+
fetcher, invalidationChan := NewMetadataFetcher(ctx, esClient, ".apm-source-map", tp, logptest.NewTestingLogger(t, ""))
132132

133133
<-fetcher.ready()
134134
if tc.expectErr {
@@ -144,6 +144,12 @@ func TestMetadataFetcher(t *testing.T) {
144144
tp.ForceFlush(ctx)
145145

146146
assert.Greater(t, len(exporter.spans), 1)
147+
148+
cancel()
149+
// wait for invalidationChan to be closed so
150+
// the background goroutine created by NewMetadataFetcher is done
151+
for range invalidationChan {
152+
}
147153
})
148154
}
149155
}

0 commit comments

Comments
 (0)