Skip to content

Conversation

@nammn
Copy link
Collaborator

@nammn nammn commented Dec 29, 2025

Summary

Why

  • Unit tests were slow due to actual time.Sleep() calls and HTTP retry delays, causing unnecessary wait times during test execution.
  • Using Synctest to speed up slow unit tests (which were relying on sleeps and go scheduler scheduling)
  • test changed and speedup:

What

  • Adopted Go testing/synctest to eliminate real-time waits in time-based tests (PVC resize, StatefulSet deletion)
  • Configured HTTP clients in tests to retry immediately instead of waiting seconds between attempts
  • Fixed CI to only create Python venv for Python tests, not Go tests
Test Before After
TestReconcilePVCResizeShardedCluster 3.06s 0.03s
TestReconcilePVCResizeMultiCluster 3.06s 0.05s
TestHandlePVCResize 1.00s 0.00s
TestIsMemberClusterHealthy 3.00s 0.00s
TestRetriesOnWritingAutomationConfig 3.00s 0.05s

Proof of Work

  • passing unit tests

Checklist

  • Have you linked a jira ticket and/or is the ticket in the title?
  • Have you checked whether your jira ticket required DOCSP changes?
  • Have you added changelog file?

@nammn nammn added the skip-changelog Use this label in Pull Request to not require new changelog entry file label Dec 29, 2025
}

func checkStatefulsetIsDeleted(ctx context.Context, memberClient kubernetesClient.Client, desiredSts *appsv1.StatefulSet, sleepDuration time.Duration, log *zap.SugaredLogger) bool {
func checkStatefulsetIsDeleted(ctx context.Context, memberClient kubernetesClient.Client, desiredSts *appsv1.StatefulSet, sleepDuration time.Duration, log *zap.SugaredLogger) (bool, int) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

returning retries makes testing easier

@github-actions
Copy link

⚠️ (this preview might not be accurate if the PR is not rebased on current master branch)

MCK 1.6.2 Release Notes

Bug Fixes

  • Fixed an issue where monitoring agents would fail after disabling TLS on a MongoDB deployment.
  • Persistent Volume Claim resize fix: Fixed an issue where the Operator ignored namespaces when listing PVCs, causing conflicts with resizing PVCs of the same name. Now, PVCs are filtered by both name and namespace for accurate resizing.


func TestReconcilePVCResizeMultiCluster(t *testing.T) {
ctx := context.Background()
synctest.Test(t, func(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

noop, just wrapping synctest

@nammn nammn changed the title optimize unit test speed Speed up unit tests with Go 1.23 synctest and optimized retry delays Dec 29, 2025
@nammn nammn changed the title Speed up unit tests with Go 1.23 synctest and optimized retry delays Speed up unit tests with synctest and optimized retry delays Dec 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Use this label in Pull Request to not require new changelog entry file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants