-
Notifications
You must be signed in to change notification settings - Fork 174
K8SPSMDB-1571: Make reconciliation interval configurable #2221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,14 @@ package perconaservermongodb | |
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "testing" | ||
| "time" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
|
|
@@ -13,6 +18,67 @@ import ( | |
| psmdbv1 "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1" | ||
| ) | ||
|
|
||
| func TestGetReconcileInterval(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| envValue string | ||
| setEnv bool | ||
| want time.Duration | ||
| }{ | ||
| { | ||
| name: "unset", | ||
| setEnv: false, | ||
| want: 5 * time.Second, | ||
| }, | ||
| { | ||
| name: "valid duration", | ||
| envValue: "30s", | ||
| setEnv: true, | ||
| want: 30 * time.Second, | ||
| }, | ||
| { | ||
| name: "invalid duration falls back to default", | ||
| envValue: "invalid", | ||
| setEnv: true, | ||
| want: 5 * time.Second, | ||
| }, | ||
| { | ||
| name: "zero duration falls back to default", | ||
| envValue: "0s", | ||
| setEnv: true, | ||
| want: 5 * time.Second, | ||
| }, | ||
| { | ||
| name: "negative duration falls back to default", | ||
| envValue: "-5s", | ||
| setEnv: true, | ||
| want: 5 * time.Second, | ||
| }, | ||
| { | ||
| name: "duration less than 5s falls back to default", | ||
| envValue: "1s", | ||
| setEnv: true, | ||
| want: 5 * time.Second, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| defer func() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all this logic is not needed, we can simply unsert the env after the end of each test. We can do something like that: Which is also handling the errors of setting and unsetting, wdyt? |
||
| err := os.Unsetenv("RECONCILE_INTERVAL") | ||
| require.NoError(t, err) | ||
| }() | ||
| if tt.setEnv { | ||
| err := os.Setenv("RECONCILE_INTERVAL", tt.envValue) | ||
| require.NoError(t, err) | ||
|
Comment on lines
+67
to
+73
|
||
| } | ||
|
|
||
| got := getReconcileInterval() | ||
| assert.Equal(t, tt.want, got) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| var _ = Describe("PerconaServerMongoDB", Ordered, func() { | ||
| ctx := context.Background() | ||
| const ns = "psmdb" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it makes sense to have a value 1second for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, i agree. maybe it's better to not allow values less than 5 seconds and fallback to 5 seconds if value is smaller