@@ -122,77 +122,6 @@ func TestBenchlist(t *testing.T) {
122122 requireBenched ()
123123}
124124
125- // Regression test: when observe() detects that a bench has expired via the
126- // mock clock (before the consumer's real-time timer fires) and the EWMA
127- // immediately re-benches the node, the consumer must not send a duplicate
128- // Benched notification. The benchable.Benched() assertion
129- // (require.NotContains) would fail if the guard were missing.
130- func TestBenchlistNoDuplicateBench (t * testing.T ) {
131- require := require .New (t )
132-
133- snowCtx := snowtest .Context (t , snowtest .CChainID )
134- ctx := snowtest .ConsensusContext (snowCtx )
135- vdrs := validators .NewManager ()
136- vdrID := ids .GenerateTestNodeID ()
137-
138- require .NoError (vdrs .AddStaker (ctx .SubnetID , vdrID , nil , ids .Empty , 1 ))
139-
140- benchable := & benchable {
141- t : t ,
142- wantChainID : ctx .ChainID ,
143- updated : make (chan struct {}, 1 ),
144- }
145- b , err := newBenchlist (
146- ctx ,
147- benchable ,
148- vdrs ,
149- Config {
150- Halflife : DefaultHalflife ,
151- UnbenchProbability : DefaultUnbenchProbability ,
152- BenchProbability : DefaultBenchProbability ,
153- BenchDuration : 10 * time .Second ,
154- },
155- prometheus .NewRegistry (),
156- )
157- require .NoError (err )
158-
159- now := time .Now ()
160- b .clock .Set (now )
161-
162- // Bench the node: p = 2/3 > 0.5
163- b .RegisterResponse (vdrID )
164- b .RegisterFailure (vdrID )
165- b .RegisterFailure (vdrID )
166- <- benchable .updated
167- require .True (b .IsBenched (vdrID ))
168-
169- // Advance the mock clock past the bench duration. The real-time timer
170- // has NOT fired, so the consumer still considers the node benched.
171- now = now .Add (11 * time .Second )
172- b .clock .Set (now )
173- require .False (b .IsBenched (vdrID ))
174-
175- // Register a failure. observe() detects the bench expired, clears
176- // isBenched, resets the EWMA to a clean slate, then observes the
177- // failure (p = 1.0 > 0.5) and immediately re-benches.
178- // This sends a bench job for a node the consumer already considers
179- // benched. Without the duplicate-bench guard, the consumer would call
180- // benchable.Benched() again, failing the require.NotContains assertion.
181- b .RegisterFailure (vdrID )
182- require .True (b .IsBenched (vdrID ))
183-
184- // Drive the probability below unbenchProbability to trigger an EWMA
185- // unbench. Since jobs are FIFO, when we receive the unbench
186- // notification we know the re-bench job above was already processed
187- // (without a duplicate Benched call).
188- for range 20 {
189- b .RegisterResponse (vdrID )
190- }
191- <- benchable .updated
192- require .False (b .IsBenched (vdrID ))
193- require .Empty (benchable .benched )
194- }
195-
196125func TestBenchlistTimeout (t * testing.T ) {
197126 require := require .New (t )
198127
@@ -232,15 +161,10 @@ func TestBenchlistTimeout(t *testing.T) {
232161 <- benchable .updated
233162 require .True (b .IsBenched (vdrID ))
234163
235- // Advance the mock clock past the bench duration so IsBenched returns
236- // false immediately.
237- now = now .Add (100 * time .Millisecond )
238- b .clock .Set (now )
239- require .False (b .IsBenched (vdrID ))
240-
241164 // The consumer goroutine's timer also fires (real time ≥ 50ms) and calls
242165 // Unbenched on the benchable.
243166 <- benchable .updated
167+ require .False (b .IsBenched (vdrID ))
244168 require .Empty (benchable .benched )
245169}
246170
@@ -271,7 +195,7 @@ func TestBenchlistTimeoutCleansSlate(t *testing.T) {
271195 Halflife : DefaultHalflife ,
272196 UnbenchProbability : DefaultUnbenchProbability ,
273197 BenchProbability : DefaultBenchProbability ,
274- BenchDuration : 10 * time .Second ,
198+ BenchDuration : 50 * time .Millisecond ,
275199 },
276200 prometheus .NewRegistry (),
277201 )
@@ -287,9 +211,8 @@ func TestBenchlistTimeoutCleansSlate(t *testing.T) {
287211 <- benchable .updated
288212 require .True (b .IsBenched (vdrID ))
289213
290- // Advance past the bench duration so the bench expires.
291- now = now .Add (11 * time .Second )
292- b .clock .Set (now )
214+ // Wait for timeout-based unbench.
215+ <- benchable .updated
293216 require .False (b .IsBenched (vdrID ))
294217
295218 // Register a response followed by a failure. With a clean slate, p = 1/2
0 commit comments