test(weaviate): 让并发建表的用例真的每个 worker 都去创建,消掉随机失败
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 缺失",这里只是让实现与意图一致。 只改测试,不碰生产代码。main
parent
e39043f34b
commit
1912ba26c5
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue