fix: fix test case unstable issues (#1412)

Co-authored-by: andrew shan <45474304+andrewshan@users.noreply.github.com>
pull/1413/head
Fishtail 4 months ago committed by GitHub
parent 797b33f47f
commit 6b3f4304c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -21,3 +21,4 @@
- [feat:add Tencent Cloud TSF support.](https://github.com/Tencent/spring-cloud-tencent/pull/1409) - [feat:add Tencent Cloud TSF support.](https://github.com/Tencent/spring-cloud-tencent/pull/1409)
- [feat:support consul config.](https://github.com/Tencent/spring-cloud-tencent/pull/1410) - [feat:support consul config.](https://github.com/Tencent/spring-cloud-tencent/pull/1410)
- [feat:add trace report support.](https://github.com/Tencent/spring-cloud-tencent/pull/1411) - [feat:add trace report support.](https://github.com/Tencent/spring-cloud-tencent/pull/1411)
- [fix: fix lossless test case unstable issues.](https://github.com/Tencent/spring-cloud-tencent/pull/1412)

@ -140,8 +140,8 @@ public class LosslessRegistryAspectTest {
assertThatCode(() -> { assertThatCode(() -> {
assertThat(OkHttpUtil.checkUrl(HOST, LOSSLESS_PORT_1, "/online", Collections.EMPTY_MAP)).isFalse(); assertThat(OkHttpUtil.checkUrl(HOST, LOSSLESS_PORT_1, "/online", Collections.EMPTY_MAP)).isFalse();
}).doesNotThrowAnyException(); }).doesNotThrowAnyException();
// delay register after 5s // delay register after 10s
Thread.sleep(5000); Thread.sleep(10000);
PolarisServiceRegistry registry = context.getBean(PolarisServiceRegistry.class); PolarisServiceRegistry registry = context.getBean(PolarisServiceRegistry.class);
PolarisRegistration registration = context.getBean(PolarisRegistration.class); PolarisRegistration registration = context.getBean(PolarisRegistration.class);

@ -22,6 +22,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import com.tencent.cloud.polaris.context.config.PolarisContextProperties; import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
import com.tencent.polaris.api.config.Configuration;
import com.tencent.polaris.api.control.Destroyable; import com.tencent.polaris.api.control.Destroyable;
import com.tencent.polaris.api.core.ConsumerAPI; import com.tencent.polaris.api.core.ConsumerAPI;
import com.tencent.polaris.api.core.LosslessAPI; import com.tencent.polaris.api.core.LosslessAPI;
@ -229,9 +230,10 @@ public class PolarisSDKContextManager {
} }
} }
// init SDKContext // init SDKContext
serviceSdkContext = SDKContext.initContextByConfig(properties.configuration(serviceModifierList, Configuration configuration = properties.configuration(serviceModifierList,
() -> environment.getProperty("spring.cloud.client.ip-address"), () -> environment.getProperty("spring.cloud.client.ip-address"),
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0))); () -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0));
serviceSdkContext = SDKContext.initContextByConfig(configuration);
serviceSdkContext.init(); serviceSdkContext.init();
// init ProviderAPI // init ProviderAPI
@ -269,7 +271,7 @@ public class PolarisSDKContextManager {
} }
} }
})); }));
LOG.info("create Polaris SDK context successfully. properties: {}, ", properties); LOG.info("create Polaris SDK context successfully. properties: {}, configuration: {}", properties, configuration);
} }
catch (Throwable throwable) { catch (Throwable throwable) {
LOG.error("create Polaris SDK context failed. properties: {}, ", properties, throwable); LOG.error("create Polaris SDK context failed. properties: {}, ", properties, throwable);
@ -289,14 +291,15 @@ public class PolarisSDKContextManager {
if (null == configSDKContext && CollectionUtils.isNotEmpty(configModifierList)) { if (null == configSDKContext && CollectionUtils.isNotEmpty(configModifierList)) {
try { try {
// init config SDKContext // init config SDKContext
configSDKContext = SDKContext.initContextByConfig(properties.configuration(configModifierList, Configuration configuration = properties.configuration(configModifierList,
() -> environment.getProperty("spring.cloud.client.ip-address"), () -> environment.getProperty("spring.cloud.client.ip-address"),
() -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0))); () -> environment.getProperty("spring.cloud.polaris.local-port", Integer.class, 0));
configSDKContext = SDKContext.initContextByConfig(configuration);
configSDKContext.init(); configSDKContext.init();
// add shutdown hook // add shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(PolarisSDKContextManager::innerConfigDestroy)); Runtime.getRuntime().addShutdownHook(new Thread(PolarisSDKContextManager::innerConfigDestroy));
LOG.info("create Polaris config SDK context successfully. properties: {}, ", properties); LOG.info("create Polaris config SDK context successfully. properties: {}, configuration: {}", properties, configuration);
} }
catch (Throwable throwable) { catch (Throwable throwable) {
LOG.error("create Polaris config SDK context failed. properties: {}, ", properties, throwable); LOG.error("create Polaris config SDK context failed. properties: {}, ", properties, throwable);

Loading…
Cancel
Save