-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcollectionresolver_cached_test.go
More file actions
713 lines (603 loc) · 20.2 KB
/
collectionresolver_cached_test.go
File metadata and controls
713 lines (603 loc) · 20.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
package gocbcorex
import (
"context"
"errors"
"fmt"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// We expect to see a single get cid be dispatched for n requests, and then all the callbacks
// called with the cid.
func TestCollectionResolverCachedNCallsOneCollection(t *testing.T) {
var called uint32
collection := uuid.NewString()
scope := uuid.NewString()
manifestRev := uint64(4)
cid := uint32(9)
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
called++
assert.Equal(t, scope, scopeName)
assert.Equal(t, collection, collectionName)
assert.NotNil(t, ctx)
return cid, manifestRev, nil
}}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
var wg sync.WaitGroup
numReqs := 10
for i := 0; i < numReqs; i++ {
wg.Add(1)
go func() {
u, mRev, err := resolver.ResolveCollectionID(context.Background(), scope, collection)
assert.Nil(t, err)
assert.Equal(t, cid, u)
assert.Equal(t, manifestRev, mRev)
wg.Done()
}()
}
wg.Wait()
assert.Equal(t, uint32(1), called)
}
// We expect to see 2 get cids be dispatched for n requests, and then all the callbacks
// called with the cids.
func TestCollectionResolverNCallsNCollections(t *testing.T) {
var called uint32
collection1 := uuid.NewString()
scope1 := uuid.NewString()
collection2 := uuid.NewString()
scope2 := uuid.NewString()
cid1 := uint32(9)
cid2 := uint32(10)
manifestRev := uint64(4)
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
atomic.AddUint32(&called, 1)
assert.NotNil(t, ctx)
if scopeName == scope1 && collectionName == collection1 {
return cid1, manifestRev, nil
} else if scopeName == scope2 && collectionName == collection2 {
return cid2, manifestRev, nil
} else {
t.Fatalf("Collection and scope par unknown: %s.%s", scopeName, collectionName)
}
return 0, 0, errors.New("code should be unreachable")
}}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
var wg sync.WaitGroup
numReqs := 10
for i := 0; i < numReqs; i++ {
wg.Add(1)
go func(i int) {
if i%2 == 0 {
u, mRev, err := resolver.ResolveCollectionID(context.Background(), scope1, collection1)
assert.Nil(t, err)
assert.Equal(t, cid1, u)
assert.Equal(t, manifestRev, mRev)
wg.Done()
} else {
u, mRev, err := resolver.ResolveCollectionID(context.Background(), scope2, collection2)
assert.Nil(t, err)
assert.Equal(t, cid2, u)
assert.Equal(t, manifestRev, mRev)
wg.Done()
}
}(i)
}
wg.Wait()
assert.Equal(t, uint32(2), called)
}
func TestCollectionManagerDispatchErrors(t *testing.T) {
var called atomic.Uint32
collection := uuid.NewString()
scope := uuid.NewString()
cbErr := errors.New("some error")
// gate1/gate2 let the test synchronize with the first two mock
// invocations. Any additional calls (from late-arriving goroutines
// under scheduler pressure) pass through without blocking.
gate1 := make(chan struct{})
gate1Called := make(chan struct{})
gate2 := make(chan struct{})
gate2Called := make(chan struct{})
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
n := called.Add(1)
assert.Equal(t, scope, scopeName)
assert.Equal(t, collection, collectionName)
assert.NotNil(t, ctx)
switch n {
case 1:
close(gate1Called)
<-gate1
case 2:
close(gate2Called)
<-gate2
}
return 0, 0, cbErr
}}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
var wg sync.WaitGroup
numReqs := 10
// Start goroutine 1 to create the entry and spawn the resolve
// thread.
wg.Add(1)
go func() {
u, mRev, err := resolver.ResolveCollectionID(context.Background(), scope, collection)
assert.Equal(t, cbErr, err)
assert.Equal(t, uint32(0), u)
assert.Equal(t, uint64(0), mRev)
wg.Done()
}()
// Wait for the first resolve thread to enter the mock. Its
// time.Now() has already been captured.
<-gate1Called
// Start goroutines 2-10. Their time.Now() calls in
// resolveCollectionIDSlow are guaranteed to return a time after
// the resolve thread's requestedAt because we only start them
// after the resolve thread is blocked inside the mock.
for i := 1; i < numReqs; i++ {
wg.Add(1)
go func() {
u, mRev, err := resolver.ResolveCollectionID(context.Background(), scope, collection)
assert.Equal(t, cbErr, err)
assert.Equal(t, uint32(0), u)
assert.Equal(t, uint64(0), mRev)
wg.Done()
}()
}
// Give goroutines 2-10 time to enter resolveCollectionIDSlow
// and wait on PendingCh. Since the resolve thread is still
// blocked in the mock, PendingCh is open, so any goroutine
// that has entered the slow path is waiting on it.
time.Sleep(50 * time.Millisecond)
// Unblock call 1. Waiting goroutines will see the error,
// detect their requestedAt is after the entry's, and retry —
// coalescing into a second resolution (call 2).
close(gate1)
// Wait for the coalesced retry to enter the mock, then unblock.
<-gate2Called
close(gate2)
wg.Wait()
// We expect at least 2 calls: the initial failure plus at least
// one coalesced retry. Under scheduler pressure, a few extra
// calls may occur from goroutines that hadn't entered the slow
// path before call 1 completed.
assert.GreaterOrEqual(t, called.Load(), uint32(2))
}
func TestCollectionResolverCachedKnownCollection(t *testing.T) {
scope := uuid.NewString()
collection := uuid.NewString()
manifestRev := uint64(4)
fqCollectionName := scope + "." + collection
cid := uint32(12)
var called int
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
called++
return 0, 0, errors.New("should not have reached here")
}}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
manifest := &collectionsFastManifest{
collections: map[string]collectionsFastCacheEntry{
fqCollectionName: {
CollectionID: cid,
ManifestRev: manifestRev,
},
},
}
resolver.fastCache.Store(manifest)
waitCh := make(chan struct{}, 1)
go func() {
u, mRev, err := resolver.ResolveCollectionID(context.Background(), scope, collection)
assert.Nil(t, err)
assert.Equal(t, uint32(12), u)
assert.Equal(t, manifestRev, mRev)
waitCh <- struct{}{}
}()
<-waitCh
assert.Zero(t, called)
}
// We expect an unknown collection with a newer manifest rev to remove the collection from the cache, and send a get
// cid. Any further requests should get queued.
func TestCollectionResolverUnknownCollectionNewerManifestRev(t *testing.T) {
collection := uuid.NewString()
scope := uuid.NewString()
baseCollectionId := uint32(17)
baseManifestRev := uint64(7)
resolveCount := 0
invalidateCount := 0
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
resolveCount++
return baseCollectionId + uint32(invalidateCount), baseManifestRev + uint64(invalidateCount), nil
},
InvalidateCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string, endpoint string, manifestRev uint64) {
invalidateCount++
},
}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
firstCid, firstManifestRev, err := resolver.ResolveCollectionID(context.Background(), scope, collection)
require.NoError(t, err)
require.Equal(t, 1, resolveCount)
require.Equal(t, baseCollectionId, firstCid)
require.Equal(t, baseManifestRev, firstManifestRev)
resolver.InvalidateCollectionID(context.Background(), scope, collection, "", 100)
require.Equal(t, 1, invalidateCount)
cid, mRev, err := resolver.ResolveCollectionID(context.Background(), scope, collection)
assert.Nil(t, err)
assert.Equal(t, baseCollectionId+1, cid)
assert.Equal(t, baseManifestRev+1, mRev)
require.Equal(t, 2, resolveCount)
}
// We expect an unknown collection with a older manifest rev to not send any requests.
func TestCollectionsResolverUnknownCollectionOlderManifestRev(t *testing.T) {
collection := uuid.NewString()
scope := uuid.NewString()
fqCollectionName := fmt.Sprintf("%s.%s", scope, collection)
cid := uint32(15)
manifestRev := uint64(4)
var called int
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
called++
return 0, 0, errors.New("should be unreachable")
},
InvalidateCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string, endpoint string, manifestRev uint64) {
},
}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
manifest := &collectionsFastManifest{
collections: map[string]collectionsFastCacheEntry{
fqCollectionName: {
CollectionID: cid,
ManifestRev: manifestRev,
},
},
}
resolver.fastCache.Store(manifest)
resolver.slowMap = map[string]*collectionCacheEntry{
fqCollectionName: {
CollectionID: cid,
ManifestRev: manifestRev,
},
}
resolver.InvalidateCollectionID(context.Background(), scope, collection, "endpoint1", 3)
cols := resolver.fastCache.Load().collections
assert.Len(t, cols, 1)
assert.Equal(t, manifestRev, cols[fqCollectionName].ManifestRev)
assert.Equal(t, cid, cols[fqCollectionName].CollectionID)
slowMap := resolver.slowMap
assert.Len(t, slowMap, 1)
assert.Equal(t, manifestRev, slowMap[fqCollectionName].ManifestRev)
assert.Equal(t, cid, slowMap[fqCollectionName].CollectionID)
}
// We expect an unknown collection with a older manifest rev to panic.
// func TestCollectionsManagerUnknownCollectionSameManifestRev(t *testing.T) {
// collection := uuid.NewString()
// scope := uuid.NewString()
// fqCollectionName := fmt.Sprintf("%s.%s", scope, collection)
// cliCb := func(req *memdx.Packet, handler memdx.DispatchCallback) error {
// go func() {
// t.Error("Should not have reached here")
// handler(nil, errors.New("nope"))
// }()
// return nil
// }
// client := &fakeKvClient{
// onCall: cliCb,
// }
// router := &fakeConnManager{
// cli: client,
// }
// resolver := newCollectionResolver(router)
// manifest := &collectionsManifest{
// collections: map[string]*collectionsManifestEntry{
// fqCollectionName: {
// cid: 12,
// rev: 4,
// },
// },
// }
// resolver.storeManifest(resolver.loadManifest(), manifest)
//
// assert.Panics(t, func() {
// resolver.InvalidateCollectionID(context.Background(), scope, collection, "endpoint1", 4)
// })
// }
func TestCollectionResolverCancelContext(t *testing.T) {
var called uint32
collection := uuid.NewString()
scope := uuid.NewString()
calledCh := make(chan struct{}, 1)
blockCh := make(chan struct{}, 1)
cid := uint32(15)
manifestRev := uint64(4)
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
called++
close(calledCh)
assert.Equal(t, scope, scopeName)
assert.Equal(t, collection, collectionName)
assert.NotNil(t, ctx)
<-blockCh
return cid, manifestRev, nil
},
}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, _, err = resolver.ResolveCollectionID(ctx, scope, collection)
assert.Equal(t, context.Canceled, err)
<-calledCh
close(blockCh)
assert.Equal(t, uint32(1), called)
}
func TestCollectionResolverTimeoutContext(t *testing.T) {
var called uint32
collection := uuid.NewString()
scope := uuid.NewString()
calledCh := make(chan struct{}, 1)
blockCh := make(chan struct{}, 1)
cid := uint32(15)
manifestRev := uint64(4)
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
called++
close(calledCh)
assert.Equal(t, scope, scopeName)
assert.Equal(t, collection, collectionName)
assert.NotNil(t, ctx)
<-blockCh
return cid, manifestRev, nil
},
}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond)
_, _, err = resolver.ResolveCollectionID(ctx, scope, collection)
cancel()
assert.ErrorIs(t, err, ErrStillResolvingCollection)
assert.ErrorIs(t, err, context.DeadlineExceeded)
<-calledCh
close(blockCh)
assert.Equal(t, uint32(1), called)
}
func TestCollectionResolverCancelContextMultipleOps(t *testing.T) {
var called uint32
collection := uuid.NewString()
scope := uuid.NewString()
cid := uint32(15)
manifestRev := uint64(4)
blockCh := make(chan struct{}, 1)
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
<-blockCh
called++
assert.Equal(t, scope, scopeName)
assert.Equal(t, collection, collectionName)
assert.NotNil(t, ctx)
return cid, manifestRev, nil
},
}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
var wg sync.WaitGroup
var cancelGroup sync.WaitGroup
numReqs := 10
var toCancel []context.CancelFunc
for i := 0; i < numReqs; i++ {
var willCancel bool
var ctx context.Context
if i%2 == 0 {
cancelGroup.Add(1)
var cancel context.CancelFunc
ctx, cancel = context.WithCancel(context.Background())
toCancel = append(toCancel, cancel)
willCancel = true
} else {
wg.Add(1)
ctx = context.Background()
}
go func(hasCanceled bool) {
u, mRev, err := resolver.ResolveCollectionID(ctx, scope, collection)
if willCancel {
assert.Equal(t, context.Canceled, err)
cancelGroup.Done()
} else {
assert.Equal(t, cid, u)
assert.Equal(t, manifestRev, mRev)
wg.Done()
}
}(willCancel)
}
for _, cancel := range toCancel {
cancel()
}
cancelGroup.Wait()
close(blockCh)
wg.Wait()
assert.Equal(t, uint32(1), called)
}
func TestCollectionsManagerCancelContextAllOps(t *testing.T) {
var called uint32
collection := uuid.NewString()
scope := uuid.NewString()
cid := uint32(9)
manifestRev := uint64(4)
blockCh := make(chan struct{})
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
blockCh <- struct{}{}
called++
assert.Equal(t, scope, scopeName)
assert.Equal(t, collection, collectionName)
assert.NotNil(t, ctx)
<-blockCh
return cid, manifestRev, nil
},
}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
var wg sync.WaitGroup
numReqs := 10
ctx, cancel := context.WithCancel(context.Background())
for i := 0; i < numReqs; i++ {
wg.Add(1)
go func() {
_, _, err := resolver.ResolveCollectionID(ctx, scope, collection)
assert.Equal(t, context.Canceled, err)
wg.Done()
}()
}
// Wait for the resolve collection id op to be sent.
<-blockCh
cancel()
wg.Wait()
// We block the resolve collection id op from completing until we've received a response
// for all of our requests.
blockCh <- struct{}{}
assert.Equal(t, uint32(1), called)
}
func TestCollectionsManagerInvalidateTwice(t *testing.T) {
collection := uuid.NewString()
scope := uuid.NewString()
cid := uint32(15)
manifestRev := uint64(4)
var callCount atomic.Uint32
// calledCh is signaled each time the mock is entered.
// blockCh gates each resolver call so the test can control timing.
calledCh := make(chan struct{}, 1)
blockCh := make(chan struct{})
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
callCount.Add(1)
calledCh <- struct{}{}
<-blockCh
return cid, manifestRev, nil
},
InvalidateCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string, endpoint string, manifestRev uint64) {
},
}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
// Step 1: Resolve the collection for the first time to populate the cache.
// The mock blocks until we signal, ensuring we control the timing.
resultCh := make(chan error, 1)
go func() {
u, mRev, err := resolver.ResolveCollectionID(context.Background(), scope, collection)
if err == nil {
assert.Equal(t, cid, u)
assert.Equal(t, manifestRev, mRev)
}
resultCh <- err
}()
// Wait for the resolver to be called, then unblock it.
<-calledCh
require.Equal(t, uint32(1), callCount.Load())
blockCh <- struct{}{}
require.NoError(t, <-resultCh)
// Step 2: Invalidate the collection. This spawns a new resolve thread
// that will block on blockCh (call #2).
resolver.InvalidateCollectionID(context.Background(), scope, collection, "endpoint1", 5)
// Wait for the re-resolve thread to call the resolver and block.
<-calledCh
require.Equal(t, uint32(2), callCount.Load())
// Step 3: Invalidate again while the resolve thread is active.
// Since DoneCh != nil, this should be a no-op.
resolver.InvalidateCollectionID(context.Background(), scope, collection, "endpoint1", 6)
// Unblock the re-resolve and verify the result.
go func() {
u, mRev, err := resolver.ResolveCollectionID(context.Background(), scope, collection)
if err == nil {
assert.Equal(t, cid, u)
assert.Equal(t, manifestRev, mRev)
}
resultCh <- err
}()
blockCh <- struct{}{}
require.NoError(t, <-resultCh)
// The second invalidation should not have spawned a new resolve thread,
// so the total call count should be exactly 2.
require.Equal(t, uint32(2), callCount.Load())
}
// We expect that when a collection resolution fails (e.g. the collection does
// not exist), the error is returned to the caller. When a subsequent request
// comes in (e.g. after the collection has been created), it should trigger a
// fresh resolution rather than returning the stale cached error.
func TestCollectionResolverCachedRecoveryAfterError(t *testing.T) {
collection := uuid.NewString()
scope := uuid.NewString()
cbErr := errors.New("unknown collection name")
cid := uint32(9)
manifestRev := uint64(4)
var callCount atomic.Uint32
mock := &CollectionResolverMock{
ResolveCollectionIDFunc: func(ctx context.Context, scopeName string, collectionName string) (uint32, uint64, error) {
call := callCount.Add(1)
if call == 1 {
return 0, 0, cbErr
}
return cid, manifestRev, nil
},
}
resolver, err := NewCollectionResolverCached(&CollectionResolverCachedOptions{
Resolver: mock,
ResolveTimeout: 10 * time.Second,
})
require.NoError(t, err)
// First resolve triggers a resolution which will fail. The caller's
// requestedAt predates the error, so this returns the error.
_, _, err = resolver.ResolveCollectionID(context.Background(), scope, collection)
require.ErrorIs(t, err, cbErr)
// A subsequent resolve (whose requestedAt postdates the error) should
// trigger a fresh resolution, which now succeeds.
resolvedCid, resolvedManifestRev, err := resolver.ResolveCollectionID(context.Background(), scope, collection)
require.NoError(t, err)
require.Equal(t, cid, resolvedCid)
require.Equal(t, manifestRev, resolvedManifestRev)
require.Equal(t, uint32(2), callCount.Load())
}