test: cover dispatch loss and workflow commit fault boundaries
This commit is contained in:
@@ -53,6 +53,9 @@ type workerFaultGateway struct {
|
||||
target atomic.Value
|
||||
dropOffline atomic.Bool
|
||||
dropCancel atomic.Bool
|
||||
holdAssignment atomic.Bool
|
||||
assignmentsHeld chan WorkerAssignment
|
||||
releaseAssignment chan struct{}
|
||||
offline atomic.Bool
|
||||
mu sync.Mutex
|
||||
active map[*websocket.Conn]struct{}
|
||||
@@ -66,7 +69,7 @@ func newWorkerFaultGateway(t *testing.T, upstream string) *workerFaultGateway {
|
||||
|
||||
func newProtocolFaultGateway(t *testing.T, upstream, path, protocol string) *workerFaultGateway {
|
||||
t.Helper()
|
||||
g := &workerFaultGateway{dropped: make(chan string, 4), active: make(map[*websocket.Conn]struct{})}
|
||||
g := &workerFaultGateway{dropped: make(chan string, 4), active: make(map[*websocket.Conn]struct{}), assignmentsHeld: make(chan WorkerAssignment, 1), releaseAssignment: make(chan struct{})}
|
||||
g.drop.Store("")
|
||||
g.target.Store(upstream)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@@ -150,6 +153,20 @@ func newProtocolFaultGateway(t *testing.T, upstream, path, protocol string) *wor
|
||||
g.dropped <- "task.cancel"
|
||||
return
|
||||
}
|
||||
if f.Type == "task.assign" && g.holdAssignment.CompareAndSwap(true, false) {
|
||||
var assignment WorkerAssignment
|
||||
if json.Unmarshal(f.Body, &assignment) != nil {
|
||||
return
|
||||
}
|
||||
// 真实派发帧只到隔离网关,不向Worker发送;测试确认节点退出后丢弃。
|
||||
g.offline.Store(true)
|
||||
g.assignmentsHeld <- assignment
|
||||
select {
|
||||
case <-g.releaseAssignment:
|
||||
case <-bridge.Done():
|
||||
}
|
||||
return
|
||||
}
|
||||
if f.Type == "ack" && operation != "" && g.drop.CompareAndSwap(operation, "") {
|
||||
if g.dropOffline.Load() {
|
||||
g.offline.Store(true)
|
||||
|
||||
Reference in New Issue
Block a user