-
Couldn't load subscription status.
- Fork 32
fix: Integration testing leaked processes on DualCluster #2825
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
Merged
LeelaChacha
merged 7 commits into
kyma-project:main
from
medmes:fix-integration-test-leaked-proc
Oct 21, 2025
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c0a9629
fix Integration testing leaked processes on DualCluster
medmes 4bdc0c3
Merge branch 'main' into fix-integration-test-leaked-proc
medmes b18ee33
Add testing to dual_cluster factory code to verify the leaked process…
medmes 72eb74b
Merge branch 'fix-integration-test-leaked-proc' of github.com:medmes/…
medmes 754cabd
Merge branch 'main' into fix-integration-test-leaked-proc
medmes bbfa650
Added Unit tests for DualClusterFactory
medmes 893ede8
Addressed PR review comment
medmes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
117 changes: 117 additions & 0 deletions
117
tests/integration/commontestutils/skrcontextimpl/dual_cluster_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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| package skrcontextimpl_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "runtime" | ||
| "testing" | ||
|
|
||
| machineryruntime "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/types" | ||
|
|
||
| testskrcontext "github.com/kyma-project/lifecycle-manager/tests/integration/commontestutils/skrcontextimpl" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func newFactory() *testskrcontext.DualClusterFactory { | ||
| scheme := machineryruntime.NewScheme() | ||
| return testskrcontext.NewDualClusterFactory(scheme, nil) | ||
| } | ||
|
|
||
| func Test_GetBeforeInit(t *testing.T) { | ||
| dualFactory := newFactory() | ||
| _, err := dualFactory.Get(types.NamespacedName{Name: "kymaUninitialized"}) | ||
| require.Error(t, err) | ||
| assert.ErrorIs(t, err, testskrcontext.ErrSkrEnvNotStarted) | ||
| } | ||
|
|
||
| func Test_InitAndGet(t *testing.T) { | ||
| dualFactory := newFactory() | ||
| kyma := types.NamespacedName{Name: "kymaInit"} | ||
| require.NoError(t, dualFactory.Init(context.Background(), kyma)) | ||
| skrCtx, err := dualFactory.Get(kyma) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, skrCtx) | ||
| require.NotNil(t, dualFactory.GetSkrEnv()) | ||
| } | ||
|
|
||
| func Test_InitTwiceSameKyma(t *testing.T) { | ||
| dualFactory := newFactory() | ||
| kyma := types.NamespacedName{Name: "kymaSame"} | ||
| require.NoError(t, dualFactory.Init(context.Background(), kyma)) | ||
| envFirst := dualFactory.GetSkrEnv() | ||
| require.NotNil(t, envFirst) | ||
| require.NoError(t, dualFactory.Init(context.Background(), kyma)) | ||
| envSecond := dualFactory.GetSkrEnv() | ||
| assert.Equal(t, envFirst, envSecond) | ||
| } | ||
|
|
||
| func Test_MultipleKymasAndStop(t *testing.T) { | ||
| dualFactory := newFactory() | ||
| kymaPrimary := types.NamespacedName{Name: "kymaPrimary"} | ||
| kymaSecondary := types.NamespacedName{Name: "kymaSecondary"} | ||
|
|
||
| for _, k := range []types.NamespacedName{kymaPrimary, kymaSecondary} { | ||
| require.NoError(t, dualFactory.Init(context.Background(), k)) | ||
| _, err := dualFactory.Get(k) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| require.NoError(t, dualFactory.Stop()) | ||
| assert.Nil(t, dualFactory.GetSkrEnv()) | ||
|
|
||
| _, err := dualFactory.Get(kymaPrimary) | ||
| assert.Error(t, err) | ||
| } | ||
|
|
||
| func Test_StopIdempotent(t *testing.T) { | ||
| dualFactory := newFactory() | ||
| kyma := types.NamespacedName{Name: "kymaLifecycle"} | ||
| require.NoError(t, dualFactory.Init(context.Background(), kyma)) | ||
| require.NoError(t, dualFactory.Stop()) | ||
| require.NoError(t, dualFactory.Stop()) | ||
| } | ||
|
|
||
| func Test_NoLeakedProcesses(t *testing.T) { | ||
| dualFactory := newFactory() | ||
| kyma := types.NamespacedName{Name: "kymaGoroutineCheck"} | ||
|
|
||
| before := runtime.NumGoroutine() | ||
| require.NoError(t, dualFactory.Init(context.Background(), kyma)) | ||
| require.NoError(t, dualFactory.Stop()) | ||
|
|
||
| runtime.GC() | ||
| after := runtime.NumGoroutine() | ||
| assert.LessOrEqual(t, after, before+2) | ||
| } | ||
|
|
||
| type fakeEnv struct { | ||
| name string | ||
| stopCalled bool | ||
| stopErr error | ||
| } | ||
|
|
||
| func (fenv *fakeEnv) Stop() error { | ||
| fenv.stopCalled = true | ||
| return fenv.stopErr | ||
| } | ||
|
|
||
| func Test_StopAggregatesErrors(t *testing.T) { | ||
| dualFactory := newFactory() | ||
|
|
||
| envPrimary := &fakeEnv{name: "primary-env", stopErr: errors.New("primary stop failure")} | ||
| envSecondary := &fakeEnv{name: "secondary-env", stopErr: errors.New("secondary stop failure")} | ||
| envTertiary := &fakeEnv{name: "tertiary-env"} | ||
|
|
||
| dualFactory.StoreEnv("primary-env", envPrimary) | ||
| dualFactory.StoreEnv("secondary-env", envSecondary) | ||
| dualFactory.StoreEnv("tertiary-env", envTertiary) | ||
|
|
||
| err := dualFactory.Stop() | ||
| require.Error(t, err) | ||
| msg := err.Error() | ||
| assert.Contains(t, msg, "primary stop failure") | ||
| assert.Contains(t, msg, "secondary stop failure") | ||
| assert.Nil(t, dualFactory.GetSkrEnv()) | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.