Skip to content

Commit fb5f3fa

Browse files
xlorneclaude
andcommitted
fix: 修复 Groovy 元数据策略跨测试类泄漏导致的 CI 失败
GroovyStrategyTest 向全局 GroovyMetadataGenerateStrategyContext 注册的自定义策略 未在结束后清理,测试类执行顺序变化时污染 GroovyScriptControllerTest 的元数据断言。 为两个测试类补充清理逻辑,并将 test.db* 加入 .gitignore 避免 H2 文件库残留。 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 06f55a7 commit fb5f3fa

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ build/
3939
.codegraph/
4040

4141
.flattened-pom.xml
42+
test.db*

springboot-starter-script/src/test/java/com/codingapi/springboot/script/GroovyStrategyTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.codingapi.springboot.script.request.MyScriptRequest;
88
import com.codingapi.springboot.script.strategy.*;
99
import org.apache.groovy.util.Maps;
10+
import org.junit.jupiter.api.AfterEach;
1011
import org.junit.jupiter.api.BeforeEach;
1112
import org.junit.jupiter.api.Test;
1213

@@ -22,6 +23,14 @@ void beforeRun(){
2223
ScriptTypeMappingContext.getInstance().clear();
2324
}
2425

26+
@AfterEach
27+
void afterRun(){
28+
// 避免自定义策略泄漏到其他测试类(跨类共享单例上下文)
29+
GroovyMetadataGenerateStrategyContext.getInstance().clear();
30+
GroovyTypeFixStrategyContext.getInstance().clear();
31+
ScriptTypeMappingContext.getInstance().clear();
32+
}
33+
2534
@Test
2635
void test1(){
2736
String script = "def run(request){return request.count;}";

springboot-starter-script/src/test/java/com/codingapi/springboot/script/controller/GroovyScriptControllerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ void setUp() {
4242
GroovyScriptCacheContext.getInstance().clear();
4343
TempGroovyScriptContext.getInstance().clear();
4444
GroovyScriptRuntimeContext.getInstance().clearCache();
45+
// 防御其他测试类泄漏的全局元数据策略
46+
com.codingapi.springboot.script.strategy.GroovyMetadataGenerateStrategyContext.getInstance().clear();
4547
}
4648

4749
@AfterEach

0 commit comments

Comments
 (0)