Open
Conversation
Contributor
|
Do we need to run go race condition tests for the unit test; I want to make sure there are no race conditions. Since it is a unit test I doubt we need to manage the parallelism but just want to make sure. |
okankoAMZ
previously approved these changes
Mar 24, 2026
Contributor
|
This PR was marked stale due to lack of activity. |
Contributor
|
This PR was marked stale due to lack of activity. |
# Conflicts: # extension/entitystore/ec2Info_test.go
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description of the issue
CloudWatch Agent unit tests can be further optimized since it currently has unit tests that run from 30 to 180 seconds. Initial deep dive shows that we are using sleep functions to avoid race conditions, there may be ways to reduce this so we can run unit tests even faster.
Current tests take ~3m20s (removed
-failfastdue to broken unit test)Trimmed out anything under 2s
Description of changes
Reduces the test runtime to ~1m40s. Some non-test code changes were made in service of the optimization or to prevent a data race/leak.
Non-Test changes
Bug fixes
certWatcher.go: Addsync.WaitGroupsoStart()waits forWatch()goroutine to exit before returningmetrics_limiter.go: Replace default:time.Sleepbusy-waits with properticker.Cselects, adddefer ticker.Stop()to both GC and rotation goroutinesRefactors
ec2tagger.go: MoveBackoffSleepArrayanddefaultRefreshIntervalfrom package-level vars to struct fields with getter methodscloudwatch.go: ExtractbackoffDuration()frombackoffSleep()for testabilitytarget.go: Extract timing params into struct fields withnewTargetManagerWithTimingconstructorTest changes
Bug fixes
logfile_test.go: Fixwg.Done()called multiple times viasync.Once, preventing paniclogfile_test.go: Fix blacklist test comparing raw filename instead ofgenerateLogGroupName()resultlogthrottle_test.go: Fix data race ontestLoggerslices by addingsync.Mutexentitystoretests (extension_test.go,ec2Info_test.go): Fix data race on logger buffer by introducingsyncBuffer(thread-safebytes.Buffer)tailersrc_test.go: Fix data race on event counter by usingatomic.Int32certWatcher_test.go: Fix data race on callback flag by usingatomic.Boolec2tagger_test.go: Fix data race from package-level variable mutation by using struct field assignmentcertWatcher_test.go: Fix test teardown ordering — uset.Cleanupwithsync.WaitGroupto ensureStart()goroutine exits beforet.TempDir()removes cert filesGeneral Improvements
time.Sleepwithrequire.Eventuallyfor faster, more reliable synchronizationt.Parallel()throughout where safe (cloudwatch, pusher, cardinalitycontrol, entitystore, publisher, ec2tagger, certWatcher, processor)TestBackoffRetriesto callbackoffDuration()directly instead ofbackoffSleep(), eliminating ~45s of real sleepingTestPublishworkload from 250K to 100K metricsTestProcessMetricsWithConcurrencyrandom sleep range from 0–4900ms to 0–9msTestBackupConfigFileper-iteration sleep from 1s to 10ms (16 iterations: 16s → 160ms)TestMain+ shared testdata with per-testt.TempDir()in certWatcher testsLicense
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Tests
Requirements
Before commiting your code, please do the following steps.
make fmtandmake fmt-shmake lintIntegration Tests
To run integration tests against this PR, add the
ready for testinglabel.PR Build: https://github.com/aws/amazon-cloudwatch-agent/actions/runs/23221866759
Build Test Artifacts: https://github.com/aws/amazon-cloudwatch-agent/actions/runs/23216131141
Integration Tests: https://github.com/aws/amazon-cloudwatch-agent/actions/runs/23222042708