| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package apiservers | 5 package apiservers |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "testing" | 9 "testing" |
| 10 "time" | 10 "time" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 }, | 68 }, |
| 69 }, nil | 69 }, nil |
| 70 } | 70 } |
| 71 reply, err := ss.GetJobs(ctx, nil) | 71 reply, err := ss.GetJobs(ctx, nil) |
| 72 So(err, ShouldBeNil) | 72 So(err, ShouldBeNil) |
| 73 So(reply.GetJobs(), ShouldResemble, []*scheduler.Job{ | 73 So(reply.GetJobs(), ShouldResemble, []*scheduler.Job{ |
| 74 { | 74 { |
| 75 JobRef: &scheduler.JobRef{Job: "foo",
Project: "bar"}, | 75 JobRef: &scheduler.JobRef{Job: "foo",
Project: "bar"}, |
| 76 Schedule: "0 * * * * * *", | 76 Schedule: "0 * * * * * *", |
| 77 State: &scheduler.JobState{UiStatus:
"RUNNING"}, | 77 State: &scheduler.JobState{UiStatus:
"RUNNING"}, |
| 78 Paused: false, |
| 78 }, | 79 }, |
| 79 { | 80 { |
| 80 JobRef: &scheduler.JobRef{Job: "faz",
Project: "baz"}, | 81 JobRef: &scheduler.JobRef{Job: "faz",
Project: "baz"}, |
| 81 Schedule: "with 1m interval", | 82 Schedule: "with 1m interval", |
| 82 State: &scheduler.JobState{UiStatus:
"PAUSED"}, | 83 State: &scheduler.JobState{UiStatus:
"PAUSED"}, |
| 84 Paused: true, |
| 83 }, | 85 }, |
| 84 }) | 86 }) |
| 85 }) | 87 }) |
| 86 | 88 |
| 87 Convey("One Project", func() { | 89 Convey("One Project", func() { |
| 88 fakeEng.getProjectJobs = func(projectID string) ([]*engi
ne.Job, error) { | 90 fakeEng.getProjectJobs = func(projectID string) ([]*engi
ne.Job, error) { |
| 89 So(projectID, ShouldEqual, "bar") | 91 So(projectID, ShouldEqual, "bar") |
| 90 return []*engine.Job{ | 92 return []*engine.Job{ |
| 91 { | 93 { |
| 92 JobID: "bar/foo", | 94 JobID: "bar/foo", |
| 93 ProjectID: "bar", | 95 ProjectID: "bar", |
| 94 Schedule: "0 * * * * * *", | 96 Schedule: "0 * * * * * *", |
| 95 State: engine.JobState{State
: engine.JobStateRunning}, | 97 State: engine.JobState{State
: engine.JobStateRunning}, |
| 96 Task: fakeTaskBlob, | 98 Task: fakeTaskBlob, |
| 97 }, | 99 }, |
| 98 }, nil | 100 }, nil |
| 99 } | 101 } |
| 100 reply, err := ss.GetJobs(ctx, &scheduler.JobsRequest{Pro
ject: "bar"}) | 102 reply, err := ss.GetJobs(ctx, &scheduler.JobsRequest{Pro
ject: "bar"}) |
| 101 So(err, ShouldBeNil) | 103 So(err, ShouldBeNil) |
| 102 So(reply.GetJobs(), ShouldResemble, []*scheduler.Job{ | 104 So(reply.GetJobs(), ShouldResemble, []*scheduler.Job{ |
| 103 { | 105 { |
| 104 JobRef: &scheduler.JobRef{Job: "foo",
Project: "bar"}, | 106 JobRef: &scheduler.JobRef{Job: "foo",
Project: "bar"}, |
| 105 Schedule: "0 * * * * * *", | 107 Schedule: "0 * * * * * *", |
| 106 State: &scheduler.JobState{UiStatus:
"RUNNING"}, | 108 State: &scheduler.JobState{UiStatus:
"RUNNING"}, |
| 109 Paused: false, |
| 107 }, | 110 }, |
| 108 }) | 111 }) |
| 109 }) | 112 }) |
| 113 |
| 114 Convey("Paused but currently running job", func() { |
| 115 fakeEng.getProjectJobs = func(projectID string) ([]*engi
ne.Job, error) { |
| 116 So(projectID, ShouldEqual, "bar") |
| 117 return []*engine.Job{ |
| 118 { |
| 119 // Job which is paused but its l
atest invocation still running. |
| 120 JobID: "bar/foo", |
| 121 ProjectID: "bar", |
| 122 Schedule: "0 * * * * * *", |
| 123 State: engine.JobState{State
: engine.JobStateRunning}, |
| 124 Paused: true, |
| 125 Task: fakeTaskBlob, |
| 126 }, |
| 127 }, nil |
| 128 } |
| 129 reply, err := ss.GetJobs(ctx, &scheduler.JobsRequest{Pro
ject: "bar"}) |
| 130 So(err, ShouldBeNil) |
| 131 So(reply.GetJobs(), ShouldResemble, []*scheduler.Job{ |
| 132 { |
| 133 JobRef: &scheduler.JobRef{Job: "foo",
Project: "bar"}, |
| 134 Schedule: "0 * * * * * *", |
| 135 State: &scheduler.JobState{UiStatus:
"RUNNING"}, |
| 136 Paused: true, |
| 137 }, |
| 138 }) |
| 139 }) |
| 110 }) | 140 }) |
| 111 } | 141 } |
| 112 | 142 |
| 113 func TestGetInvocationsApi(t *testing.T) { | 143 func TestGetInvocationsApi(t *testing.T) { |
| 114 t.Parallel() | 144 t.Parallel() |
| 115 | 145 |
| 116 Convey("Scheduler GetInvocations API works", t, func() { | 146 Convey("Scheduler GetInvocations API works", t, func() { |
| 117 ctx := gaetesting.TestingContext() | 147 ctx := gaetesting.TestingContext() |
| 118 fakeEng, catalog := newTestEngine() | 148 fakeEng, catalog := newTestEngine() |
| 119 _, err := registerUrlFetcher(catalog) | 149 _, err := registerUrlFetcher(catalog) |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 return f.resumeJob(jobID, who) | 458 return f.resumeJob(jobID, who) |
| 429 } | 459 } |
| 430 | 460 |
| 431 func (f *fakeEngine) AbortInvocation(c context.Context, jobID string, invID int6
4, who identity.Identity) error { | 461 func (f *fakeEngine) AbortInvocation(c context.Context, jobID string, invID int6
4, who identity.Identity) error { |
| 432 return f.abortInvocation(jobID, invID, who) | 462 return f.abortInvocation(jobID, invID, who) |
| 433 } | 463 } |
| 434 | 464 |
| 435 func (f *fakeEngine) AbortJob(c context.Context, jobID string, who identity.Iden
tity) error { | 465 func (f *fakeEngine) AbortJob(c context.Context, jobID string, who identity.Iden
tity) error { |
| 436 return f.abortJob(jobID, who) | 466 return f.abortJob(jobID, who) |
| 437 } | 467 } |
| OLD | NEW |