From 2bdbed0974d2f6e2a5644a5a2bc8a1cda7952f25 Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Tue, 26 May 2020 09:24:50 -0400 Subject: [PATCH] refactor: context is first parameter By convention, go functions take `context.Context` as the first argument. --- nomad/volumewatcher/batcher.go | 2 +- nomad/volumewatcher/batcher_test.go | 2 +- nomad/volumewatcher/volumes_watcher.go | 2 +- nomad/volumewatcher/volumes_watcher_test.go | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nomad/volumewatcher/batcher.go b/nomad/volumewatcher/batcher.go index e9eb74abe..0728b806d 100644 --- a/nomad/volumewatcher/batcher.go +++ b/nomad/volumewatcher/batcher.go @@ -29,7 +29,7 @@ type VolumeUpdateBatcher struct { // NewVolumeUpdateBatcher returns an VolumeUpdateBatcher that uses the // passed raft endpoints to create the updates to volume claims, and // exits the batcher when the passed exit channel is closed. -func NewVolumeUpdateBatcher(batchDuration time.Duration, raft VolumeRaftEndpoints, ctx context.Context) *VolumeUpdateBatcher { +func NewVolumeUpdateBatcher(ctx context.Context, batchDuration time.Duration, raft VolumeRaftEndpoints) *VolumeUpdateBatcher { b := &VolumeUpdateBatcher{ batchDuration: batchDuration, raft: raft, diff --git a/nomad/volumewatcher/batcher_test.go b/nomad/volumewatcher/batcher_test.go index 930342cdc..fd6773c43 100644 --- a/nomad/volumewatcher/batcher_test.go +++ b/nomad/volumewatcher/batcher_test.go @@ -23,7 +23,7 @@ func TestVolumeWatch_Batcher(t *testing.T) { srv := &MockBatchingRPCServer{} srv.state = state.TestStateStore(t) - srv.volumeUpdateBatcher = NewVolumeUpdateBatcher(CrossVolumeUpdateBatchDuration, srv, ctx) + srv.volumeUpdateBatcher = NewVolumeUpdateBatcher(ctx, CrossVolumeUpdateBatchDuration, srv) srv.nextCSIControllerDetachError = fmt.Errorf("some controller plugin error") plugin := mock.CSIPlugin() diff --git a/nomad/volumewatcher/volumes_watcher.go b/nomad/volumewatcher/volumes_watcher.go index d4d77d48f..6bae22901 100644 --- a/nomad/volumewatcher/volumes_watcher.go +++ b/nomad/volumewatcher/volumes_watcher.go @@ -124,7 +124,7 @@ func (w *Watcher) flush(enabled bool) { w.ctx, w.exitFn = context.WithCancel(context.Background()) if enabled { - w.volumeUpdateBatcher = NewVolumeUpdateBatcher(w.updateBatchDuration, w.raft, w.ctx) + w.volumeUpdateBatcher = NewVolumeUpdateBatcher(w.ctx, w.updateBatchDuration, w.raft) } else { w.volumeUpdateBatcher = nil } diff --git a/nomad/volumewatcher/volumes_watcher_test.go b/nomad/volumewatcher/volumes_watcher_test.go index 3d00fa13b..53f97fe30 100644 --- a/nomad/volumewatcher/volumes_watcher_test.go +++ b/nomad/volumewatcher/volumes_watcher_test.go @@ -110,7 +110,7 @@ func TestVolumeWatch_StartStop(t *testing.T) { srv.state = state.TestStateStore(t) index := uint64(100) srv.volumeUpdateBatcher = NewVolumeUpdateBatcher( - CrossVolumeUpdateBatchDuration, srv, ctx) + ctx, CrossVolumeUpdateBatchDuration, srv) watcher := NewVolumesWatcher(testlog.HCLogger(t), srv, srv, @@ -261,7 +261,7 @@ func TestVolumeWatch_RegisterDeregister(t *testing.T) { srv := &MockStatefulRPCServer{} srv.state = state.TestStateStore(t) srv.volumeUpdateBatcher = NewVolumeUpdateBatcher( - CrossVolumeUpdateBatchDuration, srv, ctx) + ctx, CrossVolumeUpdateBatchDuration, srv) index := uint64(100)