Repository navigation
fix(dashboard): 回放管线拒收输入时保留首个处理器失败 #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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]; | ||
| 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 中 当前两条断言不能确定地验证本次修复路径:
建议补充断言,锁定异常确实来自拒收路径,例如: var rejected = assertInstanceOf(IllegalStateException.class, failure);
assertTrue(rejected.getMessage().startsWith("ProcessorPipeline no longer accepts input"));如果会话会再包装一层,就沿 cause 链定位。也可以在 |
||
| assertInstanceOf(IllegalArgumentException.class, failure.getCause()); | ||
| } | ||
|
|
||
| private static PluginMeasureExecutor provider(List<FrameFact> facts, AtomicBoolean resourceClosed, | ||
| AtomicReference<CompletionStage<Void>> packageReleased) { | ||
| return provider(facts,resourceClosed,packageReleased,services -> { }); | ||
|
|
@@ -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"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
|
@@ -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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 低 每次拒收都会新建一个以同一 本 diff 看不到上层的合并逻辑,所以不能确定一定会出现这种情况。建议确认调用方在主异常与拒收异常的 cause 相同时,不再把拒收异常加为 suppressed。 |
||
| } | ||
|
|
||
| @Override | ||
| public void stop() { | ||
| if (!stopping.compareAndSet(false, true)) { | ||
|
|
||
There was a problem hiding this comment.
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 时长,以减少单元测试的耗时和磁盘占用。采样率和位深可以保留,以贴近生产条件。