-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix flaky TestNegativeCases in cometd input (#47698) #47820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
orestisfl
wants to merge
2
commits into
elastic:main
Choose a base branch
from
orestisfl:fix-flaky-TestNegativeCases
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+8
−8
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The test was flaky because workerWg.Done() was called before the final
log statement completed, allowing input.Stop() to return while the
goroutine was still logging to the test's logger.
Fix by reordering defers so workerWg.Done() runs last (must be first
defer due to LIFO ordering).
Also fix goroutine leak in the test itself by removing the unnecessary
goroutine and using a select to check for unexpected events.
Difficult to reproduce, run with:
```sh
GOMAXPROCS=1 go test -run TestNegativeCases -count=2000 -failfast ./x-pack/filebeat/input/cometd
```
```
panic: Log in goroutine after TestNegativeCases has completed: 2025-11-28T16:04:01.738+0100 INFO cometd Input worker has stopped. {"pubsub_channel": "channel_name"}
goroutine 8352 [running]:
testing.(*common).log(0xc0002aa000, {0xc0003e9a40?, 0x65?})
/usr/lib/go/src/testing/testing.go:1030 +0x1ac
testing.(*common).Logf(0xc0002aa000, {0x13f435e?, 0x400?}, {0xc00035ddb0?, 0x0?, 0x2?})
/usr/lib/go/src/testing/testing.go:1191 +0x4f
go.uber.org/zap/zaptest.TestingWriter.Write({{0x75eedea33200?, 0xc0002aa000?}, 0x40?}, {0xc0005e5c00?, 0x66, 0xc0005e5c00?})
/home/orestis/go/pkg/mod/go.uber.org/[email protected]/zaptest/logger.go:146 +0xdb
go.uber.org/zap/zapcore.(*ioCore).Write(0xc000136d80, {0x0, {0xc2428c586bfdd61c, 0xafdaba1f1, 0x1d14dc0}, {0x13f6038, 0x6}, {0x140a066, 0x19}, {0x0, ...}, ...}, ...)
/home/orestis/go/pkg/mod/go.uber.org/[email protected]/zapcore/core.go:99 +0xb5
go.uber.org/zap/zapcore.(*CheckedEntry).Write(0xc000251790, {0x0, 0x0, 0x0})
/home/orestis/go/pkg/mod/go.uber.org/[email protected]/zapcore/entry.go:253 +0x119
go.uber.org/zap.(*SugaredLogger).log(0xc000054a98, 0x0, {0x0?, 0x0?}, {0xc0000d5e18?, 0x1?, 0x1?}, {0x0, 0x0, 0x0})
/home/orestis/go/pkg/mod/go.uber.org/[email protected]/sugar.go:355 +0xec
go.uber.org/zap.(*SugaredLogger).Info(...)
/home/orestis/go/pkg/mod/go.uber.org/[email protected]/sugar.go:155
github.com/elastic/elastic-agent-libs/logp.(*Logger).Info(...)
/home/orestis/go/pkg/mod/github.com/elastic/[email protected]/logp/logger.go:186
github.com/elastic/beats/v7/x-pack/filebeat/input/cometd.(*cometdInput).Run.func1.1()
/home/orestis/src/beats/x-pack/filebeat/input/cometd/input.go:77 +0x56d
created by github.com/elastic/beats/v7/x-pack/filebeat/input/cometd.(*cometdInput).Run.func1 in goroutine 8343
/home/orestis/src/beats/x-pack/filebeat/input/cometd/input.go:41 +0x87
FAIL github.com/elastic/beats/v7/x-pack/filebeat/input/cometd 47.249s
FAIL
```
Closes elastic#47698
Contributor
🤖 GitHub commentsJust comment with:
|
mykola-elastic
approved these changes
Dec 3, 2025
stefans-elastic
approved these changes
Dec 3, 2025
shmsr
approved these changes
Dec 3, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
backport-active-all
Automated backport with mergify to all the active branches
bug
flaky-test
Unstable or unreliable test cases.
skip-changelog
Team:Obs-InfraObs
Label for the Observability Infrastructure Monitoring team
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed commit message
The test was flaky because workerWg.Done() was called before the final log statement completed, allowing input.Stop() to return while the goroutine was still logging to the test's logger.
Fix by reordering defers so workerWg.Done() runs last (must be first defer due to LIFO ordering).
Also fix goroutine leak in the test itself by removing the unnecessary goroutine and using a select to check for unexpected events.
Checklist
I have made corresponding changes to the documentationI have made corresponding change to the default configuration filesstresstest.shscript to run them under stress conditions and race detector to verify their stability.I have added an entry in./changelog/fragmentsusing the changelog tool.How to test this PR locally
Difficult to reproduce, run with:
GOMAXPROCS=1 go test -run TestNegativeCases -count=2000 -failfast ./x-pack/filebeat/input/cometdRelated issues
Log in goroutine after TestNegativeCases has completed#47698