From 88739e8d1add30d1646cfbe49bf688045a1d8b3c Mon Sep 17 00:00:00 2001 From: yukaidi Date: Fri, 29 May 2026 04:04:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20JsParserTest=20Vertx=20=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=B3=84=E6=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将各 @Test 方法中局部创建的 Vertx.vertx() 统一为成员变量, 通过 @Before 创建并初始化,@After 关闭,避免资源泄漏。 --- .../java/cn/qaiu/parser/JsParserTest.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/parser/src/test/java/cn/qaiu/parser/JsParserTest.java b/parser/src/test/java/cn/qaiu/parser/JsParserTest.java index 88f2a43..c738f90 100644 --- a/parser/src/test/java/cn/qaiu/parser/JsParserTest.java +++ b/parser/src/test/java/cn/qaiu/parser/JsParserTest.java @@ -7,6 +7,8 @@ import cn.qaiu.parser.custom.CustomParserRegistry; import cn.qaiu.parser.customjs.JsParserExecutor; import cn.qaiu.WebClientVertxInit; import io.vertx.core.Vertx; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import java.util.HashMap; @@ -21,15 +23,26 @@ import java.util.Map; */ public class JsParserTest { + private Vertx vertx; + + @Before + public void setUp() { + vertx = Vertx.vertx(); + WebClientVertxInit.init(vertx); + } + + @After + public void tearDown() { + if (vertx != null) { + vertx.close(); + } + } + @Test public void testJsParserRegistration() { // 清理注册表 CustomParserRegistry.clear(); - - // 初始化Vertx - Vertx vertx = Vertx.vertx(); - WebClientVertxInit.init(vertx); - + // 检查是否加载了JavaScript解析器 CustomParserConfig config = CustomParserRegistry.get("demo_js"); assert config != null : "JavaScript解析器未加载"; @@ -43,11 +56,7 @@ public class JsParserTest { public void testJsParserExecution() { // 清理注册表 CustomParserRegistry.clear(); - - // 初始化Vertx - Vertx vertx = Vertx.vertx(); - WebClientVertxInit.init(vertx); - + try { // 创建解析器 IPanTool tool = ParserCreate.fromType("demo_js") @@ -74,11 +83,7 @@ public class JsParserTest { public void testJsParserFileList() { // 清理注册表 CustomParserRegistry.clear(); - - // 初始化Vertx - Vertx vertx = Vertx.vertx(); - WebClientVertxInit.init(vertx); - + try { // 创建解析器 IPanTool tool = ParserCreate.fromType("demo_js") @@ -114,11 +119,7 @@ public class JsParserTest { public void testJsParserById() { // 清理注册表 CustomParserRegistry.clear(); - - // 初始化Vertx - Vertx vertx = Vertx.vertx(); - WebClientVertxInit.init(vertx); - + try { // 创建ShareLinkInfo Map otherParam = new HashMap<>();