Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Unified Diff: scheduler/appengine/presentation/state_test.go

Issue 2945843002: scheduler WIP: add GetAllJobs api. (Closed)
Patch Set: meh Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « scheduler/appengine/presentation/state.go ('k') | scheduler/appengine/ui/presentation.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scheduler/appengine/presentation/state_test.go
diff --git a/scheduler/appengine/presentation/state_test.go b/scheduler/appengine/presentation/state_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..1f211bde2ea94cef2ba439107ee3f21f4387bdf2
--- /dev/null
+++ b/scheduler/appengine/presentation/state_test.go
@@ -0,0 +1,83 @@
+// Copyright 2017 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package presentation
+
+import (
+ "testing"
+
+ "golang.org/x/net/context"
+
+ "github.com/golang/protobuf/proto"
+ "github.com/luci/luci-go/scheduler/appengine/catalog"
+ "github.com/luci/luci-go/scheduler/appengine/engine"
+ "github.com/luci/luci-go/scheduler/appengine/messages"
+ "github.com/luci/luci-go/scheduler/appengine/task"
+ "github.com/luci/luci-go/scheduler/appengine/task/urlfetch"
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestGetPublicStateKind(t *testing.T) {
+ t.Parallel()
+
+ Convey("works", t, func() {
+ So(GetPublicStateKind(&engine.Job{
+ State: engine.JobState{State: engine.JobStateOverrun},
+ }, task.Traits{}), ShouldEqual, PublicStateOverrun)
+
+ So(GetPublicStateKind(&engine.Job{
+ State: engine.JobState{State: engine.JobStateSlowQueue},
+ }, task.Traits{}), ShouldEqual, PublicStateStarting)
+
+ So(GetPublicStateKind(&engine.Job{
+ State: engine.JobState{State: engine.JobStateSlowQueue, InvocationRetryCount: 1},
+ }, task.Traits{}), ShouldEqual, PublicStateRetrying)
+
+ So(GetPublicStateKind(&engine.Job{
+ Paused: true,
+ State: engine.JobState{State: engine.JobStateSuspended},
+ }, task.Traits{}), ShouldEqual, PublicStatePaused)
+
+ So(GetPublicStateKind(&engine.Job{
+ State: engine.JobState{State: engine.JobStateQueued, InvocationID: 1},
+ }, task.Traits{Multistage: true}), ShouldEqual, PublicStateStarting)
+
+ So(GetPublicStateKind(&engine.Job{
+ State: engine.JobState{State: engine.JobStateQueued, InvocationID: 1},
+ }, task.Traits{Multistage: false}), ShouldEqual, PublicStateRunning)
+ })
+}
+
+func TestGetJobTraits(t *testing.T) {
+ t.Parallel()
+ Convey("works", t, func() {
+ cat := catalog.New("scheduler.cfg")
+ So(cat.RegisterTaskManager(&urlfetch.TaskManager{}), ShouldBeNil)
+ ctx := context.Background()
+
+ Convey("bad task", func() {
+ taskBlob, err := proto.Marshal(&messages.TaskDefWrapper{
+ Noop: &messages.NoopTask{},
+ })
+ So(err, ShouldBeNil)
+ traits, err := GetJobTraits(ctx, cat, &engine.Job{
+ Task: taskBlob,
+ })
+ So(err, ShouldNotBeNil)
+ So(traits, ShouldResemble, task.Traits{})
+ })
+
+ Convey("OK task", func() {
+ taskBlob, err := proto.Marshal(&messages.TaskDefWrapper{
+ UrlFetch: &messages.UrlFetchTask{Url: "http://example.com/path"},
+ })
+ So(err, ShouldBeNil)
+ traits, err := GetJobTraits(ctx, cat, &engine.Job{
+ Task: taskBlob,
+ })
+ So(err, ShouldBeNil)
+ So(traits, ShouldResemble, task.Traits{})
+ })
+ })
+}
« no previous file with comments | « scheduler/appengine/presentation/state.go ('k') | scheduler/appengine/ui/presentation.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698