@@ -45,6 +45,12 @@ func insertBlockedRow(t *testing.T, dbMap *db.WrappedMap, fc clock.Clock, hash [
4545 test .AssertNotError (t , err , "failed to add test row" )
4646}
4747
48+ func fcBeforeRepLag (clk clock.Clock , bkr * badKeyRevoker ) clock.FakeClock {
49+ fc := clock .NewFake ()
50+ fc .Set (clk .Now ().Add (- bkr .maxExpectedReplicationLag - time .Second ))
51+ return fc
52+ }
53+
4854func TestSelectUncheckedRows (t * testing.T ) {
4955 ctx := context .Background ()
5056
@@ -55,24 +61,30 @@ func TestSelectUncheckedRows(t *testing.T) {
5561 fc := clock .NewFake ()
5662
5763 bkr := & badKeyRevoker {
58- dbMap : dbMap ,
59- logger : blog .NewMock (),
60- clk : fc ,
64+ dbMap : dbMap ,
65+ logger : blog .NewMock (),
66+ clk : fc ,
67+ maxExpectedReplicationLag : time .Second * 22 ,
6168 }
6269
6370 hashA , hashB , hashC := randHash (t ), randHash (t ), randHash (t )
71+
72+ // insert a blocked key that's marked as already checked
6473 insertBlockedRow (t , dbMap , fc , hashA , 1 , true )
6574 count , err := bkr .countUncheckedKeys (ctx )
6675 test .AssertNotError (t , err , "countUncheckedKeys failed" )
6776 test .AssertEquals (t , count , 0 )
6877 _ , err = bkr .selectUncheckedKey (ctx )
6978 test .AssertError (t , err , "selectUncheckedKey didn't fail with no rows to process" )
7079 test .Assert (t , db .IsNoRows (err ), "returned error is not sql.ErrNoRows" )
71- insertBlockedRow (t , dbMap , fc , hashB , 1 , false )
80+
81+ // insert a blocked key that's due to be checked
82+ insertBlockedRow (t , dbMap , fcBeforeRepLag (fc , bkr ), hashB , 1 , false )
83+ // insert a freshly blocked key, so it's not yet due to be checked
7284 insertBlockedRow (t , dbMap , fc , hashC , 1 , false )
7385 count , err = bkr .countUncheckedKeys (ctx )
7486 test .AssertNotError (t , err , "countUncheckedKeys failed" )
75- test .AssertEquals (t , count , 2 )
87+ test .AssertEquals (t , count , 1 )
7688 row , err := bkr .selectUncheckedKey (ctx )
7789 test .AssertNotError (t , err , "selectUncheckKey failed" )
7890 test .AssertByteEquals (t , row .KeyHash , hashB )
@@ -191,7 +203,13 @@ func TestFindUnrevokedNoRows(t *testing.T) {
191203 )
192204 test .AssertNotError (t , err , "failed to insert test keyHashToSerial row" )
193205
194- bkr := & badKeyRevoker {dbMap : dbMap , serialBatchSize : 1 , maxRevocations : 10 , clk : fc }
206+ bkr := & badKeyRevoker {
207+ dbMap : dbMap ,
208+ serialBatchSize : 1 ,
209+ maxRevocations : 10 ,
210+ clk : fc ,
211+ maxExpectedReplicationLag : time .Second * 22 ,
212+ }
195213 _ , err = bkr .findUnrevoked (ctx , uncheckedBlockedKey {KeyHash : hashA })
196214 test .Assert (t , db .IsNoRows (err ), "expected NoRows error" )
197215}
@@ -207,7 +225,13 @@ func TestFindUnrevoked(t *testing.T) {
207225
208226 regID := insertRegistration (t , dbMap , fc )
209227
210- bkr := & badKeyRevoker {dbMap : dbMap , serialBatchSize : 1 , maxRevocations : 10 , clk : fc }
228+ bkr := & badKeyRevoker {
229+ dbMap : dbMap ,
230+ serialBatchSize : 1 ,
231+ maxRevocations : 10 ,
232+ clk : fc ,
233+ maxExpectedReplicationLag : time .Second * 22 ,
234+ }
211235
212236 hashA := randHash (t )
213237 // insert valid, unexpired
@@ -251,7 +275,11 @@ func TestRevokeCerts(t *testing.T) {
251275
252276 fc := clock .NewFake ()
253277 mr := & mockRevoker {}
254- bkr := & badKeyRevoker {dbMap : dbMap , raClient : mr , clk : fc }
278+ bkr := & badKeyRevoker {
279+ dbMap : dbMap ,
280+ raClient : mr ,
281+ clk : fc ,
282+ }
255283
256284 err = bkr .revokeCerts ([]unrevokedCertificate {
257285 {ID : 0 , Serial : "ff" },
@@ -269,11 +297,20 @@ func TestCertificateAbsent(t *testing.T) {
269297 defer test .ResetBoulderTestDatabase (t )()
270298
271299 fc := clock .NewFake ()
300+ bkr := & badKeyRevoker {
301+ dbMap : dbMap ,
302+ maxRevocations : 1 ,
303+ serialBatchSize : 1 ,
304+ raClient : & mockRevoker {},
305+ logger : blog .NewMock (),
306+ clk : fc ,
307+ maxExpectedReplicationLag : time .Second * 22 ,
308+ }
272309
273310 // populate DB with all the test data
274311 regIDA := insertRegistration (t , dbMap , fc )
275312 hashA := randHash (t )
276- insertBlockedRow (t , dbMap , fc , hashA , regIDA , false )
313+ insertBlockedRow (t , dbMap , fcBeforeRepLag ( fc , bkr ) , hashA , regIDA , false )
277314
278315 // Add an entry to keyHashToSerial but not to certificateStatus or certificate
279316 // status, and expect an error.
@@ -286,14 +323,6 @@ func TestCertificateAbsent(t *testing.T) {
286323 )
287324 test .AssertNotError (t , err , "failed to insert test keyHashToSerial row" )
288325
289- bkr := & badKeyRevoker {
290- dbMap : dbMap ,
291- maxRevocations : 1 ,
292- serialBatchSize : 1 ,
293- raClient : & mockRevoker {},
294- logger : blog .NewMock (),
295- clk : fc ,
296- }
297326 _ , err = bkr .invoke (ctx )
298327 test .AssertError (t , err , "expected error when row in keyHashToSerial didn't have a matching cert" )
299328}
@@ -309,12 +338,13 @@ func TestInvoke(t *testing.T) {
309338
310339 mr := & mockRevoker {}
311340 bkr := & badKeyRevoker {
312- dbMap : dbMap ,
313- maxRevocations : 10 ,
314- serialBatchSize : 1 ,
315- raClient : mr ,
316- logger : blog .NewMock (),
317- clk : fc ,
341+ dbMap : dbMap ,
342+ maxRevocations : 10 ,
343+ serialBatchSize : 1 ,
344+ raClient : mr ,
345+ logger : blog .NewMock (),
346+ clk : fc ,
347+ maxExpectedReplicationLag : time .Second * 22 ,
318348 }
319349
320350 // populate DB with all the test data
@@ -323,7 +353,7 @@ func TestInvoke(t *testing.T) {
323353 regIDC := insertRegistration (t , dbMap , fc )
324354 regIDD := insertRegistration (t , dbMap , fc )
325355 hashA := randHash (t )
326- insertBlockedRow (t , dbMap , fc , hashA , regIDC , false )
356+ insertBlockedRow (t , dbMap , fcBeforeRepLag ( fc , bkr ) , hashA , regIDC , false )
327357 insertGoodCert (t , dbMap , fc , hashA , "ff" , regIDA )
328358 insertGoodCert (t , dbMap , fc , hashA , "ee" , regIDB )
329359 insertGoodCert (t , dbMap , fc , hashA , "dd" , regIDC )
@@ -344,7 +374,7 @@ func TestInvoke(t *testing.T) {
344374
345375 // add a row with no associated valid certificates
346376 hashB := randHash (t )
347- insertBlockedRow (t , dbMap , fc , hashB , regIDC , false )
377+ insertBlockedRow (t , dbMap , fcBeforeRepLag ( fc , bkr ) , hashB , regIDC , false )
348378 insertCert (t , dbMap , fc , hashB , "bb" , regIDA , Expired , Revoked )
349379
350380 noWork , err = bkr .invoke (ctx )
@@ -375,11 +405,12 @@ func TestInvokeRevokerHasNoExtantCerts(t *testing.T) {
375405
376406 mr := & mockRevoker {}
377407 bkr := & badKeyRevoker {dbMap : dbMap ,
378- maxRevocations : 10 ,
379- serialBatchSize : 1 ,
380- raClient : mr ,
381- logger : blog .NewMock (),
382- clk : fc ,
408+ maxRevocations : 10 ,
409+ serialBatchSize : 1 ,
410+ raClient : mr ,
411+ logger : blog .NewMock (),
412+ clk : fc ,
413+ maxExpectedReplicationLag : time .Second * 22 ,
383414 }
384415
385416 // populate DB with all the test data
@@ -389,7 +420,7 @@ func TestInvokeRevokerHasNoExtantCerts(t *testing.T) {
389420
390421 hashA := randHash (t )
391422
392- insertBlockedRow (t , dbMap , fc , hashA , regIDA , false )
423+ insertBlockedRow (t , dbMap , fcBeforeRepLag ( fc , bkr ) , hashA , regIDA , false )
393424
394425 insertGoodCert (t , dbMap , fc , hashA , "ee" , regIDB )
395426 insertGoodCert (t , dbMap , fc , hashA , "dd" , regIDB )
0 commit comments