@@ -15,6 +15,7 @@ import (
1515 capb "github.com/letsencrypt/boulder/ca/proto"
1616 corepb "github.com/letsencrypt/boulder/core/proto"
1717 cspb "github.com/letsencrypt/boulder/crl/storer/proto"
18+ "github.com/letsencrypt/boulder/features"
1819 "github.com/letsencrypt/boulder/issuance"
1920 blog "github.com/letsencrypt/boulder/log"
2021 "github.com/letsencrypt/boulder/metrics"
@@ -50,19 +51,27 @@ func (f *fakeGRCC) Recv() (*corepb.CRLEntry, error) {
5051// fakeGRCC to be used as the return value for calls to GetRevokedCerts, and a
5152// fake timestamp to serve as the database's maximum notAfter value.
5253type fakeSAC struct {
53- mocks.StorageAuthorityReadOnly
54+ mocks.StorageAuthority
5455 grcc fakeGRCC
5556 maxNotAfter time.Time
57+ leaseError error
5658}
5759
58- func (f * fakeSAC ) GetRevokedCerts (ctx context.Context , _ * sapb.GetRevokedCertsRequest , _ ... grpc.CallOption ) (sapb.StorageAuthorityReadOnly_GetRevokedCertsClient , error ) {
60+ func (f * fakeSAC ) GetRevokedCerts (ctx context.Context , _ * sapb.GetRevokedCertsRequest , _ ... grpc.CallOption ) (sapb.StorageAuthority_GetRevokedCertsClient , error ) {
5961 return & f .grcc , nil
6062}
6163
6264func (f * fakeSAC ) GetMaxExpiration (_ context.Context , req * emptypb.Empty , _ ... grpc.CallOption ) (* timestamppb.Timestamp , error ) {
6365 return timestamppb .New (f .maxNotAfter ), nil
6466}
6567
68+ func (f * fakeSAC ) LeaseCRLShard (_ context.Context , req * sapb.LeaseCRLShardRequest , _ ... grpc.CallOption ) (* sapb.LeaseCRLShardResponse , error ) {
69+ if f .leaseError != nil {
70+ return nil , f .leaseError
71+ }
72+ return & sapb.LeaseCRLShardResponse {IssuerNameID : req .IssuerNameID , ShardIdx : req .MinShardIdx }, nil
73+ }
74+
6675// fakeGCC is a fake capb.CRLGenerator_GenerateCRLClient which can be
6776// populated with some CRL entries or an error for use as the return value of
6877// a faked GenerateCRL call.
@@ -140,13 +149,15 @@ func TestTickShard(t *testing.T) {
140149 test .AssertNotError (t , err , "loading test issuer" )
141150
142151 sentinelErr := errors .New ("oops" )
152+ ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
153+ defer cancel ()
143154
144155 clk := clock .NewFake ()
145156 clk .Set (time .Date (2020 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC ))
146157 cu , err := NewUpdater (
147158 []* issuance.Certificate {e1 , r3 },
148159 2 , 18 * time .Hour , 24 * time .Hour ,
149- 6 * time .Hour , 1 * time .Minute , 1 , 1 ,
160+ 6 * time .Hour , time .Minute , time . Hour , 1 , 1 ,
150161 & fakeSAC {grcc : fakeGRCC {}, maxNotAfter : clk .Now ().Add (90 * 24 * time .Hour )},
151162 & fakeCGC {gcc : fakeGCC {}},
152163 & fakeCSC {ucc : fakeUCC {}},
@@ -159,16 +170,29 @@ func TestTickShard(t *testing.T) {
159170 }
160171
161172 // Ensure that getting no results from the SA still works.
162- err = cu .tickShard (context . Background () , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
173+ err = cu .tickShard (ctx , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
163174 test .AssertNotError (t , err , "empty CRL" )
164175 test .AssertMetricWithLabelsEquals (t , cu .updatedCounter , prometheus.Labels {
165176 "issuer" : "(TEST) Elegant Elephant E1" , "result" : "success" ,
166177 }, 1 )
167178 cu .updatedCounter .Reset ()
168179
180+ // With leasing enabled, errors while leasing should bubble up early.
181+ _ = features .Set (map [string ]bool {"LeaseCRLShards" : true })
182+ cu .sa .(* fakeSAC ).leaseError = sentinelErr
183+ err = cu .tickShard (ctx , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
184+ test .AssertError (t , err , "leasing error" )
185+ test .AssertContains (t , err .Error (), "leasing shard" )
186+ test .AssertErrorIs (t , err , sentinelErr )
187+ test .AssertMetricWithLabelsEquals (t , cu .updatedCounter , prometheus.Labels {
188+ "issuer" : "(TEST) Elegant Elephant E1" , "result" : "failed" ,
189+ }, 1 )
190+ cu .updatedCounter .Reset ()
191+ features .Reset ()
192+
169193 // Errors closing the Storer upload stream should bubble up.
170194 cu .cs = & fakeCSC {ucc : fakeUCC {recvErr : sentinelErr }}
171- err = cu .tickShard (context . Background () , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
195+ err = cu .tickShard (ctx , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
172196 test .AssertError (t , err , "storer error" )
173197 test .AssertContains (t , err .Error (), "closing CRLStorer upload stream" )
174198 test .AssertErrorIs (t , err , sentinelErr )
@@ -179,7 +203,7 @@ func TestTickShard(t *testing.T) {
179203
180204 // Errors sending to the Storer should bubble up sooner.
181205 cu .cs = & fakeCSC {ucc : fakeUCC {sendErr : sentinelErr }}
182- err = cu .tickShard (context . Background () , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
206+ err = cu .tickShard (ctx , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
183207 test .AssertError (t , err , "storer error" )
184208 test .AssertContains (t , err .Error (), "sending CRLStorer metadata" )
185209 test .AssertErrorIs (t , err , sentinelErr )
@@ -190,7 +214,7 @@ func TestTickShard(t *testing.T) {
190214
191215 // Errors reading from the CA should bubble up sooner.
192216 cu .ca = & fakeCGC {gcc : fakeGCC {recvErr : sentinelErr }}
193- err = cu .tickShard (context . Background () , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
217+ err = cu .tickShard (ctx , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
194218 test .AssertError (t , err , "CA error" )
195219 test .AssertContains (t , err .Error (), "receiving CRL bytes" )
196220 test .AssertErrorIs (t , err , sentinelErr )
@@ -201,7 +225,7 @@ func TestTickShard(t *testing.T) {
201225
202226 // Errors sending to the CA should bubble up sooner.
203227 cu .ca = & fakeCGC {gcc : fakeGCC {sendErr : sentinelErr }}
204- err = cu .tickShard (context . Background () , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
228+ err = cu .tickShard (ctx , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
205229 test .AssertError (t , err , "CA error" )
206230 test .AssertContains (t , err .Error (), "sending CA metadata" )
207231 test .AssertErrorIs (t , err , sentinelErr )
@@ -212,7 +236,7 @@ func TestTickShard(t *testing.T) {
212236
213237 // Errors reading from the SA should bubble up soonest.
214238 cu .sa = & fakeSAC {grcc : fakeGRCC {err : sentinelErr }, maxNotAfter : clk .Now ().Add (90 * 24 * time .Hour )}
215- err = cu .tickShard (context . Background () , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
239+ err = cu .tickShard (ctx , cu .clk .Now (), e1 .NameID (), 0 , testChunks )
216240 test .AssertError (t , err , "database error" )
217241 test .AssertContains (t , err .Error (), "retrieving entry from SA" )
218242 test .AssertErrorIs (t , err , sentinelErr )
@@ -237,7 +261,7 @@ func TestTickShardWithRetry(t *testing.T) {
237261 cu , err := NewUpdater (
238262 []* issuance.Certificate {e1 , r3 },
239263 2 , 18 * time .Hour , 24 * time .Hour ,
240- 6 * time .Hour , 1 * time .Minute , 1 , 1 ,
264+ 6 * time .Hour , time .Minute , time . Hour , 1 , 1 ,
241265 & fakeSAC {grcc : fakeGRCC {err : sentinelErr }, maxNotAfter : clk .Now ().Add (90 * 24 * time .Hour )},
242266 & fakeCGC {gcc : fakeGCC {}},
243267 & fakeCSC {ucc : fakeUCC {}},
@@ -283,7 +307,7 @@ func TestTickIssuer(t *testing.T) {
283307 cu , err := NewUpdater (
284308 []* issuance.Certificate {e1 , r3 },
285309 2 , 18 * time .Hour , 24 * time .Hour ,
286- 6 * time .Hour , 1 * time .Minute , 1 , 1 ,
310+ 6 * time .Hour , time .Minute , time . Hour , 1 , 1 ,
287311 & fakeSAC {grcc : fakeGRCC {err : errors .New ("db no worky" )}, maxNotAfter : clk .Now ().Add (90 * 24 * time .Hour )},
288312 & fakeCGC {gcc : fakeGCC {}},
289313 & fakeCSC {ucc : fakeUCC {}},
@@ -319,7 +343,7 @@ func TestTick(t *testing.T) {
319343 cu , err := NewUpdater (
320344 []* issuance.Certificate {e1 , r3 },
321345 2 , 18 * time .Hour , 24 * time .Hour ,
322- 6 * time .Hour , 1 * time .Minute , 1 , 1 ,
346+ 6 * time .Hour , time .Minute , time . Hour , 1 , 1 ,
323347 & fakeSAC {grcc : fakeGRCC {err : errors .New ("db no worky" )}, maxNotAfter : clk .Now ().Add (90 * 24 * time .Hour )},
324348 & fakeCGC {gcc : fakeGCC {}},
325349 & fakeCSC {ucc : fakeUCC {}},
0 commit comments