Repository navigation
fix(ci): repair deterministic main baseline failures #22
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
8e13a15
3ba6327
1038367
3b332e4
4062b49
f2efd1b
70cb935
de6ff55
a9a1344
67c5b34
fdcc4b1
1c88279
e7b79e2
34c29d6
5cc40aa
0e4f7c4
e1d21ae
3ee6c76
fcf9d9c
16df4c8
5678ef9
16bd0e3
6de3a20
9971be9
cfb4ed1
e081498
16aee21
a9f30cf
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 |
|---|---|---|
|
|
@@ -46,6 +46,9 @@ jobs: | |
| run: pnpm typecheck:tests | ||
| - name: Unit tests | ||
| if: ${{ !cancelled() && steps.install.outcome == 'success' }} | ||
| env: | ||
|
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. 🟡 低 单元测试依赖仅在 CI 中注入的 |
||
| OPENTEST_LICENSE_ENVIRONMENT: test | ||
|
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. 🟡 低 按《贡献指南》,修改工作流需要 CODEOWNERS 指定的维护者审查,请确认已请求。 另外, |
||
| OPENTEST_LICENSE_URL: https://license.invalid | ||
| run: pnpm test:run | ||
| - name: Check framework boundaries | ||
| if: ${{ !cancelled() && steps.install.outcome == 'success' }} | ||
|
|
@@ -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 |
|---|---|---|
|
|
@@ -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; | ||
|
|
||
|
|
@@ -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"; | ||
|
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. 🟡 低 这个期望值把实现中拼接路径的方式原样写进了测试:在 Windows 上会得到形如 该测试本意是验证 Darwin 下加载 POSIX 路径。当前断言等于默认接受了生产代码在任意平台上都产生混合分隔符这一行为,以后若修正拼接方式,测试反而会失败。 建议改为比较规范化后的路径,例如 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. 🟡 低 在 Windows CI 上模拟 Darwin 时,期望值会变成 如果这种拼接只是测试环境下的偶然结果,那没有问题。如果产品要求在 POSIX 平台使用规范路径,建议不要让测试锁定混合分隔符,可以只在非 Windows 平台运行该用例,或者改为比较规范化后的路径。 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. 🟡 低 期望值写成了 建议将实际参数与期望值都转换为 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. 🟡 低 期望值 建议改为比较规范化后的 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. 🟡 低 期望值写成 该用例模拟的是 Darwin,使用 POSIX 路径;但在 Windows 上,混合分隔符是否被认为正确并不明确。 建议改用 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. 🟡 低 期望路径写死为 建议: 比较规范化后的路径(如 |
||
| nativeLoading.verify(() -> NativeLoader.loader(expectedPath), times(1)); | ||
| nativeLoading.verifyNoMoreInteractions(); | ||
| } finally { | ||
| if (previous == null) System.clearProperty("os.name"); else System.setProperty("os.name", previous); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
@@ -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"); | ||
|
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. 🟡 低 测试通过反射替换私有字段 建议在 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. 🟠 中
建议在 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. 🟡 低 该夹具通过反射替换生产类的私有字段 另外,被替换的 建议在 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. 🟡 低 测试通过反射替换私有字段
建议: 在生产类中提供包级可见的 executor 工厂或测试钩子,以注入可控队列,替代反射。 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. 🟡 低 新夹具通过反射替换私有字段
如果实现改为任何提交都走带超时的 建议:给 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. 🟡 低 测试通过反射替换私有字段 建议为 executor 提供测试注入点,并在 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. 🟡 低 问题:测试通过反射替换 建议:在 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. 🟡 低 通过反射替换私有字段 |
||
| 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) { | ||
|
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. 🟡 低 如果契约已经明确为“ 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. 🟠 中 既然新增的 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. 🟠 中 这改变了 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. 🟡 低
|
||
| 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"); | ||
|
|
||
| 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(); | ||
| } | ||
| } |
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.
🟡 低 未声明的工作流改动。
apps/desktop/tests/setup.mjs已通过||=设置相同的默认值,这里的配置与之重复。如果只有桌面单测需要这两个变量,保留
setup.mjs中的设置即可,可以避免修改工作流;如果其他包也需要,请在 PR 描述中说明原因。