Repository navigation
fix(ci): align plugin acceptance and backend concurrency checks #30
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 |
|---|---|---|
|
|
@@ -54,14 +54,37 @@ jobs: | |
| name: backend-tests | ||
| runs-on: windows-latest | ||
| timeout-minutes: 60 | ||
| defaults: | ||
| run: | ||
| shell: pwsh | ||
| env: | ||
| COREPACK_ENABLE_DOWNLOAD_PROMPT: '0' | ||
| NODE_OPTIONS: --max-old-space-size=6144 | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Checkout plugin development CLI for cross-repository acceptance | ||
| uses: actions/checkout@v7 | ||
| with: | ||
| repository: crysound/OpenTest-Plugins | ||
| ref: c8e62659fac4543eb8cd22d8211a25b1bf59761e | ||
| path: .ci/OpenTest-Plugins | ||
| persist-credentials: false | ||
| - uses: actions/setup-node@v7 | ||
| with: | ||
| node-version: 22 | ||
| package-manager-cache: false | ||
| - name: Prepare frontend acceptance dependencies | ||
| run: | | ||
|
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. 🟠 中 这个 job 使用 建议在脚本开头加入 |
||
| corepack enable | ||
| corepack prepare pnpm@10.6.5 --activate | ||
| pnpm install --frozen-lockfile | ||
|
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. 🟠 中 插件仓库的依赖可能没有安装。 这一步只在宿主仓库根目录执行了 建议:
|
||
| pnpm build:sdk | ||
| - uses: actions/setup-java@v6 | ||
| with: | ||
| distribution: zulu | ||
| 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 -f apps/backend/pom.xml "-Dopentest.plugins.repository=${{ github.workspace }}/.ci/OpenTest-Plugins" 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. 🟡 低 期望值从 如果改动是因为 macOS 临时目录的符号链接,建议像其他测试一样在用例开头对临时目录执行 |
||
| 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 |
|---|---|---|
|
|
@@ -67,6 +67,7 @@ public class ConcurrentFileManager implements AutoCloseable { | |
| new ConcurrentHashMap<>(); | ||
| private final ConcurrentMap<String, FileConsumerState> fileConsumers = | ||
| new ConcurrentHashMap<>(); | ||
| private final Object writeAdmissionMonitor = new Object(); | ||
| private final Object fileConsumerMonitor = new Object(); | ||
| private final Map<Byte, ContextualFileWriterFactory> writerFactories = | ||
| new ConcurrentHashMap<>(); | ||
|
|
@@ -672,10 +673,14 @@ private ThreadPoolExecutor createFileExecutor() { | |
| while (acceptingWrites.get() && !executor.isShutdown()) { | ||
| try { | ||
| if (executor.getQueue().offer(task, 100L, TimeUnit.MILLISECONDS)) { | ||
| // Close may win while offer is waiting. A task already consumed or discarded | ||
| // owns its existing completion; otherwise reject and let the caller release it. | ||
| if ((!acceptingWrites.get() || executor.isShutdown()) && executor.remove(task)) { | ||
| throw new RejectedExecutionException("fileManager is shutting down"); | ||
| synchronized (writeAdmissionMonitor) { | ||
|
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. 🟡 低 新的同步块与原来的单行条件在判定结果上等价。它额外提供的唯一保证是:在“检查标志”和 请在代码注释或 PR 描述中说明这把锁具体消除了哪条交错路径。如果确实存在问题,也请补充对应测试(见测试文件中的意见)。另外,原来解释任务所有权的注释被删掉了,建议保留,便于后续维护者理解“任务已被 worker 取走时由其负责完成”的约定。 |
||
| if (!acceptingWrites.get() || executor.isShutdown()) { | ||
| if (executor.remove(task)) { | ||
| throw new RejectedExecutionException( | ||
| "fileManager is shutting down"); | ||
| } | ||
| return; | ||
| } | ||
| } | ||
| return; | ||
| } | ||
|
|
@@ -929,12 +934,14 @@ private void completeFileConsumers(Throwable failure) { | |
| } | ||
|
|
||
| private boolean beginManagerClose() { | ||
| synchronized (fileConsumerMonitor) { | ||
| if (!closed.compareAndSet(false, true)) { | ||
| return false; | ||
| synchronized (writeAdmissionMonitor) { | ||
| synchronized (fileConsumerMonitor) { | ||
| if (!closed.compareAndSet(false, true)) { | ||
| return false; | ||
| } | ||
| acceptingWrites.set(false); | ||
| return true; | ||
| } | ||
| acceptingWrites.set(false); | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,20 @@ | |
| import com.opentest.platform.file.writer.FileWriter; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.lang.reflect.Field; | ||
| import java.util.List; | ||
| import java.util.concurrent.ArrayBlockingQueue; | ||
| import java.util.concurrent.BlockingQueue; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.RejectedExecutionException; | ||
| import java.util.concurrent.RejectedExecutionHandler; | ||
| 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; | ||
|
|
@@ -57,6 +63,79 @@ void cancelRejectsBlockedAdmissionAndReleasesEveryQueuedBorrow() throws Exceptio | |
| closeWithBlockedProducer(true); | ||
| } | ||
|
|
||
| @Test | ||
| void workerClaimedAdmissionIsNotRejectedOrDiscarded() throws Exception { | ||
| ConcurrentFileManager manager = new ConcurrentFileManager( | ||
| new ConcurrentFileManagerConfig(1, 1, 3600L, 3600L)); | ||
| BlockingWriter writer = new BlockingWriter(); | ||
| manager.setBlockOnQueueFull(true); | ||
| manager.registerWriterFactory(TYPE, (fileName, append) -> writer); | ||
| manager.init(); | ||
| try { | ||
| ThreadPoolExecutor admissionOwner = managerExecutor(manager); | ||
| RejectedExecutionHandler handler = admissionOwner.getRejectedExecutionHandler(); | ||
| OfferThenShutdownExecutor worker = OfferThenShutdownExecutor.create(); | ||
| AtomicInteger completions = new AtomicInteger(); | ||
| TestData offered = new TestData(); | ||
| offered.addWriteCompletionCallback(error -> completions.incrementAndGet()); | ||
| FileWriteTask task = new FileWriteTask(writer, offered, | ||
| new FileWriteObserver() { | ||
| @Override public void onEnqueued(Data data) { } | ||
| @Override public void onCompleted(Data data, Throwable failure) { } | ||
| }, failure -> { }); | ||
|
|
||
| handler.rejectedExecution(task, worker); | ||
|
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. 🟠 中 这个测试不能作为回归测试。 把它放到改动前的实现上运行:
所以它在旧代码上也能通过,无法证明生产代码的改动修复了什么。 此外,模拟本身前后不一致: 测试还通过反射读取私有字段 **建议:**改为驱动真实的 close 与阻塞 admission 竞争,并断言 completion 恰好触发一次、调用方没有重复释放。 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. 🟠 中 这个测试在修改前的实现上同样会通过。在该场景中, 建议补充一个能区分新旧实现的测试:用闩锁让生产者停在 |
||
| assertEquals(1, worker.getQueue().size()); | ||
| assertEquals(task, worker.getQueue().poll()); | ||
| writer.release.countDown(); | ||
| task.run(); | ||
| assertEquals(1, completions.get()); | ||
| } finally { | ||
| writer.release.countDown(); | ||
| manager.closeNow(); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static ThreadPoolExecutor managerExecutor(ConcurrentFileManager manager) | ||
| throws Exception { | ||
| Field field = ConcurrentFileManager.class.getDeclaredField("fileExecutors"); | ||
| field.setAccessible(true); | ||
| return ((List<ThreadPoolExecutor>) field.get(manager)).getFirst(); | ||
| } | ||
|
|
||
| private static final class OfferThenShutdownExecutor extends ThreadPoolExecutor { | ||
| private final AtomicBoolean shutdownObserved = new AtomicBoolean(); | ||
|
|
||
| private OfferThenShutdownExecutor(BlockingQueue<Runnable> queue) { | ||
| super(0, 1, 0L, TimeUnit.MILLISECONDS, queue); | ||
| } | ||
|
|
||
| static OfferThenShutdownExecutor create() { | ||
| AtomicReference<OfferThenShutdownExecutor> owner = new AtomicReference<>(); | ||
| BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(1) { | ||
| @Override | ||
| public boolean offer(Runnable task, long timeout, TimeUnit unit) | ||
| throws InterruptedException { | ||
| boolean offered = super.offer(task, timeout, unit); | ||
| owner.get().shutdownObserved.set(true); | ||
| return offered; | ||
| } | ||
| }; | ||
| OfferThenShutdownExecutor executor = new OfferThenShutdownExecutor(queue); | ||
| owner.set(executor); | ||
| return executor; | ||
| } | ||
|
|
||
| @Override public boolean isShutdown() { | ||
| return shutdownObserved.get(); | ||
| } | ||
|
|
||
| @Override public boolean remove(Runnable task) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private void closeWithBlockedProducer(boolean cancel) throws Exception { | ||
| try (Fixture fixture = new Fixture()) { | ||
| AtomicInteger completions = new AtomicInteger(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,15 +84,16 @@ void declaredClassesCannotHideDifferentActualGenericTypes(String mode) throws Ex | |
| var bundle = bundle("org.test.invalid", PROVIDER, "level", "1", mode); | ||
| queue(bundle); | ||
| try (PluginRuntime runtime = runtime(bundle)) { | ||
| assertEquals("RECOVERY", runtime.candidate().path("status").asText()); | ||
| assertEquals("PLUGINS_NOT_READY", assertThrows(PluginFailure.class, runtime::dashboardProviders).code()); | ||
| assertEquals("APP_READY", runtime.candidate().path("status").asText()); | ||
| assertIsolated(runtime, bundle); | ||
| assertEquals("DASHBOARD_PROVIDER_NOT_ACTIVE", assertThrows(PluginFailure.class, () -> runtime.dashboardProvider(PROVIDER)).code()); | ||
| var snapshot = runtime.snapshot(false).toString(); | ||
| assertTrue(snapshot.contains("Measurement provider type arguments do not match its registration"), snapshot); | ||
| } | ||
| } | ||
|
|
||
| @ParameterizedTest @ValueSource(strings = {"provider"}) | ||
| void duplicateProviderIdentityRejectsTheWholeCandidate(String collision) throws Exception { | ||
| void duplicateProviderIdentityIsolatesTheConflictingPlugin(String collision) throws Exception { | ||
| var a = bundle("org.test.a", PROVIDER, "level", "1", "valid"); | ||
| var b = bundle("org.test.b", collision.equals("provider") ? PROVIDER : "org.example.other:gain", | ||
| collision.equals("mapping-different-scene") ? "other" : "level", "1", "valid"); | ||
|
|
@@ -101,9 +102,13 @@ void duplicateProviderIdentityRejectsTheWholeCandidate(String collision) throws | |
| initial.requestInstall(b.descriptor(), "install-b", generation(initial)); | ||
| } | ||
| try (PluginRuntime runtime = runtime(a, b)) { | ||
| assertEquals("RECOVERY", runtime.candidate().path("status").asText()); | ||
| assertEquals("BACKEND_CORE_READY", runtime.candidate().path("status").asText()); | ||
| assertIsolated(runtime, b); | ||
|
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. 🟡 低 测试固定了“先到者保留、后到者隔离”的规则,但没有锁定判定依据。
因此测试无法区分实际规则是按安装顺序、按 ID 排序,还是依赖目录遍历顺序。如果是最后一种,测试在不同文件系统上可能不稳定。 建议:
|
||
| assertTrue(runtime.snapshot(false).toString().contains("重复")); | ||
| assertThrows(PluginFailure.class, runtime::dashboardProviders); | ||
| runtime.report(report(runtime, a)); | ||
| assertTrue(runtime.ready()); | ||
| assertEquals("org.test.a", runtime.dashboardProviders().path("providers").get(0).path("pluginId").asText()); | ||
| assertEquals(1, runtime.dashboardProviders().path("providers").size()); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -135,7 +140,8 @@ void duplicateProviderIdentityRejectsTheWholeCandidate(String collision) throws | |
| var mismatch = bundle("org.test.version", PROVIDER, "level", "2", "valid"); | ||
| queue(mismatch); | ||
| try (PluginRuntime runtime = runtime(mismatch)) { | ||
| assertEquals("RECOVERY", runtime.candidate().path("status").asText()); | ||
| assertEquals("APP_READY", runtime.candidate().path("status").asText()); | ||
| assertIsolated(runtime, mismatch); | ||
| assertTrue(runtime.snapshot(false).toString().contains("版本")); | ||
| } | ||
| var valid = bundle("org.test.valid", "org.example.valid:gain", "level", "1", "valid"); | ||
|
|
@@ -187,25 +193,33 @@ void duplicateProviderIdentityRejectsTheWholeCandidate(String collision) throws | |
| } | ||
|
|
||
| @ParameterizedTest @ValueSource(strings={"ownership-duplicate", "ownership-missing", "ownership-empty"}) | ||
| void invalidResultAlgorithmRegistrationRejectsTheCandidate(String mode) throws Exception { | ||
| void invalidResultAlgorithmRegistrationIsolatesThePlugin(String mode) throws Exception { | ||
| var bundle = bundle("org.test.invalid-owner", PROVIDER, "level", "1", mode); | ||
| queue(bundle); | ||
| try (var runtime = runtime(bundle)) { | ||
| assertEquals("RECOVERY", runtime.candidate().path("status").asText()); | ||
| assertEquals("APP_READY", runtime.candidate().path("status").asText()); | ||
| assertIsolated(runtime, bundle); | ||
| assertTrue(runtime.dashboardProviderForAnalysis("sample-analysis").isEmpty()); | ||
| } | ||
| } | ||
|
|
||
| @Test void duplicateResultAlgorithmAcrossProvidersRejectsTheCandidate() throws Exception { | ||
| @Test void duplicateResultAlgorithmAcrossProvidersIsolatesThePlugin() throws Exception { | ||
| var first = bundle("org.test.first-owner", PROVIDER, "level", "1", "ownership"); | ||
| var second = bundle("org.test.second-owner", "org.example.other:gain", "level", "1", "ownership"); | ||
| try (var initial = runtime(first, second)) { | ||
| initial.requestInstall(first.descriptor(), "install-first", generation(initial)); | ||
| initial.requestInstall(second.descriptor(), "install-second", generation(initial)); | ||
| } | ||
| try (var runtime = runtime(first, second)) { | ||
| assertEquals("RECOVERY", runtime.candidate().path("status").asText()); | ||
| assertEquals("BACKEND_CORE_READY", runtime.candidate().path("status").asText()); | ||
| assertIsolated(runtime, second); | ||
| assertTrue(runtime.snapshot(false).toString().contains("sample-analysis")); | ||
| runtime.report(report(runtime, first)); | ||
| assertTrue(runtime.ready()); | ||
| assertSame(runtime.dashboardProvider(PROVIDER).registration(), | ||
| runtime.dashboardProviderForAnalysis("sample-analysis").orElseThrow().registration()); | ||
| assertEquals("DASHBOARD_PROVIDER_NOT_ACTIVE", assertThrows(PluginFailure.class, | ||
| () -> runtime.dashboardProvider("org.example.other:gain")).code()); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -225,11 +239,12 @@ void invalidResultAlgorithmRegistrationRejectsTheCandidate(String mode) throws E | |
| } | ||
|
|
||
| @ParameterizedTest @ValueSource(strings={"catalog-duplicate", "catalog-missing", "catalog-multi-duplicate", "catalog-empty"}) | ||
| void catalogRegistrationRejectsDuplicateAndUnregisteredMeasurements(String mode) throws Exception { | ||
| void catalogRegistrationIsolatesDuplicateAndUnregisteredMeasurements(String mode) throws Exception { | ||
| var bundle = bundle("org.test.catalog", PROVIDER, "level", "1", mode); | ||
| queue(bundle); | ||
| try (var runtime = runtime(bundle)) { | ||
| assertEquals("RECOVERY", runtime.candidate().path("status").asText()); | ||
| assertEquals("APP_READY", runtime.candidate().path("status").asText()); | ||
| assertIsolated(runtime, bundle); | ||
| assertTrue(runtime.measureResultCatalogs().isEmpty()); | ||
| } | ||
| } | ||
|
|
@@ -284,4 +299,13 @@ private static ObjectNode report(PluginRuntime runtime, TestPluginJar.Bundle bun | |
| .put("contributionId", "measure").put("componentId", "contributions/measure/demo"))); | ||
| return report; | ||
| } | ||
| private static void assertIsolated(PluginRuntime runtime, TestPluginJar.Bundle bundle) { | ||
| String id = bundle.descriptor().path("pluginId").asText(); | ||
| var snapshot = runtime.snapshot(false); | ||
| assertEquals("BACKEND_ACTIVATION_FAILED", snapshot.path("pluginFailures").path(id).path("code").asText(), snapshot.toString()); | ||
| for (var plugin : runtime.candidate().path("plugins")) { | ||
| assertFalse(id.equals(plugin.path("pluginId").asText()), "Failed plugin must not be offered to the frontend"); | ||
| } | ||
| } | ||
|
|
||
| } | ||
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.
🟡 低 插件仓库只做了检出,没有安装它自己的依赖。如果
tools/dev.mjs或它调用的打包流程会导入插件仓库自身的 npm 依赖,CI 中的跨仓库验收会因缺少node_modules失败,而本地验证时这些依赖通常已经装好。请确认 CI 下该验收确实能运行。如果需要依赖,应在.ci/OpenTest-Plugins中执行pnpm install --frozen-lockfile。另外,检出目录位于工作区内,请确认它不会被根目录的 pnpm workspace 或其他检查扫描到。