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