-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Buchanan
committed
Apr 14, 2017
1 parent
daa353d
commit 49a3b56
Showing
10 changed files
with
151 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package mocks | ||
|
||
import context "golang.org/x/net/context" | ||
import funnel "funnel/proto/funnel" | ||
import mock "github.com/stretchr/testify/mock" | ||
|
||
import tes "funnel/proto/tes" | ||
|
||
// Database is an autogenerated mock type for the Database type | ||
type Database struct { | ||
mock.Mock | ||
} | ||
|
||
// AssignJob provides a mock function with given fields: _a0, _a1 | ||
func (_m *Database) AssignJob(_a0 *tes.Job, _a1 *funnel.Worker) { | ||
_m.Called(_a0, _a1) | ||
} | ||
|
||
// CheckWorkers provides a mock function with given fields: | ||
func (_m *Database) CheckWorkers() error { | ||
ret := _m.Called() | ||
|
||
var r0 error | ||
if rf, ok := ret.Get(0).(func() error); ok { | ||
r0 = rf() | ||
} else { | ||
r0 = ret.Error(0) | ||
} | ||
|
||
return r0 | ||
} | ||
|
||
// GetWorkers provides a mock function with given fields: _a0, _a1 | ||
func (_m *Database) GetWorkers(_a0 context.Context, _a1 *funnel.GetWorkersRequest) (*funnel.GetWorkersResponse, error) { | ||
ret := _m.Called(_a0, _a1) | ||
|
||
var r0 *funnel.GetWorkersResponse | ||
if rf, ok := ret.Get(0).(func(context.Context, *funnel.GetWorkersRequest) *funnel.GetWorkersResponse); ok { | ||
r0 = rf(_a0, _a1) | ||
} else { | ||
if ret.Get(0) != nil { | ||
r0 = ret.Get(0).(*funnel.GetWorkersResponse) | ||
} | ||
} | ||
|
||
var r1 error | ||
if rf, ok := ret.Get(1).(func(context.Context, *funnel.GetWorkersRequest) error); ok { | ||
r1 = rf(_a0, _a1) | ||
} else { | ||
r1 = ret.Error(1) | ||
} | ||
|
||
return r0, r1 | ||
} | ||
|
||
// ReadQueue provides a mock function with given fields: n | ||
func (_m *Database) ReadQueue(n int) []*tes.Job { | ||
ret := _m.Called(n) | ||
|
||
var r0 []*tes.Job | ||
if rf, ok := ret.Get(0).(func(int) []*tes.Job); ok { | ||
r0 = rf(n) | ||
} else { | ||
if ret.Get(0) != nil { | ||
r0 = ret.Get(0).([]*tes.Job) | ||
} | ||
} | ||
|
||
return r0 | ||
} | ||
|
||
// UpdateWorker provides a mock function with given fields: _a0, _a1 | ||
func (_m *Database) UpdateWorker(_a0 context.Context, _a1 *funnel.Worker) (*funnel.UpdateWorkerResponse, error) { | ||
ret := _m.Called(_a0, _a1) | ||
|
||
var r0 *funnel.UpdateWorkerResponse | ||
if rf, ok := ret.Get(0).(func(context.Context, *funnel.Worker) *funnel.UpdateWorkerResponse); ok { | ||
r0 = rf(_a0, _a1) | ||
} else { | ||
if ret.Get(0) != nil { | ||
r0 = ret.Get(0).(*funnel.UpdateWorkerResponse) | ||
} | ||
} | ||
|
||
var r1 error | ||
if rf, ok := ret.Get(1).(func(context.Context, *funnel.Worker) error); ok { | ||
r1 = rf(_a0, _a1) | ||
} else { | ||
r1 = ret.Error(1) | ||
} | ||
|
||
return r0, r1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package scheduler | ||
|
||
import ( | ||
"funnel/config" | ||
"funnel/logger" | ||
"funnel/proto/tes" | ||
"funnel/scheduler/mocks" | ||
"golang.org/x/net/context" | ||
"testing" | ||
) | ||
|
||
func init() { | ||
logger.ForceColors() | ||
} | ||
|
||
type BlankBackend struct{} | ||
|
||
func (b *BlankBackend) Schedule(*tes.Job) *Offer { | ||
return nil | ||
} | ||
|
||
func TestBackendCaching(t *testing.T) { | ||
conf := config.DefaultConfig() | ||
conf.Scheduler = "test" | ||
|
||
db := &mocks.Database{} | ||
db.On("CheckWorkers").Return(nil) | ||
db.On("ReadQueue", 10).Return([]*tes.Job{}) | ||
|
||
s, _ := NewScheduler(db, conf) | ||
calls := 0 | ||
s.AddBackend(&BackendPlugin{ | ||
Name: "test", | ||
Create: func(config.Config) (Backend, error) { | ||
calls++ | ||
return &BlankBackend{}, nil | ||
}, | ||
}) | ||
ctx := context.Background() | ||
s.Schedule(ctx) | ||
s.Schedule(ctx) | ||
if calls != 1 { | ||
logger.Debug("Calls", calls) | ||
t.Error("Expected one call") | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters