From 85301a9b02d66912f5cb1db7cb8a0ad029edf943 Mon Sep 17 00:00:00 2001 From: Nan Yu Date: Wed, 4 Oct 2023 23:52:15 +0000 Subject: [PATCH] test: tune the retryCap to stabalize the unit test (#920) A 20ms retry cap seems not long enough for the test directories to be created, e.g.: https://oss.gprow.dev/view/gs/oss-prow-build-kpt-config-sync/pr-logs/pull/GoogleContainerTools_kpt-config-sync/918/kpt-config-sync-presubmit/1709704761911021568 1. started calling readHydratedDirWithRetry at 2023-10-04 23:02:16.385300841 2. retryied 6 times whithin 20ms ``` I1004 23:02:16.385422 17534 retry.go:75] failed to load the hydrated configs under /tmp/read-hydrated-dir-test3711104822/hydrated I1004 23:02:16.386681 17534 retry.go:75] failed to load the hydrated configs under /tmp/read-hydrated-dir-test3711104822/hydrated I1004 23:02:16.389097 17534 retry.go:75] failed to load the hydrated configs under /tmp/read-hydrated-dir-test3711104822/hydrated I1004 23:02:16.394563 17534 retry.go:75] failed to load the hydrated configs under /tmp/read-hydrated-dir-test3711104822/hydrated I1004 23:02:16.403944 17534 retry.go:75] failed to load the hydrated configs under /tmp/read-hydrated-dir-test3711104822/hydrated ``` 3. sync directory created 68ms later: sync directory "/tmp/read-hydrated-dir-test3711104822/hydrated/1234567890abcde/configs" created at 2023-10-04 23:02:16.453810924 4. symlink created 69ms later: symlink "/tmp/read-hydrated-dir-test3711104822/hydrated/rev" created and linked to "/tmp/read-hydrated-dir-test3711104822/hydrated/1234567890abcde" at 2023-10-04 23:02:16.454404483 This commit increases the cap from 20ms to 100ms. --- pkg/hydrate/controller_test.go | 10 +++++----- pkg/parse/run_test.go | 2 +- pkg/parse/source_test.go | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/hydrate/controller_test.go b/pkg/hydrate/controller_test.go index 83e1d5e8b5..ab81607a58 100644 --- a/pkg/hydrate/controller_test.go +++ b/pkg/hydrate/controller_test.go @@ -59,7 +59,7 @@ func TestSourceCommitAndDirWithRetry(t *testing.T) { }, { name: "source root directory created within the retry cap", - retryCap: 20 * time.Millisecond, + retryCap: 100 * time.Millisecond, srcRootCreateLatency: 5 * time.Millisecond, expectedSourceCommit: commit, }, @@ -71,26 +71,26 @@ func TestSourceCommitAndDirWithRetry(t *testing.T) { }, { name: "symlink created within the retry cap", - retryCap: 20 * time.Millisecond, + retryCap: 100 * time.Millisecond, symlinkCreateLatency: 5 * time.Millisecond, expectedSourceCommit: commit, }, { name: "error file exists with empty content", - retryCap: 10 * time.Millisecond, + retryCap: 100 * time.Millisecond, errFileExists: true, expectedErrMsg: "is empty. Please check git-sync logs for more info", }, { name: "error file exists with non-empty content", - retryCap: 10 * time.Millisecond, + retryCap: 100 * time.Millisecond, errFileExists: true, errFileContent: "git-sync error", expectedErrMsg: "git-sync error", }, { name: "sync directory doesn't exist", - retryCap: 10 * time.Millisecond, + retryCap: 100 * time.Millisecond, syncDir: "unknown", expectedErrMsg: "failed to evaluate the config directory", }, diff --git a/pkg/parse/run_test.go b/pkg/parse/run_test.go index 4cec68e43f..fa60f7fd1b 100644 --- a/pkg/parse/run_test.go +++ b/pkg/parse/run_test.go @@ -192,7 +192,7 @@ func TestRun(t *testing.T) { { id: "1", name: "source commit directory created within the retry cap", - retryCap: 20 * time.Millisecond, + retryCap: 100 * time.Millisecond, srcRootCreateLatency: 5 * time.Millisecond, needRetry: false, expectedMsg: "Sync Completed", diff --git a/pkg/parse/source_test.go b/pkg/parse/source_test.go index 31b305cdbe..31387ac7b8 100644 --- a/pkg/parse/source_test.go +++ b/pkg/parse/source_test.go @@ -164,20 +164,20 @@ func TestReadHydratedDirWithRetry(t *testing.T) { { name: "symlink created within the retry cap", commit: originCommit, - retryCap: 20 * time.Millisecond, + retryCap: 100 * time.Millisecond, symlinkCreateLatency: 5 * time.Millisecond, expectedCommit: originCommit, }, { name: "error file exists", - retryCap: 10 * time.Millisecond, + retryCap: 100 * time.Millisecond, hydrationErr: `{"code": "1068", "error": "actionable-error"}`, expectedErrMsg: "actionable-error", expectedErrCode: status.ActionableHydrationErrorCode, }, { name: "sync directory doesn't exist", - retryCap: 10 * time.Millisecond, + retryCap: 100 * time.Millisecond, commit: originCommit, syncDir: "unknown", expectedErrMsg: "failed to evaluate symbolic link to the hydrated sync directory",