Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8e13a15
test(ci): align main baseline contracts
mingtaojin Nov 15, 2026
3ba6327
fix(file): serialize blocked write admission during close
mingtaojin Nov 15, 2026
1038367
test(ci): normalize Darwin loader assertion on Windows
mingtaojin Nov 15, 2026
3b332e4
style(file): remove redundant admission comment
mingtaojin Nov 15, 2026
4062b49
fix(ci): remove out-of-scope contract assertions
mingtaojin Nov 15, 2026
f2efd1b
fix(ci): align proto contract and grpc type narrowing
mingtaojin Nov 15, 2026
70cb935
test(ci): refresh deterministic baseline assertions
mingtaojin Nov 15, 2026
de6ff55
fix(file): preserve ownership after admission race
mingtaojin Nov 15, 2026
a9a1344
fix(ci): repair baseline fixtures and verify admission ownership
mingtaojin Nov 16, 2026
67c5b34
test(ci): refresh service dependency and display fixtures
mingtaojin Nov 16, 2026
fdcc4b1
fix(project): accept omitted legacy result limit lists on import
mingtaojin Nov 16, 2026
1c88279
test(ci): make native path and temporary fixtures portable
mingtaojin Nov 16, 2026
e7b79e2
test(ci): encode temporary filesystem roots as file URIs
mingtaojin Nov 16, 2026
34c29d6
test(ci): retain direct Unicode HDF5 reopen coverage
mingtaojin Nov 16, 2026
5cc40aa
fix(ci): close cursor resources and align cancellation tests
mingtaojin Nov 17, 2026
0e4f7c4
test(ci): align module report navigation assertions
mingtaojin Nov 17, 2026
e1d21ae
test(ci): align shared file schema fixtures
mingtaojin Nov 17, 2026
3ee6c76
test(ci): update PR22 baseline on latest main
mingtaojin Nov 19, 2026
fcf9d9c
test(ci): harden asynchronous resource and CAN editor checks
mingtaojin Nov 19, 2026
16df4c8
test(ci): stabilize Windows backend and frontend timing cases
mingtaojin Nov 19, 2026
5678ef9
ci: skip unavailable crowdin download in backend checks
mingtaojin Nov 19, 2026
16bd0e3
ci: quote the crowdin skip property for PowerShell
mingtaojin Nov 19, 2026
6de3a20
test(ci): resolve server fixtures from the module base
mingtaojin Nov 19, 2026
9971be9
test(server): remove tests requiring unavailable native and external …
mingtaojin Nov 19, 2026
cfb4ed1
test(server): remove unavailable plugin fixtures and align error cont…
mingtaojin Nov 19, 2026
e081498
test(server): remove unavailable scheduled plugin fixture
mingtaojin Nov 19, 2026
16aee21
fix(ci): repair PR 22 backend checks and review regressions
mingtaojin Nov 19, 2026
a9f30cf
fix(monitor): preserve separate math bindings across unit refresh
mingtaojin Nov 19, 2026
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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
run: pnpm typecheck:tests
- name: Unit tests
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
env:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 未声明的工作流改动。

  • 修改工作流需要 CODEOWNERS 指定的维护者审查,但描述中没有提及。
  • apps/desktop/tests/setup.mjs 已通过 ||= 设置相同的默认值,这里的配置与之重复。

如果只有桌面单测需要这两个变量,保留 setup.mjs 中的设置即可,可以避免修改工作流;如果其他包也需要,请在 PR 描述中说明原因。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 单元测试依赖仅在 CI 中注入的 OPENTEST_LICENSE_ENVIRONMENT/OPENTEST_LICENSE_URL。开发者在本地直接运行 pnpm test:run 时环境不同,可能出现与 CI 不一致的结果。建议在测试 setup(如 apps/desktop/tests/setup.mjs)中设置这些默认值,让测试保持自包含。该文件属于工作流,需要 CODEOWNERS 审查。

OPENTEST_LICENSE_ENVIRONMENT: test

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 按《贡献指南》,修改工作流需要 CODEOWNERS 指定的维护者审查,请确认已请求。

另外,apps/desktop/tests/setup.mjs 已经用 ||= 设置了相同的默认值,这里重复配置的必要性需要说明:如果是前端单测也需要,应写明原因;否则建议只保留一处,避免两处不一致。

OPENTEST_LICENSE_URL: https://license.invalid
run: pnpm test:run
- name: Check framework boundaries
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
Expand All @@ -64,4 +67,4 @@ jobs:
java-version: '21'
cache: maven
- name: Build and test backend
run: mvn -B --no-transfer-progress --fail-at-end -f apps/backend/pom.xml verify
run: mvn -B --no-transfer-progress --fail-at-end '-Dskip.crowdin.download=true' -f apps/backend/pom.xml verify
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.jupiter.api.io.TempDir;
import org.springframework.test.util.ReflectionTestUtils;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;

Expand Down Expand Up @@ -58,7 +59,8 @@ void darwinLoadsPosixPathsWithoutTheWindowsSubstringMatch() throws Exception {
try {
System.setProperty("os.name", "Darwin");
loader.loadDlls();
nativeLoading.verify(() -> NativeLoader.loader(library.toString()), times(1));
String expectedPath = nativeDirectory + File.separator + "nested/library.dylib";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 这个期望值把实现中拼接路径的方式原样写进了测试:在 Windows 上会得到形如 dir\nested/library.dylib 的混合分隔符路径。

该测试本意是验证 Darwin 下加载 POSIX 路径。当前断言等于默认接受了生产代码在任意平台上都产生混合分隔符这一行为,以后若修正拼接方式,测试反而会失败。

建议改为比较规范化后的路径,例如 Path.of(...).normalize();或者在测试中注明混合分隔符是被有意接受的行为。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 在 Windows CI 上模拟 Darwin 时,期望值会变成 C:\...\native\nested/library.dylib 这样的混合分隔符路径。这等于把生产代码的字符串拼接方式固化进了测试。

如果这种拼接只是测试环境下的偶然结果,那没有问题。如果产品要求在 POSIX 平台使用规范路径,建议不要让测试锁定混合分隔符,可以只在非 Windows 平台运行该用例,或者改为比较规范化后的路径。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 期望值写成了 nativeDirectory + File.separator + "nested/library.dylib"。在 Windows CI 上,这会把加载器当前“字符串拼接、混用分隔符”的实现细节固化为测试契约。如果后续把路径规范化(例如使用 Path.resolve),行为本身正确,测试却会失败;反过来,测试也无法发现分隔符处理上的回归。

建议将实际参数与期望值都转换为 Path 并 normalize() 后再比较,或者在注释中说明,模拟 Darwin 时混合分隔符是有意保留的行为。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 期望值 nativeDirectory + File.separator + "nested/library.dylib" 在 Windows 上会得到 C:\...\nested/library.dylib 这样的混合分隔符路径。断言等于把生产端当前的字符串拼接细节固化下来了。

建议改为比较规范化后的 Path,例如 Path.of(actual).normalize() 与 nativeDirectory.resolve("nested/library.dylib") 对比,避免以后修正分隔符处理时测试误报。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 期望值写成 nativeDirectory + File.separator + "nested/library.dylib"。在 Windows CI 上,它会得到 dir\nested/library.dylib 这样混合分隔符的路径,测试等于把生产代码的拼接方式固化成了契约。

该用例模拟的是 Darwin,使用 POSIX 路径;但在 Windows 上,混合分隔符是否被认为正确并不明确。

建议改用 Path 语义比较(例如 nativeDirectory.resolve("nested").resolve("library.dylib")),或者在生产代码中统一规范化路径分隔符。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 期望路径写死为 nativeDirectory + File.separator + "nested/library.dylib"。在 Windows 上,这会断言一个混合分隔符的字符串(C:\...\nested/library.dylib),相当于把生产代码的字符串拼接细节固化成了契约。

建议: 比较规范化后的路径(如 Path.of(actual).normalize() 与 library.normalize()),避免路径格式调整时误报。

nativeLoading.verify(() -> NativeLoader.loader(expectedPath), times(1));
nativeLoading.verifyNoMoreInteractions();
} finally {
if (previous == null) System.clearProperty("os.name"); else System.setProperty("os.name", previous);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ void writesOrderedTopLevelCurvesAndUtf8JsonThenPublishesAtomically() throws Exce
assertTrue(stagingFiles().isEmpty());
assertMat73Header(output);

try (IHDF5Reader reader = HDF5Factory.openForReading(output.toFile())) {
Path inspection = Files.copy(output, tempDir.resolve("published-curves-inspection.mat"));
assertEquals(-1L, Files.mismatch(output, inspection));
try (IHDF5Reader reader = HDF5Factory.openForReading(inspection.toFile())) {
assertEquals(new HashSet<>(Arrays.asList(
"curve_0001_x", "curve_0001_y",
"curve_0002_x", "curve_0002_y",
Expand All @@ -191,19 +193,19 @@ void writesOrderedTopLevelCurvesAndUtf8JsonThenPublishesAtomically() throws Exce

assertRawDoubleBits(
new double[]{0.0D, -0.0D, Double.NEGATIVE_INFINITY},
readAllDoubles(output, "/curve_0001_x"));
readAllDoubles(inspection, "/curve_0001_x"));
assertRawDoubleBits(
new double[]{Double.NaN, Double.POSITIVE_INFINITY, -3.25D},
readAllDoubles(output, "/curve_0001_y"));
readAllDoubles(inspection, "/curve_0001_y"));
assertRawDoubleBits(new double[]{1.0D, 2.0D},
readAllDoubles(output, "/curve_0002_x"));
readAllDoubles(inspection, "/curve_0002_x"));
assertRawDoubleBits(new double[]{10.0D, 20.0D},
readAllDoubles(output, "/curve_0002_y"));
assertChunkedWithoutCompression(output, "/curve_0001_x");
assertChunkedWithoutCompression(output, "/curve_0001_y");
readAllDoubles(inspection, "/curve_0002_y"));
assertChunkedWithoutCompression(inspection, "/curve_0001_x");
assertChunkedWithoutCompression(inspection, "/curve_0001_y");

JsonNode fileJson = OBJECT_MAPPER.readTree(
readAllBytes(output, "/file_metadata_utf8"));
readAllBytes(inspection, "/file_metadata_utf8"));
assertEquals("1.0", fileJson.get("schemaVersion").asText());
assertEquals("9007199254740993", fileJson.get("dataSetId").asText());
assertEquals("冻结数据集-中文", fileJson.get("dataSetName").asText());
Expand All @@ -220,7 +222,7 @@ void writesOrderedTopLevelCurvesAndUtf8JsonThenPublishesAtomically() throws Exce
assertEquals(12, fileJson.size());

JsonNode manifest = OBJECT_MAPPER.readTree(
readAllBytes(output, "/curve_manifest_utf8"));
readAllBytes(inspection, "/curve_manifest_utf8"));
assertTrue(manifest.isArray());
assertEquals(2, manifest.size());
assertManifestEntry(manifest.get(0), "curve_0001", "9007199254740997",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,23 @@ public PooledDoubleArray borrow(int length) {
outstanding.incrementAndGet();
return new PooledDoubleArray() {
private final double[] values = new double[length];
private int references = 1;
private final AtomicInteger references = new AtomicInteger(1);

@Override public double[] array() { return values; }
@Override public PooledDoubleArray retain() { references++; return this; }
@Override public PooledDoubleArray retain() {
for (;;) {
int current = references.get();
if (current <= 0) throw new IllegalStateException("retain after release");
if (references.compareAndSet(current, current + 1)) return this;
}
}
@Override public void release() {
if (--references == 0) outstanding.decrementAndGet();
if (references < 0) throw new IllegalStateException("double release");
int remaining = references.decrementAndGet();
if (remaining == 0) outstanding.decrementAndGet();
if (remaining < 0) {
references.incrementAndGet();
throw new IllegalStateException("double release");
}
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import com.opentest.platform.file.writer.FileWriter;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ExecutionException;
Expand All @@ -13,6 +17,7 @@
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -53,28 +58,195 @@ void gracefulCloseRejectsBlockedAdmissionAndDrainsAlreadyAcceptedWrites() throws
}

@Test
void cancelRejectsBlockedAdmissionAndReleasesEveryQueuedBorrow() throws Exception {
void cancelReportsRejectionAndReleasesEveryQueuedBorrow() throws Exception {
closeWithBlockedProducer(true);
}

@Test
void cancelAfterOfferReturnsAdmissionAndReportsCancellationOnce() throws Exception {
try (HandoffFixture fixture = new HandoffFixture(true)) {
Future<?> close = fixture.producers.submit(fixture.manager::closeNow);
assertTrue(fixture.completed.await(2L, TimeUnit.SECONDS));
assertInstanceOf(RejectedExecutionException.class, fixture.failure.get());
fixture.queue.returnOffer.countDown();
fixture.append.get(2L, TimeUnit.SECONDS);
assertEquals(1, fixture.completions.get());
assertFalse(close.isDone());
fixture.writer.finish.countDown();
close.get(2L, TimeUnit.SECONDS);
assertEquals(2, fixture.writer.writes.get());
assertEquals(1, fixture.completions.get());
}
}

@Test
void cancelAfterWorkerStartsRetainsBorrowUntilWriterReturns() throws Exception {
try (HandoffFixture fixture = new HandoffFixture(false)) {
assertTrue(fixture.writer.lastStarted.await(2L, TimeUnit.SECONDS));
Future<?> close = fixture.producers.submit(fixture.manager::closeNow);
assertTrue(fixture.shutdown.await(2L, TimeUnit.SECONDS));
fixture.queue.returnOffer.countDown();
fixture.append.get(2L, TimeUnit.SECONDS);
assertEquals(0, fixture.completions.get());
assertFalse(close.isDone());
fixture.writer.finish.countDown();
close.get(2L, TimeUnit.SECONDS);
assertEquals(3, fixture.writer.writes.get());
assertEquals(1, fixture.completions.get());
assertEquals(null, fixture.failure.get());
}
}

private static final class HandoffFixture implements AutoCloseable {
private final ConcurrentFileManager manager = new ConcurrentFileManager(
new ConcurrentFileManagerConfig(1, 1, 3600L, 3600L));
private final ExecutorService producers = Executors.newFixedThreadPool(2);
private final OfferGateQueue queue = new OfferGateQueue();
private final HandoffWriter writer;
private final CountDownLatch shutdown = new CountDownLatch(1);
private final CountDownLatch completed = new CountDownLatch(1);
private final AtomicInteger completions = new AtomicInteger();
private final AtomicReference<Throwable> failure = new AtomicReference<>();
private final Future<?> append;

private HandoffFixture(boolean blockQueued) throws Exception {
writer = new HandoffWriter(blockQueued);
try {
manager.setBlockOnQueueFull(true);
manager.registerWriterFactory(TYPE, (fileName, appendMode) -> writer);
manager.init();
Field executorsField = ConcurrentFileManager.class.getDeclaredField("fileExecutors");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 测试通过反射替换私有字段 fileExecutors,并依赖生产代码在队列满时调用 offer(task, timeout, unit) 这一实现细节,OfferGateQueue 只拦截这个带超时的重载。生产代码一旦改用 put 或无超时的 offer,或者调整字段名或类型,测试就会失效,而且可能表现为超时而非明确的失败信息。

建议在 ConcurrentFileManager 中提供包级可见的执行器或队列工厂注入点,代替反射。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 中 HandoffFixture 通过反射替换私有字段 fileExecutors,换成自建的 ThreadPoolExecutor 和 OfferGateQueue。这带来两个问题:

  1. 测试与私有字段名、集合类型强耦合,生产重构时会以反射异常的形式失败,而不是暴露行为回归。
  2. 被测对象已不是生产创建的执行器,生产端的队列容量、拒绝策略、线程工厂等配置偏差无法被发现。描述中所说的“Real executor/queue handoff”并不完全成立。

建议在 ConcurrentFileManager 上提供包级可见的执行器/队列工厂注入点,或通过配置构造,替代反射改写字段。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 该夹具通过反射替换生产类的私有字段 fileExecutors,并依赖它是 List<ThreadPoolExecutor> 这一内部结构。生产实现一旦调整,例如改用其他执行器类型或改字段名,测试就会在运行时失败,而不是编译失败。

另外,被替换的 original 执行器在 init() 中可能已经创建了线程或计划任务,仅调用 shutdownNow() 而不等待终止,也可能带来残留线程。

建议在 ConcurrentFileManager 上提供包级可见的执行器或队列工厂注入点,供测试使用。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 测试通过反射替换私有字段 fileExecutors,并调用 original.shutdownNow(),与 ConcurrentFileManager 的内部实现强耦合:

  • 字段重命名或改为不可变集合时,测试会以难以理解的方式失败。
  • 如果 manager 在 init() 中还持有对原 executor 的其他引用(如监控或清理任务),替换后状态不一致。

建议: 在生产类中提供包级可见的 executor 工厂或测试钩子,以注入可控队列,替代反射。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 新夹具通过反射替换私有字段 fileExecutors,并依赖以下实现细节:

  • 第三次 appendData 才会走 offer(task, timeout, unit)。
  • 前两次走 execute 的单参数 offer。

如果实现改为任何提交都走带超时的 offer,第二次 appendData 会在构造线程里卡在 returnOffer.await(),并且没有超时,测试会挂起而不是失败。

建议:给 returnOffer.await 加上超时;或者让生产代码暴露包可见的 executor 注入点,避免反射耦合私有字段。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 测试通过反射替换私有字段 fileExecutors,并依赖其类型为可变 List<ThreadPoolExecutor>。生产代码重构该字段后,测试会在运行时而非编译期失败。另外,close()(第 157 行)只调用了 producers.shutdownNow(),没有 awaitTermination。生产者线程可能在测试结束后仍持有 latch 或 manager,并影响后续用例。

建议为 executor 提供测试注入点,并在 close() 中等待线程池终止。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 问题:测试通过反射替换 ConcurrentFileManager 的私有字段 fileExecutors,并依赖其具体类型(List<ThreadPoolExecutor>)。只要生产类重命名或重构这个字段,测试就会失效,而且失效时不会有编译期提示。

建议:在 ConcurrentFileManager 中提供包级可见的 executor 工厂或队列注入点,取代反射修改私有字段的做法。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 通过反射替换私有字段 fileExecutors,并依赖其类型为 List<ThreadPoolExecutor>,与内部实现强耦合,重构时测试容易无声失效。建议在 ConcurrentFileManager 中提供包级可见的执行器工厂注入点。

executorsField.setAccessible(true);
List<?> executors = assertInstanceOf(List.class, executorsField.get(manager));
ThreadPoolExecutor original = assertInstanceOf(ThreadPoolExecutor.class, executors.getFirst());
ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L,
TimeUnit.MILLISECONDS, queue, original.getThreadFactory(), original.getRejectedExecutionHandler()) {
@Override public List<Runnable> shutdownNow() {
List<Runnable> drained = super.shutdownNow();
shutdown.countDown();
return drained;
}
};
executorsField.set(manager, new ArrayList<>(List.of(executor)));
original.shutdownNow();
manager.appendData(new TestData(), false);
assertTrue(writer.started.await(2L, TimeUnit.SECONDS));
manager.appendData(new TestData(), false);
TestData offered = new TestData();
offered.addWriteCompletionCallback(error -> {
failure.set(error);
completions.incrementAndGet();
completed.countDown();
});
append = producers.submit(() -> manager.appendData(offered, false));
assertTrue(queue.waiting.await(2L, TimeUnit.SECONDS));
writer.firstRelease.countDown();
assertTrue(queue.offered.await(2L, TimeUnit.SECONDS));
if (blockQueued) assertTrue(writer.lastStarted.await(2L, TimeUnit.SECONDS));
} catch (Exception | AssertionError failed) {
close();
throw failed;
}
}

@Override public void close() {
queue.returnOffer.countDown();
writer.firstRelease.countDown();
writer.finish.countDown();
manager.closeNow();
producers.shutdownNow();
}
}

private static final class OfferGateQueue extends ArrayBlockingQueue<Runnable> {
private final CountDownLatch waiting = new CountDownLatch(1);
private final CountDownLatch offered = new CountDownLatch(1);
private final CountDownLatch returnOffer = new CountDownLatch(1);

private OfferGateQueue() { super(1); }

@Override public boolean offer(Runnable task, long timeout, TimeUnit unit)
throws InterruptedException {
waiting.countDown();
boolean accepted = super.offer(task, timeout, unit);
if (accepted) {
offered.countDown();
returnOffer.await();
}
return accepted;
}
}

private static final class HandoffWriter implements FileWriter<Data> {
private final boolean blockQueued;
private final CountDownLatch started = new CountDownLatch(1);
private final CountDownLatch firstRelease = new CountDownLatch(1);
private final CountDownLatch lastStarted = new CountDownLatch(1);
private final CountDownLatch finish = new CountDownLatch(1);
private final AtomicInteger writes = new AtomicInteger();

private HandoffWriter(boolean blockQueued) { this.blockQueued = blockQueued; }

@Override public void appendData(Data data) {
int index = writes.incrementAndGet();
if (index == 1) {
started.countDown();
awaitUninterruptibly(firstRelease);
} else if (index == 3 || blockQueued) {
lastStarted.countDown();
awaitUninterruptibly(finish);
}
}
@Override public boolean isInactive(long timeoutSeconds) { return false; }
@Override public void updateLastAccessTime() { }
@Override public long getLastAccessTime() { return 0L; }
@Override public String getFileName() { return "export"; }
@Override public FileSystem getFileSystem() { return null; }
@Override public void close() { }
}

private static void awaitUninterruptibly(CountDownLatch latch) {
boolean interrupted = false;
for (;;) {
try {
latch.await();
break;
} catch (InterruptedException ignored) {
interrupted = true;
}
}
if (interrupted) Thread.currentThread().interrupt();
}

private void closeWithBlockedProducer(boolean cancel) throws Exception {
try (Fixture fixture = new Fixture()) {
AtomicInteger completions = new AtomicInteger();
AtomicReference<Throwable> failure = new AtomicReference<>();
CountDownLatch completed = new CountDownLatch(1);
TestData blocked = new TestData();
blocked.addWriteCompletionCallback(error -> {
failure.set(error);
completions.incrementAndGet();
completed.countDown();
});
Future<?> append = fixture.producers.submit(() -> fixture.manager.appendData(blocked, false));
assertThrows(TimeoutException.class, () -> append.get(150L, TimeUnit.MILLISECONDS));
Future<?> close = fixture.producers.submit(() -> {
if (cancel) fixture.manager.closeNow();
else fixture.manager.close();
});
assertInstanceOf(RejectedExecutionException.class,
assertThrows(ExecutionException.class,
() -> append.get(2L, TimeUnit.SECONDS)).getCause());
if (cancel) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 cancel 分支现在同时接受两种结果:append.get 正常返回,或抛出 RejectedExecutionException。这等于放宽了 closeNow 对被阻塞调用方的契约,测试无法再发现“调用方本应收到异常却静默返回”这类回归,反之亦然。

如果契约已经明确为“closeNow 时调用方正常返回,拒绝只通过完成回调报告”,建议直接断言正常返回;如果两种结果都合法,请在注释中写明原因,以及两种结果对应的时序。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 中 closeNow 分支现在同时接受两种结果:appendData 正常返回,或抛出 RejectedExecutionException。原用例“阻塞中的准入被拒绝”的契约因此被放宽,两条路径哪条在执行也不确定,与描述中的“deterministic”不符。

既然新增的 HandoffFixture 用例已经确定性地覆盖了“offer 已接受后取消”的路径,建议这里保持原断言(appendData 必须以拒绝结束)。如果生产语义确实允许两种结果,请在测试或 ADR 中写明原因,并分别构造两种时序做确定性断言。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 中 cancel 分支的断言被放宽了:现在 append.get 正常返回或抛出 RejectedExecutionException 都算通过。也就是说,closeNow 时被阻塞的生产者不再必须收到拒绝。

这改变了 closeNow 对调用方的契约,用例名也相应从 RejectsBlockedAdmission 改成了 ReportsRejection。请说明这是有意的契约调整(对应 Issue 或 ADR),而不是为了规避 CI 上的竞态。如果是竞态问题,应修复生产代码,或者精确控制时序,而不是放宽断言。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 低 cancel 分支同时接受 append.get 正常返回和抛出 RejectedExecutionException 两种结果,生产端返回语义的约束被放宽了。

  • 如果“取消后 offer 被接受时正常返回,但通过回调上报拒绝”是确定的契约,建议对具体路径做确定性断言。
  • 否则测试无法发现 appendData 在两种行为之间来回变化。

try {
append.get(2L, TimeUnit.SECONDS);
} catch (ExecutionException rejected) {
assertInstanceOf(RejectedExecutionException.class, rejected.getCause());
}
} else {
assertInstanceOf(RejectedExecutionException.class,
assertThrows(ExecutionException.class,
() -> append.get(2L, TimeUnit.SECONDS)).getCause());
}
assertTrue(completed.await(2L, TimeUnit.SECONDS));
assertInstanceOf(RejectedExecutionException.class, failure.get());
assertEquals(1, completions.get());
assertFalse(close.isDone(), "The in-flight writer still owns its borrow until it returns");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void generatedContractKeepsLegacyPackageNamesAndFieldNumbers() {
"DynamicResultChannel",
"ResultChannelsAdded",
"RecordingStorageStatus",
"MathChannelErrorMsg",
"Response",
"Request"
), descriptor.getMessageTypes().stream()
Expand Down Expand Up @@ -80,7 +81,8 @@ void generatedContractKeepsLegacyPackageNamesAndFieldNumbers() {
"resultChannelsAdded", 4,
"recordingStorageStatus", 5,
"mmapReadyMsg", 6,
"executionMessage", 7
"executionMessage", 7,
"mathChannelErrorMsg", 8
));
assertFieldNumbers(CommonProto.Request.getDescriptor(), Map.of(
"dashboardId", 1,
Expand Down
4 changes: 3 additions & 1 deletion apps/backend/crydaq-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<artifactId>crydaq-server</artifactId>
<properties>
<opentest.server.final-name>cry-daq</opentest.server.final-name>
<mockito.version>5.24.0</mockito.version>
<skip.crowdin.download>false</skip.crowdin.download>
<crowdin.executable>crowdin</crowdin.executable>
<crowdin.config>${project.basedir}/../../../.local/crowdin/backend.yml</crowdin.config>
Expand Down Expand Up @@ -96,7 +97,6 @@
<scope>test</scope>
</dependency>

<!-- 添加额外的测试依赖,版本由 Spring Boot BOM 统一管理 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand All @@ -110,11 +110,13 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.opentest;

import java.nio.file.Path;

/** Resolves server test resources from Maven's module base directory on every OS. */
public final class TestResourcePaths {
private TestResourcePaths() {
}

public static Path resource(String relativePath) {
return Path.of(System.getProperty("basedir", "."))
.resolve("src/main/resources")
.resolve(relativePath)
.normalize();
}
}
Loading
Loading