mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-30 16:23:31 +00:00
test: 修复 WebSocket 同线程抢占测试的关闭时序竞态
This commit is contained in:
@@ -310,10 +310,21 @@ func runOpenAIWSCodexThreadPair(t *testing.T, threadA, threadB string) (serverEr
|
||||
close(gatedConn.gate)
|
||||
|
||||
readCtxA, cancelA := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
_, completedA, aReadErr := connA.Read(readCtxA)
|
||||
defer cancelA()
|
||||
for {
|
||||
var completedA []byte
|
||||
_, completedA, aReadErr = connA.Read(readCtxA)
|
||||
if aReadErr != nil {
|
||||
break
|
||||
}
|
||||
require.Equal(t, "resp_thread_a", gjson.GetBytes(completedA, "response.id").String())
|
||||
if threadA != threadB {
|
||||
break
|
||||
}
|
||||
// 抢占关闭帧异步发送,已在飞的响应可能先到达;同线程必须继续读到关闭帧。
|
||||
}
|
||||
cancelA()
|
||||
if aReadErr == nil {
|
||||
require.Equal(t, "resp_thread_a", gjson.GetBytes(completedA, "response.id").String())
|
||||
require.NoError(t, connA.Close(coderws.StatusNormalClosure, "done"))
|
||||
}
|
||||
require.NoError(t, connB.Close(coderws.StatusNormalClosure, "done"))
|
||||
|
||||
Reference in New Issue
Block a user