mirror of
https://github.com/slhaf/Partner.git
synced 2026-05-12 08:43:02 +08:00
fix(ActionExecutor): support removing phaserRecord correctly when exception occurred in ActionCorrector
This commit is contained in:
@@ -134,10 +134,14 @@ public class ActionExecutor extends AgentRunningSubModule<ActionExecutorInput, V
|
||||
stageCursor.requestAdvance();
|
||||
}
|
||||
|
||||
// 针对行动链进行修正,修正需要传入执行历史、行动目标等内容
|
||||
val correctorInput = assemblyHelper.buildCorrectorInput(actionData, userId);
|
||||
val correctorResult = actionCorrector.execute(correctorInput);
|
||||
actionCapability.handleInterventions(correctorResult.getMetaInterventionList(), actionData);
|
||||
try {
|
||||
// 针对行动链进行修正,修正需要传入执行历史、行动目标等内容
|
||||
// 如果后续运行 corrector 触发频率较高,可考虑增加重试机制
|
||||
val correctorInput = assemblyHelper.buildCorrectorInput(actionData, userId);
|
||||
val correctorResult = actionCorrector.execute(correctorInput);
|
||||
actionCapability.handleInterventions(correctorResult.getMetaInterventionList(), actionData);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// 第二次尝试进行阶段推进,本次负责补充上一次在不存在 stage时,但 corrector 执行期间发生了 actionChain 的插入事件
|
||||
// 如果第一次已经推进完毕,本次将会跳过
|
||||
|
||||
@@ -309,31 +309,36 @@ class ActionExecutorTest {
|
||||
}
|
||||
|
||||
// 场景11:B4.4 异常 -> 资源未清理(已知缺陷)。目的:暴露当前行为。
|
||||
@Disabled("known-issue: corrector 抛异常时未清理 phaser 记录")
|
||||
@Tag("known-issue")
|
||||
// @Disabled("known-issue: corrector 抛异常时未清理 phaser 记录")
|
||||
// @Tag("known-issue")
|
||||
@Test
|
||||
void execute_correctorThrows_shouldLeakPhaserRecord() {
|
||||
ExecutorService directExecutor = new DirectExecutorService();
|
||||
stubExecutors(directExecutor, directExecutor);
|
||||
ExecutorService platformExecutor = Executors.newCachedThreadPool();
|
||||
ExecutorService virtualExecutor = Executors.newCachedThreadPool();
|
||||
stubExecutors(platformExecutor, virtualExecutor);
|
||||
|
||||
ImmediateActionData actionData = buildActionData(singleStageChain(false));
|
||||
ActionExecutorInput input = buildInput("u1", actionData);
|
||||
|
||||
ExtractorResult ok = new ExtractorResult();
|
||||
ok.setOk(true);
|
||||
when(paramsExtractor.execute(any())).thenReturn(ok);
|
||||
doAnswer(inv -> {
|
||||
lenient().when(paramsExtractor.execute(any())).thenReturn(ok);
|
||||
lenient().doAnswer(inv -> {
|
||||
MetaAction metaAction = inv.getArgument(0);
|
||||
metaAction.getResult().setStatus(MetaAction.ResultStatus.SUCCESS);
|
||||
return null;
|
||||
}).when(runnerClient).submit(any(MetaAction.class));
|
||||
|
||||
doThrow(new RuntimeException("boom")).when(actionCorrector).execute(any());
|
||||
lenient().doThrow(new RuntimeException("boom")).when(actionCorrector).execute(any());
|
||||
|
||||
actionExecutor.init();
|
||||
actionExecutor.execute(input);
|
||||
|
||||
verify(actionCapability, never()).removePhaserRecord(any(Phaser.class));
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
verify(actionCapability).removePhaserRecord(any(Phaser.class));
|
||||
}
|
||||
|
||||
// 场景12:B4.1 actionChain 为空导致异常(已知缺陷)。目的:暴露当前行为。
|
||||
|
||||
Reference in New Issue
Block a user