Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Clear MockKubernetesApplicationAdapterService.CREATED_DEPLOYMENT_STATES in RequestBrokerKubernetesServiceTest #327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lzx404243
Copy link

@lzx404243 lzx404243 commented May 1, 2021

The test com.vmware.admiral.request.kubernetes.RequestBrokerKubernetesServiceTest.testRequestStateHasK8sInfo is not idempotent and fail if run twice in the same JVM, because it pollutes some states shared among tests. It may be good to clean this state pollution so that some other tests do not fail in the future due to the shared state polluted by this test.

Detail

Running RequestBrokerKubernetesServiceTest.testRequestStateHasK8sInfo twice would result in the second run failing due to the following assertion error:

assertEquals(numberOfDeployments, MockKubernetesApplicationAdapterService.getCreatedDeploymentStates().size());

The root cause is that the staticMockKubernetesApplicationAdapterService.CREATED_DEPLOYMENT_STATES is updated during the first test run, but doesn't get cleared upon test exits.

The suggested fix is to clear the static variable MockKubernetesApplicationAdapterService.CREATED_DEPLOYMENT_STATES in MockKubernetesApplicationAdapterService.clear(), which is already invoked in the setup() function. This will ensure that this static variable is reset before each test is run.

With the proposed fix, the test does not pollute the shared state (and passes when run twice in the same JVM).

@lzx404243
Copy link
Author

Can someone please review this? Any feedback on the changes would be greatly appreciated. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant