Skip to content

Commit

Permalink
Fix the build (#1256)
Browse files Browse the repository at this point in the history
* Fix the build

Currently, building fails with the following error:

```
server/log_operation_manager.go:342: Verbose.Infof format %d has arg
logID of wrong type string
``

This is because logID is a string, but Infof is being asked to format it
as an integer.

* Add a test for LogOperationManager's OperationLoop
  • Loading branch information
maljub01 authored and gdbelvin committed Aug 16, 2018
1 parent 9ea17df commit f3eaa88
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/log_operation_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ loop:
if runner == nil {
continue
}
glog.V(1).Infof("cancel election runner for %d", logID)
glog.V(1).Infof("cancel election runner for %s", logID)
runner.Cancel()
}
glog.Infof("wait for termination of election runners...")
Expand Down
37 changes: 37 additions & 0 deletions server/log_operation_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"reflect"
"strconv"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -179,6 +180,42 @@ func TestLogOperationManagerPassesIDs(t *testing.T) {
lom.OperationSingle(ctx)
}

func TestLogOperationManagerOperationLoopPassesIDs(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

logID1 := int64(451)
logID2 := int64(145)

var logCount int64

ctrl := gomock.NewController(t)
defer ctrl.Finish()

fakeStorage, mockAdmin := setupLogIDs(ctrl, map[int64]string{451: "LogID1", 145: "LogID2"})
registry := extension.Registry{
LogStorage: fakeStorage,
AdminStorage: mockAdmin,
}

mockLogOp := NewMockLogOperation(ctrl)
infoMatcher := logOpInfoMatcher{50}
mockLogOp.EXPECT().ExecutePass(gomock.Any(), logID1, infoMatcher).Do(func(_ context.Context, _ int64, _ *LogOperationInfo) {
if atomic.AddInt64(&logCount, 1) == 2 {
cancel()
}
})
mockLogOp.EXPECT().ExecutePass(gomock.Any(), logID2, infoMatcher).Do(func(_ context.Context, _ int64, _ *LogOperationInfo) {
if atomic.AddInt64(&logCount, 1) == 2 {
cancel()
}
})

info := defaultLogOperationInfo(registry)
lom := NewLogOperationManager(info, mockLogOp)
lom.OperationLoop(ctx)
}

func TestHeldInfo(t *testing.T) {
ctx := context.Background()
ctrl := gomock.NewController(t)
Expand Down

0 comments on commit f3eaa88

Please sign in to comment.