Skip to content

Commit

Permalink
Fix order-dependent test
Browse files Browse the repository at this point in the history
Be careful to initialise counters before taking snapshot
  • Loading branch information
hickford committed Aug 9, 2022
1 parent 6d8f0d9 commit 3202101
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
(`*`) by default.
* Updated golangci-lint to v1.47.3 (developers should update to this version)
* Delete merkle package, use [github.com/transparency-dev/merkle](https://pkg.go.dev/github.com/transparency-dev/merkle) instead.
* #2792: Fixed order-dependent unit test.

## v1.4.2

Expand Down
10 changes: 6 additions & 4 deletions log/operation_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,15 @@ func TestOperationManagerExecutePassError(t *testing.T) {
mockLogOp.EXPECT().ExecutePass(gomock.Any(), logID1, infoMatcher).Return(1, nil)
mockLogOp.EXPECT().ExecutePass(gomock.Any(), logID2, infoMatcher).Return(0, errors.New("test error"))

info := defaultOperationInfo(registry)
lom := NewOperationManager(info, mockLogOp) // initialises counters

// Do not run this test in parallel with any other that affects the signingRuns or failedSigningRuns counters.
log1SigningRuns := testonly.NewCounterSnapshot(signingRuns, logID1Label)
log1FailedSigningRuns := testonly.NewCounterSnapshot(failedSigningRuns, logID1Label)
log2SigningRuns := testonly.NewCounterSnapshot(signingRuns, logID2Label)
log2FailedSigningRuns := testonly.NewCounterSnapshot(failedSigningRuns, logID2Label)

info := defaultOperationInfo(registry)
lom := NewOperationManager(info, mockLogOp)
lom.OperationSingle(ctx)

// Check that logID1 has 1 successful signing run, 0 failed.
Expand Down Expand Up @@ -318,14 +319,15 @@ func TestOperationManagerOperationLoopExecutePassError(t *testing.T) {
}
}).Return(0, errors.New("test error"))

info := defaultOperationInfo(registry)
lom := NewOperationManager(info, mockLogOp) // initialises counters

// Do not run this test in parallel with any other that affects the signingRuns or failedSigningRuns counters.
log1SigningRuns := testonly.NewCounterSnapshot(signingRuns, logID1Label)
log1FailedSigningRuns := testonly.NewCounterSnapshot(failedSigningRuns, logID1Label)
log2SigningRuns := testonly.NewCounterSnapshot(signingRuns, logID2Label)
log2FailedSigningRuns := testonly.NewCounterSnapshot(failedSigningRuns, logID2Label)

info := defaultOperationInfo(registry)
lom := NewOperationManager(info, mockLogOp)
lom.OperationLoop(ctx)

// Check that logID1 has 1 successful signing run, 0 failed.
Expand Down
3 changes: 3 additions & 0 deletions monitoring/testonly/delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type CounterSnapshot struct {
// by the given labels. This value can be compared to future values to determine
// how it has changed over time.
func NewCounterSnapshot(c monitoring.Counter, labels ...string) CounterSnapshot {
if c == nil {
panic("can't take snapshot of nil counter")
}
return CounterSnapshot{
c: c,
labels: labels,
Expand Down

0 comments on commit 3202101

Please sign in to comment.