Skip to content

Conversation

@l-qing
Copy link
Member

@l-qing l-qing commented Aug 16, 2025

  • Add proper cleanup mechanism for the ticker goroutine in UpdateCACertToClusterInterceptorCRD
  • Return a stop function to allow graceful shutdown of the background goroutine
  • Update caller to use the returned stop function and handle the return value
  • Add defer statement in test to ensure proper cleanup

Changes

Fix test instability in UpdateCACertToClusterInterceptorCRD unit test

This PR addresses test instability issues in the Test_UpdateCACertToClusterInterceptorCRD unit test by improving resource cleanup in the tested function.

panic: Log in goroutine after Test_UpdateCACertToClusterInterceptorCRD has completed: 2025-08-13T02:15:36.599Z	ERROR	failed to fetch secret secret "testsecrets" not found

goroutine 26 [running]:
testing.(*common).logDepth(0xc00098e700, {0xc00055d920, 0x54}, 0x3)
	/target/usr/local/go/src/testing/testing.go:1064 +0x4b4
testing.(*common).log(...)
	/target/usr/local/go/src/testing/testing.go:1046
testing.(*common).Logf(0xc00098e700, {0x2e5f996?, 0x400?}, {0xc000487570?, 0x2?, 0x1?})
	/target/usr/local/go/src/testing/testing.go:1097 +0x54
go.uber.org/zap/zaptest.TestingWriter.Write({{0x325fbb0?, 0xc00098e700?}, 0xc0?}, {0xc0001f2c00?, 0x55, 0xc0001f2c00?})
	/workspace/source/upstream/vendor/go.uber.org/zap/zaptest/logger.go:146 +0xdb
go.uber.org/zap/zapcore.(*ioCore).Write(0xc000593d40, {0x2, {0xc21f1b3223b5b9a1, 0x4b06b72d6, 0x4f8a160}, {0x0, 0x0}, {0xc00054db40, 0x35}, {0x0, ...}, ...}, ...)
	/workspace/source/upstream/vendor/go.uber.org/zap/zapcore/core.go:99 +0xb5
go.uber.org/zap/zapcore.(*CheckedEntry).Write(0xc00037f1e0, {0x0, 0x0, 0x0})
	/workspace/source/upstream/vendor/go.uber.org/zap/zapcore/entry.go:253 +0x119
go.uber.org/zap.(*SugaredLogger).log(0xc000800ae0, 0x2, {0x2e83532?, 0x19?}, {0xc000729fc0?, 0x1?, 0x1?}, {0x0, 0x0, 0x0})
	/workspace/source/upstream/vendor/go.uber.org/zap/sugar.go:355 +0xec
go.uber.org/zap.(*SugaredLogger).Errorf(...)
	/workspace/source/upstream/vendor/go.uber.org/zap/sugar.go:216
github.com/tektoncd/triggers/pkg/interceptors/server.UpdateCACertToClusterInterceptorCRD.func1()
	/workspace/source/upstream/pkg/interceptors/server/server.go:335 +0x25b
created by github.com/tektoncd/triggers/pkg/interceptors/server.UpdateCACertToClusterInterceptorCRD in goroutine 25
	/workspace/source/upstream/pkg/interceptors/server/server.go:330 +0x13b

FAIL	github.com/tektoncd/triggers/pkg/interceptors/server	20.154s

Problem:

  • The unit test was occasionally failing due to improper resource cleanup
  • Background goroutines and tickers from the UpdateCACertToClusterInterceptorCRD function weren't being properly stopped after test completion
  • This caused test interference and flaky test results

Solution:

  • Modified UpdateCACertToClusterInterceptorCRD to return a cleanup function
  • Added proper goroutine termination mechanism using a done channel and select statement
  • Ensured ticker is properly stopped with defer ticker.Stop()
  • Updated the test to call the cleanup function, ensuring proper test isolation

Submitter Checklist

As the author of this PR, please check off the items in this checklist:

  • Has Docs if any changes are user facing, including updates to minimum requirements e.g. Kubernetes version bumps
  • Has Tests included if any functionality added or changed
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add one by adding a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings). See some examples of good release notes.
  • Release notes contains the string "action required" if the change requires additional action from users switching to the new release

Release Notes

NONE

/kind flake

- Add proper cleanup mechanism for the ticker goroutine in UpdateCACertToClusterInterceptorCRD
- Return a stop function to allow graceful shutdown of the background goroutine
- Update caller to use the returned stop function and handle the return value
- Add defer statement in test to ensure proper cleanup
@tekton-robot tekton-robot added kind/flake Categorizes issue or PR as related to a flakey test release-note-none Denotes a PR that doesnt merit a release note. labels Aug 16, 2025
@tekton-robot tekton-robot requested review from iancoffey and khrm August 16, 2025 03:44
@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 16, 2025
@tekton-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-tekton-triggers-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/interceptors/server/server.go Do not exist 81.5%

@khrm
Copy link
Contributor

khrm commented Oct 10, 2025

/retest

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: savitaashture

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 6, 2025
@savitaashture savitaashture reopened this Nov 6, 2025
Copy link
Contributor

@savitaashture savitaashture left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 6, 2025
@tekton-robot tekton-robot merged commit 70eaf7e into tektoncd:main Nov 6, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/flake Categorizes issue or PR as related to a flakey test lgtm Indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesnt merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants