From 91f6ef34020f95cf352fc5764245424e76189aaa Mon Sep 17 00:00:00 2001 From: Shreya Garge <31314623+shreyagarge@users.noreply.github.com> Date: Tue, 20 Nov 2018 17:02:47 +0000 Subject: [PATCH] added context for runnerpool interface (#1320) * added context for runnerpool interface * added context for runnerpool interface --- api/agent/lb_agent_test.go | 2 +- api/agent/static_pool.go | 2 +- api/agent/static_pool_test.go | 4 ++-- api/runnerpool/ch_placer.go | 2 +- api/runnerpool/naive_placer.go | 2 +- api/runnerpool/runner_pool.go | 2 +- test/fn-system-tests/exec_runner_status_test.go | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api/agent/lb_agent_test.go b/api/agent/lb_agent_test.go index dc76677f3..bab08962f 100644 --- a/api/agent/lb_agent_test.go +++ b/api/agent/lb_agent_test.go @@ -46,7 +46,7 @@ func newMockRunnerPool(rf pool.MTLSRunnerFactory, runnerAddrs []string) *mockRun } } -func (rp *mockRunnerPool) Runners(call pool.RunnerCall) ([]pool.Runner, error) { +func (rp *mockRunnerPool) Runners(ctx context.Context, call pool.RunnerCall) ([]pool.Runner, error) { return rp.runners, nil } diff --git a/api/agent/static_pool.go b/api/agent/static_pool.go index 2e8fb4d9e..b4e97dbb7 100644 --- a/api/agent/static_pool.go +++ b/api/agent/static_pool.go @@ -39,7 +39,7 @@ func NewStaticRunnerPool(runnerAddresses []string, tlsConf *tls.Config, runnerFa } } -func (rp *staticRunnerPool) Runners(call pool.RunnerCall) ([]pool.Runner, error) { +func (rp *staticRunnerPool) Runners(ctx context.Context, call pool.RunnerCall) ([]pool.Runner, error) { r := make([]pool.Runner, len(rp.runners)) copy(r, rp.runners) return r, nil diff --git a/api/agent/static_pool_test.go b/api/agent/static_pool_test.go index db5c5ad59..7e9aa492a 100644 --- a/api/agent/static_pool_test.go +++ b/api/agent/static_pool_test.go @@ -45,7 +45,7 @@ func TestNewStaticPool(t *testing.T) { addrs := []string{"127.0.0.1:8080", "127.0.0.1:8081"} np := setupStaticPool(addrs) - runners, err := np.Runners(nil) + runners, err := np.Runners(context.Background(), nil) if err != nil { t.Fatalf("Failed to list runners %v", err) } @@ -62,7 +62,7 @@ func TestNewStaticPool(t *testing.T) { func TestEmptyPool(t *testing.T) { np := setupStaticPool(nil).(*staticRunnerPool) - runners, err := np.Runners(nil) + runners, err := np.Runners(context.Background(), nil) if err != nil { t.Fatalf("Failed to list runners %v", err) } diff --git a/api/runnerpool/ch_placer.go b/api/runnerpool/ch_placer.go index 708518029..9ffb7be80 100644 --- a/api/runnerpool/ch_placer.go +++ b/api/runnerpool/ch_placer.go @@ -40,7 +40,7 @@ func (p *chPlacer) PlaceCall(ctx context.Context, rp RunnerPool, call RunnerCall var runnerPoolErr error for { var runners []Runner - runners, runnerPoolErr = rp.Runners(call) + runners, runnerPoolErr = rp.Runners(ctx, call) i := int(jumpConsistentHash(sum64, int32(len(runners)))) for j := 0; j < len(runners) && !state.IsDone(); j++ { diff --git a/api/runnerpool/naive_placer.go b/api/runnerpool/naive_placer.go index 5e04690c7..00820ac57 100644 --- a/api/runnerpool/naive_placer.go +++ b/api/runnerpool/naive_placer.go @@ -34,7 +34,7 @@ func (sp *naivePlacer) PlaceCall(ctx context.Context, rp RunnerPool, call Runner var runnerPoolErr error for { var runners []Runner - runners, runnerPoolErr = rp.Runners(call) + runners, runnerPoolErr = rp.Runners(ctx, call) for j := 0; j < len(runners) && !state.IsDone(); j++ { diff --git a/api/runnerpool/runner_pool.go b/api/runnerpool/runner_pool.go index 70abbb33a..f648d441c 100644 --- a/api/runnerpool/runner_pool.go +++ b/api/runnerpool/runner_pool.go @@ -20,7 +20,7 @@ type Placer interface { // RunnerPool is the abstraction for getting an ordered list of runners to try for a call type RunnerPool interface { // returns an error for unrecoverable errors that should not be retried - Runners(call RunnerCall) ([]Runner, error) + Runners(ctx context.Context, call RunnerCall) ([]Runner, error) Shutdown(ctx context.Context) error } diff --git a/test/fn-system-tests/exec_runner_status_test.go b/test/fn-system-tests/exec_runner_status_test.go index 4247963d1..9650e76d4 100644 --- a/test/fn-system-tests/exec_runner_status_test.go +++ b/test/fn-system-tests/exec_runner_status_test.go @@ -118,7 +118,7 @@ func TestExecuteRunnerStatus(t *testing.T) { t.Fatalf("Creating Node Pool failed %v", err) } - runners, err := pool.Runners(&zoo) + runners, err := pool.Runners(context.Background(), &zoo) if err != nil { t.Fatalf("Getting Runners from Pool failed %v", err) }