From f3eaa887163bb4d2ea4b4458cb4e7c5c2f346bc6 Mon Sep 17 00:00:00 2001 From: Marwan Aljubeh Date: Thu, 16 Aug 2018 15:37:33 +0100 Subject: [PATCH] Fix the build (#1256) * 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 --- server/log_operation_manager.go | 2 +- server/log_operation_manager_test.go | 37 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/server/log_operation_manager.go b/server/log_operation_manager.go index 173cd79698..5749c82d10 100644 --- a/server/log_operation_manager.go +++ b/server/log_operation_manager.go @@ -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...") diff --git a/server/log_operation_manager_test.go b/server/log_operation_manager_test.go index 6ced037288..9fb5e717c1 100644 --- a/server/log_operation_manager_test.go +++ b/server/log_operation_manager_test.go @@ -20,6 +20,7 @@ import ( "fmt" "reflect" "strconv" + "sync/atomic" "testing" "time" @@ -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)