示例#1
0
func init() {
	// This sets up an object stack where the REST client code talks
	// to the REST server code, which points at an in-memory backend.
	memBackend := memory.NewWithClock(coordinatetest.Clock)
	router := restserver.NewRouter(memBackend)
	server := httptest.NewServer(router)
	backend, err := restclient.New(server.URL)
	if err != nil {
		panic(err)
	}
	coordinatetest.Coordinate = backend
}
示例#2
0
func (s *Suite) SetUpTest(t *testing.T) {
	s.Clock = clock.NewMock()
	backend := memory.NewWithClock(s.Clock)
	var err error
	s.Namespace, err = backend.Namespace("")
	if !assert.NoError(t, err) {
		t.FailNow()
	}
	s.Worker = Worker{
		Namespace: s.Namespace,
	}
	s.Bit = false
	s.GotWork = make(chan bool)
	s.Finished = make(chan string)
	s.Stop = make(chan struct{})

	s.Worker.Tasks = map[string]func(context.Context, []coordinate.Attempt){
		"sanity": func(ctx context.Context, attempts []coordinate.Attempt) {
			if assert.Len(t, attempts, 1) {
				assert.Equal(t, "unit", attempts[0].WorkUnit().Name())
				assert.Equal(t, "spec", attempts[0].WorkUnit().WorkSpec().Name())
				s.Bit = true
				err := attempts[0].Finish(nil)
				assert.NoError(t, err, "finishing attempt in sanity")
			}
		},

		"timeout": func(ctx context.Context, attempts []coordinate.Attempt) {
			if !assert.Len(t, attempts, 1) {
				return
			}
			select {
			case <-ctx.Done():
				s.Bit = false
				status, err := attempts[0].Status()
				if assert.NoError(t, err) && status == coordinate.Pending {
					err = attempts[0].Fail(nil)
					assert.NoError(t, err, "failing attempt in timeout (status=%v)", status)
				}
			case <-s.Stop:
				s.Bit = true
				status, err := attempts[0].Status()
				if assert.NoError(t, err) && status == coordinate.Pending {
					err = attempts[0].Finish(nil)
					assert.NoError(t, err, "finishing attempt in timeout (status=%v)", status)
				}
			}
		},
	}

}
示例#3
0
func init() {
	coordinatetest.Coordinate = memory.NewWithClock(coordinatetest.Clock)
}
示例#4
0
	"fmt"
	"github.com/benbjohnson/clock"
	"github.com/diffeo/go-coordinate/cborrpc"
	"github.com/diffeo/go-coordinate/jobserver"
	"github.com/diffeo/go-coordinate/memory"
	"github.com/satori/go.uuid"
	"github.com/stretchr/testify/assert"
	"testing"
)

// Clock contains the mock time source.
var Clock = clock.NewMock()

// Coordinate contains the top-level interface to the backend
// for the job server.
var Coordinate = memory.NewWithClock(Clock)

// WorkSpecData contains the reference work spec.
var WorkSpecData = map[string]interface{}{
	"name":         "test_job_client",
	"min_gb":       1,
	"module":       "coordinate.tests.test_job_client",
	"run_function": "run_function",
}

func setUpTest(t *testing.T, name string) *jobserver.JobServer {
	namespace, err := Coordinate.Namespace(name)
	if !assert.NoError(t, err) {
		t.FailNow()
	}
	return &jobserver.JobServer{
示例#5
0
func init() {
	backend := memory.NewWithClock(coordinatetest.Clock)
	backend = cache.New(backend)
	coordinatetest.Coordinate = backend
}