Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
import com.opentest.dashboard.api.pipeline.SinkProcessor;
import com.opentest.dashboard.api.pipeline.StartControlProcessor;
import com.opentest.dashboard.api.pipeline.StopControlProcessor;
import com.opentest.dashboard.api.pipeline.Processor;
import com.opentest.dashboard.api.channel.ChannelMetadata;
import com.opentest.dashboard.standard.result.PersistResultSinkProcessor;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -196,6 +200,46 @@ public void execute(ExecutionPreparation preparation,Map<Class<?>,Object> servic
}
}

/** B020004: an FS spectrum frame reached a saved Vrms target and stopped the pipeline while the WAV still had input. */
@Test void multiFrameReplayFailureReportsTheProcessorFailureThatStoppedInput() throws Exception {
var row = channel(); row.setVchId("Ch1"); row.setSamplingRate(192000); row.setBitDepth(32); row.setVp(2.8D);
var channel = MeasureProviderInputs.channel(row);
var wav = directory.resolve("Ch1.wav");
var samples = new double[192000 * 10];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 低 测试在内存中生成 192 万个 double(约 15 MB),并写出约 7.7 MB 的 32 位 WAV。但失败发生在第一个 2048 点窗口,即第一帧内。复现“失败后回放源继续送帧”只需要几帧。建议把时长缩短到例如 0.5 秒(约 10 帧),并相应调整 InputClock 和 timeline 时长,以减少单元测试的耗时和磁盘占用。采样率和位深可以保留,以贴近生产条件。

for (int index = 0; index < samples.length; index++) samples[index] = .5 * Math.sin(2 * Math.PI * 1000 * index / 192000D);
try (var writer = new WavWriter(directory.toString(), wav.getFileName().toString(), false)) {
writer.appendData(new WavData(wav.getFileName().toString(), samples, 192000, 32, 2.8D, 1D));
}
var target = new ResultRequirement(101L, "FFT Spectrum", "hash", Map.of(), "Ch1", "Hz", "Vrms");
var plan = new RecordedMeasurementReplayPlan("test:replay", Map.of(), ExecutionInputPurpose.RECORDED_STREAM,
new ExecutionOutputs(1, 2, 3, List.of(channel), List.of(target), List.of()),
Map.of(new MeasurementResultMemberFacts.Key(101, "Ch1"), mock(MeasurementResultMemberFacts.Fact.class)),
List.of(new RecordedMeasurementReplayPlan.InputClock(channel, 0, 0, (long) samples.length)));
var plugins = mock(PluginMeasureExecutor.class);
when(plugins.bindMeasurement(anyString(), anyMap(), anyMap(), any(), any(), any())).thenReturn(new BoundMeasurementExecution() {
@Override public String configurationVersion() { return "1"; }
@Override public Map<Class<?>, Object> pipelineCapabilities() { return Map.of(); }
@Override public void execute(ExecutionPreparation preparation, Map<Class<?>, Object> services) throws Exception {
var prepared = preparation.prepare();
prepared.compile(outputs -> spectrumPipeline(outputs.channels()));
prepared.ready();
prepared.run();
}
});
var pressure = new ReplayPressureController(4, 64L * 1024 * 1024);
var timeline = new DashboardWavTimelineReader(List.of(new DashboardWavSource(row,
FileSystems.getFileSystem("local:///"), List.of(wav.toString()))), 10_000D, List.of("Ch1"));
RuntimeException failure;
try (var session = new RecordedMeasurementReplaySession(plan, plugins, new DashboardWavReplayRunner(), Map.of(),
frame -> { throw new AssertionError("An FS frame must not reach the Vrms target"); }, curves -> { },
CompletableFuture.completedFuture(null))) {
failure = assertThrows(RuntimeException.class, () -> session.run(timeline, new DashboardReplayCancellationToken(),
pressure, new ReplayWriteTracker(pressure), null));
}
assertTrue(failure.getMessage().contains("no unique saved result target"), failure::toString);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 中 当前两条断言不能确定地验证本次修复路径:

  • 如果会话从管线 completion() 直接抛出包装后的原始失败(例如 CompletionException(IllegalArgumentException)),消息中也含 “no unique saved result target”,getCause() 也是 IllegalArgumentException,测试同样通过。
  • 回放源能否在管线停止后再次调用 accept,取决于失败传播与送帧的时序。修复前测试失败依赖的是本地时序,不是确定条件。

建议补充断言,锁定异常确实来自拒收路径,例如:

var rejected = assertInstanceOf(IllegalStateException.class, failure);
assertTrue(rejected.getMessage().startsWith("ProcessorPipeline no longer accepts input"));

如果会话会再包装一层,就沿 cause 链定位。也可以在 ProcessorErrorPolicyContractTest 已覆盖确定性语义的前提下,把本测试定位为端到端回归,并在注释中说明它不保证走拒收路径。

assertInstanceOf(IllegalArgumentException.class, failure.getCause());
}

private static PluginMeasureExecutor provider(List<FrameFact> facts, AtomicBoolean resourceClosed,
AtomicReference<CompletionStage<Void>> packageReleased) {
return provider(facts,resourceClosed,packageReleased,services -> { });
Expand Down Expand Up @@ -242,6 +286,35 @@ private static ProcessorPipelineBuilder pipeline(List<FrameFact> facts,boolean w
return builder;
}

/** Emits one FS spectrum per 2048 samples, as the ordinary FFT processor does, into the standard result sink. */
private static ProcessorPipelineBuilder spectrumPipeline(List<ChannelMetadata> channels) {
var spectrum = new Processor<ChannelFrame, ResultFrame>() {
private final double[] window = new double[2048];
private int used;
@Override public void onFrame(ChannelFrame frame) {
for (double sample : frame.samples()) {
window[used++] = sample;
if (used < window.length) continue;
used = 0;
var output = ResultFrame.explicitX("FFT Spectrum", "hash", "Ch1", "Hz", "FS",
new double[] {0, 93.75}, new double[] {window[0], window[1]}, 0D, null);
try { context().emit(output.withDashboardResultId(101L)); } finally { output.release(); }
}
}
};
var persist = new PersistResultSinkProcessor(1, 2, 3, channels);
return ProcessorPipelineBuilder.create()
.startControl(new StartControlProcessor() {
@Override public void onFrame(ChannelFrame frame) { context().emit(frame.retain()); }
}, 2, QueueOverflowPolicy.WAIT_FOR_CAPACITY)
.stopControl(new StopControlProcessor() {
@Override public void onFrame(ChannelFrame frame) { context().emit(frame.retain()); }
}, 2, QueueOverflowPolicy.WAIT_FOR_CAPACITY)
.addProcessor("spectrum", spectrum).addProcessor("persist", persist)
.connectInput("Ch1", spectrum, 4, QueueOverflowPolicy.WAIT_FOR_CAPACITY)
.connect(spectrum, persist, 4, QueueOverflowPolicy.WAIT_FOR_CAPACITY);
}

private static ChannelDto channel() {
var channel = new ChannelDto();
channel.setVchId("input");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void accept(ChannelFrame frame) {
synchronized (inputGate) {
if (!accepting.get()) {
frame.release();
throw new IllegalStateException("ProcessorPipeline no longer accepts input");
throw rejectedInput();
}
if (inputMode == PipelineInputMode.CONTROLLED_REALTIME) {
rawStartConnection.offer(frame, true);
Expand All @@ -215,13 +215,20 @@ public void accept(ChannelFrame frame) {
}
if (!accepting.get()) {
frame.release();
throw new IllegalStateException("ProcessorPipeline no longer accepts input");
throw rejectedInput();
}
dispatchOwned(frame, matchingFormalConnections(frame), true);
}
}
}

/** Keeps the processor failure that stopped input; callers otherwise only see this later rejection. */
private IllegalStateException rejectedInput() {
Throwable cause = failure.get();
String message = "ProcessorPipeline no longer accepts input";
return new IllegalStateException(cause == null ? message : message + ": " + cause, cause);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 低 每次拒收都会新建一个以同一 failure 对象为 cause 的异常。如果上层(如 DashboardWavReplayRunner 或会话收尾)按常见写法把完成失败作为主异常,并把 accept 抛出的异常 addSuppressed 到它上面,就会形成 original → suppressed(ISE) → cause(original) 的循环引用。JDK 的 printStackTrace 能处理这种循环,但自行遍历 cause/suppressed 链的代码不一定能处理,例如错误转 gRPC 状态详情或结构化日志,可能重复输出或陷入死循环。

本 diff 看不到上层的合并逻辑,所以不能确定一定会出现这种情况。建议确认调用方在主异常与拒收异常的 cause 相同时,不再把拒收异常加为 suppressed。

}

@Override
public void stop() {
if (!stopping.compareAndSet(false, true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ public void onFrame(ChannelFrame frame) { }
Map.of(PipelineStopCoordinator.class, (PipelineStopCoordinator) failed -> { inputStopped.set(true); return List.of(tail); }))));
assertTrue(inputStopped.get()); assertEquals(0, startFailure.getSuppressed().length); assertEquals(1, released.get());
}
/** Replay sources keep feeding after a sink failure; the rejection must still name the failure that stopped input. */
@Test void inputRejectedAfterProcessorFailureCarriesThatFailure() throws Exception {
var original = new IllegalArgumentException("Recorded frame has no unique saved result target");
var processor = new SinkProcessor<ChannelFrame>() { public void onFrame(ChannelFrame frame) { throw original; } };
var pipeline = compile(processor); pipeline.accept(frame(1));
assertThrows(ExecutionException.class, () -> pipeline.completion().toCompletableFuture().get(2, TimeUnit.SECONDS));
var rejected = assertThrows(IllegalStateException.class, () -> pipeline.accept(frame(2)));
assertSame(original, rejected.getCause());
assertTrue(rejected.getMessage().contains(original.getMessage()));
}
private ProcessorPipeline compile(Processor<ChannelFrame, ?> processor) { return compile(processor, Map.of()); }
private ProcessorPipeline compile(Processor<ChannelFrame, ?> processor, Map<Class<?>, Object> capabilities) {
var builder = ProcessorPipelineBuilder.create().addProcessor("processor", processor)
Expand Down
Loading