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:
parent
0a07c0e788
commit
24b99aa16b
@ -17,6 +17,7 @@
|
|||||||
package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
package com.alibaba.nacos.api.naming.pojo.healthcheck;
|
||||||
|
|
||||||
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
import com.alibaba.nacos.api.naming.pojo.healthcheck.impl.Tcp;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@ -24,6 +25,11 @@ import static org.junit.Assert.assertTrue;
|
|||||||
|
|
||||||
public class HealthCheckerFactoryTest {
|
public class HealthCheckerFactoryTest {
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void beforeClass() {
|
||||||
|
HealthCheckerFactory.registerSubType(TestChecker.class, TestChecker.TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerialize() {
|
public void testSerialize() {
|
||||||
Tcp tcp = new Tcp();
|
Tcp tcp = new Tcp();
|
||||||
@ -33,7 +39,6 @@ public class HealthCheckerFactoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeExtend() {
|
public void testSerializeExtend() {
|
||||||
HealthCheckerFactory.registerSubType(TestChecker.class, TestChecker.TYPE);
|
|
||||||
TestChecker testChecker = new TestChecker();
|
TestChecker testChecker = new TestChecker();
|
||||||
String actual = HealthCheckerFactory.serialize(testChecker);
|
String actual = HealthCheckerFactory.serialize(testChecker);
|
||||||
assertTrue(actual.contains("\"type\":\"TEST\""));
|
assertTrue(actual.contains("\"type\":\"TEST\""));
|
||||||
|
Loading…
Reference in New Issue
Block a user