From 1912ba26c544025adb869459a74c2cbac2a95cd9 Mon Sep 17 00:00:00 2001 From: linus-liu-web <11640009+linus-liu-web@users.noreply.github.com> Date: Sun, 27 Sep 2026 01:08:01 +0800 Subject: [PATCH] =?UTF-8?q?test(weaviate):=20=E8=AE=A9=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=E5=BB=BA=E8=A1=A8=E7=9A=84=E7=94=A8=E4=BE=8B=E7=9C=9F=E7=9A=84?= =?UTF-8?q?=E6=AF=8F=E4=B8=AA=20worker=20=E9=83=BD=E5=8E=BB=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=EF=BC=8C=E6=B6=88=E6=8E=89=E9=9A=8F=E6=9C=BA=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestEnsureCollectionToleratesConcurrentCreation 用 barrier 让 8 个 worker 都先探到 "class 不存在",再一起冲创建,最后断言 server.creates == workers。但假服务器的 GET 分支是「先等 barrier、再采样 s.exists」:barrier 一放开,赢家的 POST 可能已经把 exists 置为 true,排在后面的 worker 采样到"已存在",就在创建之前返回了,从来没去 尝试创建。实际创建数取决于调度(本地 100 次里挂 1 次;CI 上是 4 或 6),断言于是 随机失败 —— main 自己的 CI 与多个 PR 都挂在这条上。 把采样挪到 barrier 之前:每个 worker 读到的是它到达时的状态(此刻必然为 false), 8 个创建请求全部到达服务端,断言稳定。测试注释里写的意图本来就是"让每个 worker 都 看到 class 缺失",这里只是让实现与意图一致。 只改测试,不碰生产代码。 --- .../repository/retriever/weaviate/repository_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/application/repository/retriever/weaviate/repository_test.go b/internal/application/repository/retriever/weaviate/repository_test.go index 37b7808d..846084ce 100644 --- a/internal/application/repository/retriever/weaviate/repository_test.go +++ b/internal/application/repository/retriever/weaviate/repository_test.go @@ -39,13 +39,18 @@ func (s *schemaTestServer) repository(t *testing.T) *weaviateRepository { w.Header().Set("Content-Type", "application/json") switch { case r.Method == http.MethodGet && strings.HasPrefix(r.URL.Path, "/v1/schema/"): - if s.probe != nil { - s.probe() - } + // Answer from the state the worker found on arrival, before the + // barrier releases the race. Sampling after it instead lets the + // winner's create turn into an "already exists" answer for whoever + // the scheduler runs last, so that worker skips the create + // entirely and fewer than `workers` creates ever reach the server. s.mu.Lock() s.probes++ exists := s.exists s.mu.Unlock() + if s.probe != nil { + s.probe() + } if !exists { w.WriteHeader(http.StatusNotFound) return