vmware-archive / admiral

Container management solution with an accent on modeling containerized applications and provide placement based on dynamic policy allocation
Other
255 stars 65 forks source link

Clear MockKubernetesAdapterService.requestOnInspect in KubernetesMaintenanceTest #320

Open lzx404243 opened 3 years ago

lzx404243 commented 3 years ago

The test com.vmware.admiral.adapter.kubernetes.KubernetesMaintenanceTest.testAdapterRequestOnPeriodicMaintenance 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 KubernetesMaintenanceTest.testAdapterRequestOnPeriodicMaintenance twice would result in the second run failing due to the following assertion error:

assertEquals(podState.documentSelfLink, MockKubernetesAdapterService.requestOnInspect.resourceReference.getPath());

The root cause is that the staticMockKubernetesAdapterService.requestOnInspect variable is set during the first test run, but doesn't get cleared upon test exits.

The suggested fix is to clear the static variable MockKubernetesAdapterService.requestOnInspect set during the test when the test finishes.

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

lzx404243 commented 3 years ago

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