added context for runnerpool interface (#1320)

* added context for runnerpool interface

* added context for runnerpool interface
This commit is contained in:
Shreya Garge
2018-11-20 17:02:47 +00:00
committed by GitHub
parent 47dab09996
commit 91f6ef3402
7 changed files with 8 additions and 8 deletions

View File

@@ -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 return rp.runners, nil
} }

View File

@@ -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)) r := make([]pool.Runner, len(rp.runners))
copy(r, rp.runners) copy(r, rp.runners)
return r, nil return r, nil

View File

@@ -45,7 +45,7 @@ func TestNewStaticPool(t *testing.T) {
addrs := []string{"127.0.0.1:8080", "127.0.0.1:8081"} addrs := []string{"127.0.0.1:8080", "127.0.0.1:8081"}
np := setupStaticPool(addrs) np := setupStaticPool(addrs)
runners, err := np.Runners(nil) runners, err := np.Runners(context.Background(), nil)
if err != nil { if err != nil {
t.Fatalf("Failed to list runners %v", err) t.Fatalf("Failed to list runners %v", err)
} }
@@ -62,7 +62,7 @@ func TestNewStaticPool(t *testing.T) {
func TestEmptyPool(t *testing.T) { func TestEmptyPool(t *testing.T) {
np := setupStaticPool(nil).(*staticRunnerPool) np := setupStaticPool(nil).(*staticRunnerPool)
runners, err := np.Runners(nil) runners, err := np.Runners(context.Background(), nil)
if err != nil { if err != nil {
t.Fatalf("Failed to list runners %v", err) t.Fatalf("Failed to list runners %v", err)
} }

View File

@@ -40,7 +40,7 @@ func (p *chPlacer) PlaceCall(ctx context.Context, rp RunnerPool, call RunnerCall
var runnerPoolErr error var runnerPoolErr error
for { for {
var runners []Runner var runners []Runner
runners, runnerPoolErr = rp.Runners(call) runners, runnerPoolErr = rp.Runners(ctx, call)
i := int(jumpConsistentHash(sum64, int32(len(runners)))) i := int(jumpConsistentHash(sum64, int32(len(runners))))
for j := 0; j < len(runners) && !state.IsDone(); j++ { for j := 0; j < len(runners) && !state.IsDone(); j++ {

View File

@@ -34,7 +34,7 @@ func (sp *naivePlacer) PlaceCall(ctx context.Context, rp RunnerPool, call Runner
var runnerPoolErr error var runnerPoolErr error
for { for {
var runners []Runner var runners []Runner
runners, runnerPoolErr = rp.Runners(call) runners, runnerPoolErr = rp.Runners(ctx, call)
for j := 0; j < len(runners) && !state.IsDone(); j++ { for j := 0; j < len(runners) && !state.IsDone(); j++ {

View File

@@ -20,7 +20,7 @@ type Placer interface {
// RunnerPool is the abstraction for getting an ordered list of runners to try for a call // RunnerPool is the abstraction for getting an ordered list of runners to try for a call
type RunnerPool interface { type RunnerPool interface {
// returns an error for unrecoverable errors that should not be retried // 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 Shutdown(ctx context.Context) error
} }

View File

@@ -118,7 +118,7 @@ func TestExecuteRunnerStatus(t *testing.T) {
t.Fatalf("Creating Node Pool failed %v", err) t.Fatalf("Creating Node Pool failed %v", err)
} }
runners, err := pool.Runners(&zoo) runners, err := pool.Runners(context.Background(), &zoo)
if err != nil { if err != nil {
t.Fatalf("Getting Runners from Pool failed %v", err) t.Fatalf("Getting Runners from Pool failed %v", err)
} }