diff --git a/modules/mesh-delivery-watchman/internal/watch/waits.go b/modules/mesh-delivery-watchman/internal/watch/waits.go index 34fc9f599..24b7d0068 100644 --- a/modules/mesh-delivery-watchman/internal/watch/waits.go +++ b/modules/mesh-delivery-watchman/internal/watch/waits.go @@ -78,12 +78,22 @@ func (w *Watchman) putStands(id string, a meshwants.Wait, bound time.Duration, f ", so the node's want is not at the build that was put.", Needs: "the put to go on, or released by hand (assigner_release)"} left := bound - w.now().Sub(from) - w.unsignal(actingRow, id) - w.unfind(f.Key()) if left > 0 { - w.signal(actingRow, id, left, signalDue{Do: dueFind, Finding: f}) + // A wait held again as it stands, its pulse standing for the same finding and none raised, changes nothing (design 47 H + // §832 5., H-A-856): the assigner says an owed event again, and a repeat is no new pulse. + due := signalDue{Do: dueFind, Finding: f} + if held, ok := w.signals[signalKey(actingRow, id)]; ok && sameDue(held, due) { + if _, raised := w.findings[f.Key()]; !raised { + return + } + } + w.unsignal(actingRow, id) + w.unfind(f.Key()) + w.signal(actingRow, id, left, due) return } + // Past its bound: the finding is written when it differs from the one the bucket holds, so a repeat clears and raises nothing. + w.unsignal(actingRow, id) w.find(f) } @@ -151,3 +161,10 @@ func (w *Watchman) EngineWaitEnded(node, module string) { w.unsignal(engineRow, id) w.unfind(FindingKey(ScopeDelivery, id, KindKeptBuildWaits)) } + +// sameDue says whether two signals' expiries do the same thing for the same finding. +func sameDue(a, b signalDue) bool { + x, err := json.Marshal(a) + y, err2 := json.Marshal(b) + return err == nil && err2 == nil && string(x) == string(y) +} diff --git a/modules/mesh-delivery-watchman/internal/watch/waits_test.go b/modules/mesh-delivery-watchman/internal/watch/waits_test.go index 611bb38da..6326baf91 100644 --- a/modules/mesh-delivery-watchman/internal/watch/waits_test.go +++ b/modules/mesh-delivery-watchman/internal/watch/waits_test.go @@ -26,18 +26,37 @@ func TestAPutWithoutHoldThatStandsIsPutStands(t *testing.T) { if len(o.findings) != 0 || len(o.pulses) != 0 { t.Fatalf("an acting part's wait is timed: findings %v, pulses %v", o.findings, o.pulses) } - w.WaitHeld("mesh-wants", put(c.t)) + held := put(c.t) + w.WaitHeld("mesh-wants", held) if len(o.findings) != 0 { t.Fatalf("within the bound: %v", o.findings) } + // A repeated wait-held, under its id or a new one, changes nothing (design 47 H §832 5., H-A-856, AC-832n): its pulse stands + // as it was written, never deleted and written again. + deletes := len(o.pulseDeletes) + w.WaitHeld("mesh-wants", held) + if len(o.pulseDeletes) != deletes { + t.Fatalf("a repeated wait-held deleted its pulse again: %v", o.pulseDeletes) + } expire(w, c, signalKey(actingRow, id), 30*time.Minute) if _, ok := o.findings[FindingKey(ScopeDelivery, id, KindPutStands)]; !ok || len(o.findings) != 1 { t.Fatalf("past its bound: %v", o.findings) } - w.WaitEnded("mesh-wants", put(c.t)) + // Past its bound, a repeat neither clears nor raises put-stands again. + writes := o.findingWrites + w.WaitHeld("mesh-wants", held) + if o.findingWrites != writes || len(o.findings) != 1 { + t.Fatalf("a repeated wait-held past its bound wrote the finding again: %d writes, was %d", o.findingWrites, writes) + } + w.WaitEnded("mesh-wants", held) if len(o.findings) != 0 { t.Fatalf("wait-ended left %v", o.findings) } + deletes = len(o.pulseDeletes) + w.WaitEnded("mesh-wants", held) + if len(o.pulseDeletes) != deletes || len(o.findings) != 0 { + t.Fatalf("a repeated wait-ended wrote again: %v", o.pulseDeletes) + } } // design 47 G §499, §541 (WM5): a node-engine's wait for a kept build standing 60 minutes is `kept-build-waits` naming the node,