Skip to content

Commit 0ce8db0

Browse files
committed
fix exponential backoff test handling
Signed-off-by: James Munnelly <[email protected]>
1 parent 60a2d87 commit 0ce8db0

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

manager/manager.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,23 @@ type Manager struct {
367367
// requestNameGenerator generates a new random name for a certificaterequest object
368368
// Defaults to uuid.NewUUID() from k8s.io/apimachinery/pkg/util/uuid.
369369
requestNameGenerator func() string
370+
371+
// doNotUse_CallOnEachIssue is a field used SOLELY for testing, and cannot be configured by external package consumers.
372+
// It is used to perform some action (e.g. counting) each time issue() is called.
373+
// It will be removed as soon as we have actual metrics support in csi-lib, which will allow us to measure
374+
// things like the number of times issue() is called.
375+
// No thread safety is added around this field, and it MUST NOT be used for any implementation logic.
376+
// It should not be used full-stop :).
377+
doNotUse_CallOnEachIssue func()
370378
}
371379

372380
// issue will step through the entire issuance flow for a volume.
373381
func (m *Manager) issue(ctx context.Context, volumeID string) error {
382+
// TODO: remove this code and replace with actual metrics support
383+
if m.doNotUse_CallOnEachIssue != nil {
384+
m.doNotUse_CallOnEachIssue()
385+
}
386+
374387
log := m.log.WithValues("volume_id", volumeID)
375388
log.Info("Processing issuance")
376389

manager/manager_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ func TestManager_ManageVolume_exponentialBackOffRetryOnIssueErrors(t *testing.T)
304304
expectGlobalTimeout := 2 * time.Second
305305

306306
var numOfRetries int32 = 0 // init
307-
308307
opts := newDefaultTestOptions(t)
309308
opts.RenewalBackoffConfig = &wait.Backoff{
310309
Duration: expBackOffDuration,
@@ -313,16 +312,16 @@ func TestManager_ManageVolume_exponentialBackOffRetryOnIssueErrors(t *testing.T)
313312
Jitter: expBackOffJitter,
314313
Steps: expBackOffSteps,
315314
}
316-
opts.ReadyToRequest = func(meta metadata.Metadata) (bool, string) {
317-
// ReadyToRequest will be called by issue()
318-
atomic.AddInt32(&numOfRetries, 1) // run in a goroutine, thus increment it atomically
319-
return true, "" // AlwaysReadyToRequest
320-
}
321315
m, err := NewManager(opts)
322-
m.issueRenewalTimeout = issueRenewalTimeout
323316
if err != nil {
324317
t.Fatal(err)
325318
}
319+
m.issueRenewalTimeout = issueRenewalTimeout
320+
// Increment the 'numOfRetries' counter whenever issue() is called.
321+
// TODO: replace usages of this function with reading from metrics.
322+
m.doNotUse_CallOnEachIssue = func() {
323+
atomic.AddInt32(&numOfRetries, 1) // run in a goroutine, thus increment it atomically
324+
}
326325

327326
// Register a new volume with the metadata store
328327
store := opts.MetadataReader.(storage.Interface)
@@ -347,7 +346,7 @@ func TestManager_ManageVolume_exponentialBackOffRetryOnIssueErrors(t *testing.T)
347346

348347
actualNumOfRetries := atomic.LoadInt32(&numOfRetries) // read atomically
349348
if actualNumOfRetries != expectNumOfRetries {
350-
t.Errorf("expect %d of retires, but got %d", expectNumOfRetries, actualNumOfRetries)
349+
t.Errorf("expect %d retires, but got %d", expectNumOfRetries, actualNumOfRetries)
351350
}
352351
}
353352

0 commit comments

Comments
 (0)