Fix an order-dependent flaky test (#4384)

[Problem]
testSerializeExtend add an item to a static mapper,
and testDeserializeExtend read that item from that static mapper.
So if testDeserializeExtend runs before testSerializeExtend,
testDeserializeExtend will fail.

@Ignore testSerializeExtend can stably reproduce this issue.

[Solution]
Add that item to the static mapper in @BeforeClass method
(Even though using static variables in unit tests is a bad practice)
This commit is contained in:
luoos 2020-12-03 20:18:55 -05:00 committed by GitHub
parent 0a07c0e788
commit 24b99aa16b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@
package com.alibaba.nacos.api.naming.pojo.healthcheck;
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@ -24,6 +25,11 @@ import static org.junit.Assert.assertTrue;
public class HealthCheckerFactoryTest {
@BeforeClass
public static void beforeClass() {
HealthCheckerFactory.registerSubType(TestChecker.class, TestChecker.TYPE);
}
@Test
public void testSerialize() {
Tcp tcp = new Tcp();
@ -33,7 +39,6 @@ public class HealthCheckerFactoryTest {
@Test
public void testSerializeExtend() {
HealthCheckerFactory.registerSubType(TestChecker.class, TestChecker.TYPE);
TestChecker testChecker = new TestChecker();
String actual = HealthCheckerFactory.serialize(testChecker);
assertTrue(actual.contains("\"type\":\"TEST\""));