Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix order-dependent test #2792

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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