Skip to content

fix(ci): 事件集成测试改用具名 Handler,适配 framework 17.3.4 - #285

Merged
xlorne merged 1 commit into
devfrom
fix/ci-event-handler-lambda
Nov 17, 2026
Merged

xlorne merged 1 commit into
devfrom
fix/ci-event-handler-lambda

Conversation

@xlorne

@xlorne xlorne commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

问题

dev 分支 CI 自 86d1e870(chore(deps): 升级 codingapi.framework 至 17.3.4,2026-11-17T01:25)起持续失败,报错都集中在 flow-engine-starter:

SpringFlowEventPublisherIntegrationTest.shouldDispatchAfterCommitInOrderThroughSpringListener:164
  提交后应按推送顺序投递 ==> expected: <[1, 2]> but was: <[]>
SpringFlowEventPublisherIntegrationTest.shouldDispatchImmediatelyWithoutTransaction:199
  expected: <[4]> but was: <[]>
Tests run: 8, Failures: 2

根因

framework 17.3.4 修改了 ApplicationHandlerUtils#getHandlerEventClass:

  • 17.3.3:ResolvableType.forClass(handler.getClass()).as(IHandler.class).getGeneric(0).resolve(),解析不到时返回 null,handler(IEvent) 的过滤条件退化为「订阅所有事件」,Handler 仍会收到事件;
  • 17.3.4:新增 TypeVariable 判断,解析不到直接返回 null,并在过滤时跳过该 Handler 并打印 warning("订阅事件类型无法解析(lambda 或 JDK 动态代理),已跳过"),不再退化。

而 SpringFlowEventPublisherIntegrationTest.TestConfig#recEventHandler() 是以 lambda 形式注册的 IHandler<RecEvent>:

@Bean
public IHandler<RecEvent> recEventHandler() {
    return event -> { ... };   // lambda 的泛型实参无法通过 getClass() 解析
}

于是 17.3.4 下该 Handler 被整体跳过,两个用例断言的外部列表始终为空 → 测试失败。生产代码与示例应用中的 Handler(如 MyFlowRecordUrgeEventHandler)都是具名类,不受影响。

修复

测试中的 Handler 改为具名内部类 RecEventHandler implements IHandler<RecEvent>,并在注释中说明 17.3.4 的类型解析约束,避免后续再以 lambda 注册 Handler。

验证

  • ./mvnw test:BUILD SUCCESS(全部模块通过,含此前失败的 SpringFlowEventPublisherIntegrationTest 3 例);
  • 单独运行 -Dtest=SpringFlowEventPublisherIntegrationTest:Tests run: 3, Failures: 0。

备注

该约束是 framework 17.3.4 的行为变更:使用方若以 lambda / JDK 动态代理实现 IHandler<T>,升级后会收不到事件(仅打印 warning)。建议在升级说明中提示使用者改用具名类或匿名内部类(后者可解析)。

framework 17.3.4 起 ApplicationHandlerUtils 不再把订阅事件类型无法解析的
Handler(lambda / JDK 动态代理)退化为「订阅所有事件」,而是直接跳过并打印
warning。SpringFlowEventPublisherIntegrationTest 中的 lambda 形式 IHandler
因此收不到事件,导致 CI 自 86d1e87(升级 17.3.4)后持续失败。

- 改为具名内部类 RecEventHandler 实现 IHandler<RecEvent>
- 同步在注释中说明该约束,避免后续误用 lambda 注册 Handler
@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.30%. Comparing base (d5376c4) to head (36ab8a8).
⚠️ Report is 17 commits behind head on dev.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev     #285      +/-   ##
============================================
- Coverage     74.32%   74.30%   -0.02%     
- Complexity     1939     2004      +65     
============================================
  Files           262      270       +8     
  Lines          7989     8256     +267     
  Branches        925      981      +56     
============================================
+ Hits           5938     6135     +197     
- Misses         1586     1630      +44     
- Partials        465      491      +26     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xlorne
xlorne merged commit 56e497c into dev Nov 17, 2026
3 checks passed
@xlorne
xlorne deleted the fix/ci-event-handler-lambda branch November 17, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant