elastic / elastic/beats

Fix all tests/components that fail with `panic: Log in goroutine after TestXXX has completed`

Open
#47,527 5 comments 0 reactions 0 assignees View on GitHub
Team:Elastic-Agent-Data-Plane
Dominant language
Go
Stars
12.7k
Forks
5k
Avg merge
2d 15m
Merged PRs (30d)
385

Description

`logptest.NewTestingLogger` uses the `testing.T` passed to it as the logger output, so if any test/component uses the logger after the test has finished, the call will panic like this:
```
panic: Log in goroutine after TestGenerateProcessorList has completed: 2025-11-05T18:46:23.758Z
```

We need to fix all tests/components that fail with this problem.

The currently know failing tests are:
- [ ] [TestGenerateProcessorList](https://github.com/elastic/beats/blob/0e87812a090a6e5634f2361ed153ebbb2f2b7b40/libbeat/publisher/processing/default_test.go#L43). On `main` the panic been mittigaged using a `logp.NewNopLogger`, however the issue is still there. [8.19 BK failure](https://buildkite.com/elastic/beats-libbeat/builds/22868/steps/canvas?sid=019a5537-1fc0-4bfb-8159-14fba7e6503d#019a554e-27e6-43d1-8d05-100be1d8dc14/193-591), [another failure](https://buildkite.com/elastic/beats-libbeat/builds/23136#019a784a-21b5-48b0-b2d2-85e1d5809ebb/192-561)
- [x] [TestRunnerFactoryWithCommonInputSettings](https://github.com/elastic/beats/blob/0e87812a090a6e5634f2361ed153ebbb2f2b7b40/filebeat/channel/runner_test.go#L223) - failing on main.
- [ ] [TestDurationIsAddedToEvent](https://github.com/elastic/beats/blob/c997509ddba73aaebfdae7751a2fb944b756bbfc/metricbeat/mb/module/wrapper_test.go#L208) - failing [on a branch](https://github.com/elastic/beats/actions/runs/19269913266/job/55095245159?pr=47573#step:3:1179).
- [x] [TestNegativeCases](https://github.com/elastic/beats/blob/3b8b99673e633cb4f4240d12d19709b82e9fa6cb/x-pack/filebeat/input/cometd/input.go#L77) - [BK failure](https://buildkite.com/elastic/beats-xpack-filebeat/builds/24331/steps/canvas?sid=019a834c-dcb7-4cf9-ac14-93294f4be867#019a8361-b7a5-4064-938a-0200e34a3865/7-275)
- [x] [TestSimpleInputConfig](https://github.com/elastic/beats/blob/10c60b7/x-pack/libbeat/management/simple_input_config_test.go#L25) - 8.19 branch, [BK failure](https://buildkite.com/elastic/beats-xpack-libbeat/builds/22571#019a9ce8-f576-43d2-9a95-e83c3f40c663/144-559)

Usually running the tests 10 times is enough to catch the flakiness, for example:
```
cd filebeat/channel
go test -count=10 -run=TestRunnerFactoryWithCommonInputSettings .
```

Contributor guide

Open the contributing guide

Research direction

Start with the listed tests in libbeat/publisher/processing/default_test.go, metricbeat/mb/module/wrapper_test.go, and the other linked test locations, then run the affected package tests repeatedly with `go test -count=10`. Trace uses of logptest.NewTestingLogger and the relevant goroutines. Done means the listed failures no longer panic after their tests complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.