Skip to content

test: Close the clients cmd/osgen's generated tests and test helpers construct - #1049

Merged
ryanyuan merged 4 commits into
opensearch-project:mainfrom
sean-:fix-osgen-roundtrip-close
Aug 7, 2026
Merged

test: Close the clients cmd/osgen's generated tests and test helpers construct#1049
ryanyuan merged 4 commits into
opensearch-project:mainfrom
sean-:fix-osgen-roundtrip-close

Conversation

@sean-

@sean- sean- commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Description

cmd/osgen's round-trip test template built a client per subtest and never released it, so each of the 960 subtests across opensearchapi/ and plugins/ left transport goroutines running for the rest of the test binary's life.

opensearchtransport.New starts both background pollers unconditionally:

  • healthCheckRate derives from the server core count and is always positive
  • NodeStatsInterval: 0 means auto-derive, not disabled

opensearch.NewClient adds a node-discovery goroutine on top. The pollers kept requesting the subtest's httptest.Server after the test body returned, which also made Server.Close block on in-flight requests.

opensearch.NewClient is never cached (the refcounted cache serves NewDefaultClient only), so each helper call owns a fresh transport and closing it cannot affect another test. No call site closes the returned client itself.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

The round-trip test template built a client per subtest and never
released it. opensearchtransport.New starts a cluster-health refresher
and a node-stats poller unconditionally (healthCheckRate derives from
the server core count and is always positive; NodeStatsInterval: 0
means auto-derive, not disabled), and opensearch.NewClient adds a
node-discovery goroutine, so every subtest left those goroutines
running for the rest of the test binary's life and kept requesting the
subtest's httptest.Server after the test body returned.

Register a t.Cleanup on the resource owner in both subtests of both
flavors: the wrapped opensearch.Client for plugin packages (the plugin
client type has no Close), the generated client itself for
opensearchapi. The cleanup is registered after the require.NoError
guarding construction, so a failed construction never gets one.

Signed-off-by: Ryan Yuan <ryan.yuan@crowdstrike.com>
Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
Output of `make gen` after the round-trip template change. No
hand edits.

Signed-off-by: Ryan Yuan <ryan.yuan@crowdstrike.com>
Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
The round-trip template was one of four places the generated tests
build a client; the three shared test-helper constructors were left
untouched, so the sweep only reached the subtests.

opensearchtransport.New falls back to context.Background() when
cfg.Context is nil, so plugintest.CreateFailingClient, which passes a
bare opensearch.Config, left its pollers running for the whole test
binary. plugintest.NewClient and osapitest.CreateFailingClient both
inherit t.Context(), so their pollers stopped when the test did, but
neither closed the transport's idle connections.

All three now register a t.Cleanup that closes the client they return.
Together they cover 806 call sites: 313 plugintest.NewClient, 312
plugintest.CreateFailingClient, and 181 osapitest.CreateFailingClient.

opensearch.NewClient is never cached -- the refcounted cache serves
NewDefaultClient only -- so each helper call owns a fresh transport and
closing it cannot affect another test. No call site closes the returned
client itself.

osapitest/helper.go is hand-written and belonged with the earlier
transport-leak work; the fix lands here because that branch missed it.

Signed-off-by: Ryan Yuan <ryan.yuan@crowdstrike.com>
Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
Output of `make gen` after the plugin test-helper template change. No
hand edits. Adds 50 t.Cleanup calls across the 25 generated
plugins/*/internal/*test/helpers_gen.go files.

Signed-off-by: Ryan Yuan <ryan.yuan@crowdstrike.com>
Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
@sean-
sean- requested review from Jakob3xD and ryanyuan as code owners August 7, 2026 06:15
@sean- sean- added bug Something isn't working v5 opensearch-go/v5 labels Aug 7, 2026
@ryanyuan ryanyuan changed the title Close the clients cmd/osgen's generated tests and test helpers construct test: Close the clients cmd/osgen's generated tests and test helpers construct Aug 7, 2026
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.30%. Comparing base (e66ba3a) to head (d10bb1c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1049      +/-   ##
==========================================
- Coverage   61.31%   61.30%   -0.01%     
==========================================
  Files         666      666              
  Lines       59841    59841              
==========================================
- Hits        36689    36687       -2     
- Misses      21245    21247       +2     
  Partials     1907     1907              
Flag Coverage Δ
integration 33.14% <ø> (-0.01%) ⬇️
unit 60.13% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/osgen/emit/frag_plugin.go 73.84% <ø> (ø)
cmd/osgen/emit/frag_roundtrip.go 0.00% <ø> (ø)

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ryanyuan
ryanyuan merged commit a35ae93 into opensearch-project:main Aug 7, 2026
61 checks passed
@sean-
sean- deleted the fix-osgen-roundtrip-close branch August 7, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working v5 opensearch-go/v5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants