fix(test): JsFetchBridgeTest Vertx 资源泄漏修复

将各 @Test 方法中局部创建的 Vertx.vertx() 统一为成员变量,
通过 @Before 创建并初始化,@After 关闭,避免资源泄漏。
This commit is contained in:
yukaidi
2026-05-29 04:06:13 +08:00
parent 88739e8d1a
commit 06416a4e5f

View File

@@ -7,6 +7,8 @@ import cn.qaiu.parser.ParserCreate;
import cn.qaiu.parser.custom.CustomParserConfig; import cn.qaiu.parser.custom.CustomParserConfig;
import cn.qaiu.parser.custom.CustomParserRegistry; import cn.qaiu.parser.custom.CustomParserRegistry;
import io.vertx.core.Vertx; import io.vertx.core.Vertx;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -16,18 +18,29 @@ import org.slf4j.LoggerFactory;
* 测试fetch API和Promise polyfill功能 * 测试fetch API和Promise polyfill功能
*/ */
public class JsFetchBridgeTest { public class JsFetchBridgeTest {
private static final Logger log = LoggerFactory.getLogger(JsFetchBridgeTest.class); private static final Logger log = LoggerFactory.getLogger(JsFetchBridgeTest.class);
private Vertx vertx;
@Before
public void setUp() {
vertx = Vertx.vertx();
WebClientVertxInit.init(vertx);
}
@After
public void tearDown() {
if (vertx != null) {
vertx.close();
}
}
@Test @Test
public void testFetchPolyfillLoaded() { public void testFetchPolyfillLoaded() {
// 初始化Vertx
Vertx vertx = Vertx.vertx();
WebClientVertxInit.init(vertx);
// 清理注册表 // 清理注册表
CustomParserRegistry.clear(); CustomParserRegistry.clear();
// 创建一个简单的解析器配置 // 创建一个简单的解析器配置
String jsCode = """ String jsCode = """
// 测试Promise是否可用 // 测试Promise是否可用
@@ -83,13 +96,9 @@ public class JsFetchBridgeTest {
@Test @Test
public void testPromiseBasicUsage() { public void testPromiseBasicUsage() {
// 初始化Vertx
Vertx vertx = Vertx.vertx();
WebClientVertxInit.init(vertx);
// 清理注册表 // 清理注册表
CustomParserRegistry.clear(); CustomParserRegistry.clear();
String jsCode = """ String jsCode = """
function parse(shareLinkInfo, http, logger) { function parse(shareLinkInfo, http, logger) {
logger.info("测试Promise基本用法"); logger.info("测试Promise基本用法");