| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. | 1 // Copyright 2017 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 t.Parallel() | 45 t.Parallel() |
| 46 | 46 |
| 47 Convey("Scheduler GetJobs API works", t, func() { | 47 Convey("Scheduler GetJobs API works", t, func() { |
| 48 ctx := gaetesting.TestingContext() | 48 ctx := gaetesting.TestingContext() |
| 49 fakeEng, catalog := newTestEngine() | 49 fakeEng, catalog := newTestEngine() |
| 50 fakeTaskBlob, err := registerUrlFetcher(catalog) | 50 fakeTaskBlob, err := registerUrlFetcher(catalog) |
| 51 So(err, ShouldBeNil) | 51 So(err, ShouldBeNil) |
| 52 ss := SchedulerServer{fakeEng, catalog} | 52 ss := SchedulerServer{fakeEng, catalog} |
| 53 | 53 |
| 54 Convey("Empty", func() { | 54 Convey("Empty", func() { |
| 55 » » » fakeEng.getAllJobs = func() ([]*engine.Job, error) { ret
urn []*engine.Job{}, nil } | 55 » » » fakeEng.getAllJobsRA = func() ([]*engine.Job, error) { r
eturn []*engine.Job{}, nil } |
| 56 reply, err := ss.GetJobs(ctx, nil) | 56 reply, err := ss.GetJobs(ctx, nil) |
| 57 So(err, ShouldBeNil) | 57 So(err, ShouldBeNil) |
| 58 So(len(reply.GetJobs()), ShouldEqual, 0) | 58 So(len(reply.GetJobs()), ShouldEqual, 0) |
| 59 }) | 59 }) |
| 60 | 60 |
| 61 Convey("All Projects", func() { | 61 Convey("All Projects", func() { |
| 62 » » » fakeEng.getAllJobs = func() ([]*engine.Job, error) { | 62 » » » fakeEng.getAllJobsRA = func() ([]*engine.Job, error) { |
| 63 return []*engine.Job{ | 63 return []*engine.Job{ |
| 64 { | 64 { |
| 65 JobID: "bar/foo", | 65 JobID: "bar/foo", |
| 66 ProjectID: "bar", | 66 ProjectID: "bar", |
| 67 Schedule: "0 * * * * * *", | 67 Schedule: "0 * * * * * *", |
| 68 State: engine.JobState{State
: engine.JobStateRunning}, | 68 State: engine.JobState{State
: engine.JobStateRunning}, |
| 69 Task: fakeTaskBlob, | 69 Task: fakeTaskBlob, |
| 70 }, | 70 }, |
| 71 { | 71 { |
| 72 JobID: "baz/faz", | 72 JobID: "baz/faz", |
| (...skipping 17 matching lines...) Expand all Loading... |
| 90 { | 90 { |
| 91 JobRef: &scheduler.JobRef{Job: "faz",
Project: "baz"}, | 91 JobRef: &scheduler.JobRef{Job: "faz",
Project: "baz"}, |
| 92 Schedule: "with 1m interval", | 92 Schedule: "with 1m interval", |
| 93 State: &scheduler.JobState{UiStatus:
"PAUSED"}, | 93 State: &scheduler.JobState{UiStatus:
"PAUSED"}, |
| 94 Paused: true, | 94 Paused: true, |
| 95 }, | 95 }, |
| 96 }) | 96 }) |
| 97 }) | 97 }) |
| 98 | 98 |
| 99 Convey("One Project", func() { | 99 Convey("One Project", func() { |
| 100 » » » fakeEng.getProjectJobs = func(projectID string) ([]*engi
ne.Job, error) { | 100 » » » fakeEng.getProjectJobsRA = func(projectID string) ([]*en
gine.Job, error) { |
| 101 So(projectID, ShouldEqual, "bar") | 101 So(projectID, ShouldEqual, "bar") |
| 102 return []*engine.Job{ | 102 return []*engine.Job{ |
| 103 { | 103 { |
| 104 JobID: "bar/foo", | 104 JobID: "bar/foo", |
| 105 ProjectID: "bar", | 105 ProjectID: "bar", |
| 106 Schedule: "0 * * * * * *", | 106 Schedule: "0 * * * * * *", |
| 107 State: engine.JobState{State
: engine.JobStateRunning}, | 107 State: engine.JobState{State
: engine.JobStateRunning}, |
| 108 Task: fakeTaskBlob, | 108 Task: fakeTaskBlob, |
| 109 }, | 109 }, |
| 110 }, nil | 110 }, nil |
| 111 } | 111 } |
| 112 reply, err := ss.GetJobs(ctx, &scheduler.JobsRequest{Pro
ject: "bar"}) | 112 reply, err := ss.GetJobs(ctx, &scheduler.JobsRequest{Pro
ject: "bar"}) |
| 113 So(err, ShouldBeNil) | 113 So(err, ShouldBeNil) |
| 114 So(reply.GetJobs(), ShouldResemble, []*scheduler.Job{ | 114 So(reply.GetJobs(), ShouldResemble, []*scheduler.Job{ |
| 115 { | 115 { |
| 116 JobRef: &scheduler.JobRef{Job: "foo",
Project: "bar"}, | 116 JobRef: &scheduler.JobRef{Job: "foo",
Project: "bar"}, |
| 117 Schedule: "0 * * * * * *", | 117 Schedule: "0 * * * * * *", |
| 118 State: &scheduler.JobState{UiStatus:
"RUNNING"}, | 118 State: &scheduler.JobState{UiStatus:
"RUNNING"}, |
| 119 Paused: false, | 119 Paused: false, |
| 120 }, | 120 }, |
| 121 }) | 121 }) |
| 122 }) | 122 }) |
| 123 | 123 |
| 124 Convey("Paused but currently running job", func() { | 124 Convey("Paused but currently running job", func() { |
| 125 » » » fakeEng.getProjectJobs = func(projectID string) ([]*engi
ne.Job, error) { | 125 » » » fakeEng.getProjectJobsRA = func(projectID string) ([]*en
gine.Job, error) { |
| 126 So(projectID, ShouldEqual, "bar") | 126 So(projectID, ShouldEqual, "bar") |
| 127 return []*engine.Job{ | 127 return []*engine.Job{ |
| 128 { | 128 { |
| 129 // Job which is paused but its l
atest invocation still running. | 129 // Job which is paused but its l
atest invocation still running. |
| 130 JobID: "bar/foo", | 130 JobID: "bar/foo", |
| 131 ProjectID: "bar", | 131 ProjectID: "bar", |
| 132 Schedule: "0 * * * * * *", | 132 Schedule: "0 * * * * * *", |
| 133 State: engine.JobState{State
: engine.JobStateRunning}, | 133 State: engine.JobState{State
: engine.JobStateRunning}, |
| 134 Paused: true, | 134 Paused: true, |
| 135 Task: fakeTaskBlob, | 135 Task: fakeTaskBlob, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 154 t.Parallel() | 154 t.Parallel() |
| 155 | 155 |
| 156 Convey("Scheduler GetInvocations API works", t, func() { | 156 Convey("Scheduler GetInvocations API works", t, func() { |
| 157 ctx := gaetesting.TestingContext() | 157 ctx := gaetesting.TestingContext() |
| 158 fakeEng, catalog := newTestEngine() | 158 fakeEng, catalog := newTestEngine() |
| 159 _, err := registerUrlFetcher(catalog) | 159 _, err := registerUrlFetcher(catalog) |
| 160 So(err, ShouldBeNil) | 160 So(err, ShouldBeNil) |
| 161 ss := SchedulerServer{fakeEng, catalog} | 161 ss := SchedulerServer{fakeEng, catalog} |
| 162 | 162 |
| 163 Convey("Job not found", func() { | 163 Convey("Job not found", func() { |
| 164 » » » fakeEng.getJob = func(JobID string) (*engine.Job, error)
{ return nil, nil } | 164 » » » fakeEng.getJobRA = func(JobID string) (*engine.Job, erro
r) { return nil, nil } |
| 165 _, err := ss.GetInvocations(ctx, &scheduler.InvocationsR
equest{ | 165 _, err := ss.GetInvocations(ctx, &scheduler.InvocationsR
equest{ |
| 166 JobRef: &scheduler.JobRef{Project: "not", Job: "
exists"}, | 166 JobRef: &scheduler.JobRef{Project: "not", Job: "
exists"}, |
| 167 }) | 167 }) |
| 168 s, ok := status.FromError(err) | 168 s, ok := status.FromError(err) |
| 169 So(ok, ShouldBeTrue) | 169 So(ok, ShouldBeTrue) |
| 170 So(s.Code(), ShouldEqual, codes.NotFound) | 170 So(s.Code(), ShouldEqual, codes.NotFound) |
| 171 }) | 171 }) |
| 172 | 172 |
| 173 Convey("DS error", func() { | 173 Convey("DS error", func() { |
| 174 » » » fakeEng.getJob = func(JobID string) (*engine.Job, error)
{ return nil, fmt.Errorf("ds error") } | 174 » » » fakeEng.getJobRA = func(JobID string) (*engine.Job, erro
r) { return nil, fmt.Errorf("ds error") } |
| 175 _, err := ss.GetInvocations(ctx, &scheduler.InvocationsR
equest{ | 175 _, err := ss.GetInvocations(ctx, &scheduler.InvocationsR
equest{ |
| 176 JobRef: &scheduler.JobRef{Project: "proj", Job:
"job"}, | 176 JobRef: &scheduler.JobRef{Project: "proj", Job:
"job"}, |
| 177 }) | 177 }) |
| 178 s, ok := status.FromError(err) | 178 s, ok := status.FromError(err) |
| 179 So(ok, ShouldBeTrue) | 179 So(ok, ShouldBeTrue) |
| 180 So(s.Code(), ShouldEqual, codes.Internal) | 180 So(s.Code(), ShouldEqual, codes.Internal) |
| 181 }) | 181 }) |
| 182 | 182 |
| 183 » » fakeEng.getJob = func(JobID string) (*engine.Job, error) { | 183 » » fakeEng.getJobRA = func(JobID string) (*engine.Job, error) { |
| 184 return &engine.Job{JobID: "proj/job", ProjectID: "proj"}
, nil | 184 return &engine.Job{JobID: "proj/job", ProjectID: "proj"}
, nil |
| 185 } | 185 } |
| 186 | 186 |
| 187 Convey("Emtpy with huge pagesize", func() { | 187 Convey("Emtpy with huge pagesize", func() { |
| 188 fakeEng.listInvocations = func(pageSize int, cursor stri
ng) ([]*engine.Invocation, string, error) { | 188 fakeEng.listInvocations = func(pageSize int, cursor stri
ng) ([]*engine.Invocation, string, error) { |
| 189 So(pageSize, ShouldEqual, 50) | 189 So(pageSize, ShouldEqual, 50) |
| 190 So(cursor, ShouldEqual, "") | 190 So(cursor, ShouldEqual, "") |
| 191 return nil, "", nil | 191 return nil, "", nil |
| 192 } | 192 } |
| 193 r, err := ss.GetInvocations(ctx, &scheduler.InvocationsR
equest{ | 193 r, err := ss.GetInvocations(ctx, &scheduler.InvocationsR
equest{ |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 UrlFetch: &messages.UrlFetchTask{Url: "http://example.com/path"}
, | 390 UrlFetch: &messages.UrlFetchTask{Url: "http://example.com/path"}
, |
| 391 }) | 391 }) |
| 392 } | 392 } |
| 393 | 393 |
| 394 func newTestEngine() (*fakeEngine, catalog.Catalog) { | 394 func newTestEngine() (*fakeEngine, catalog.Catalog) { |
| 395 cat := catalog.New("scheduler.cfg") | 395 cat := catalog.New("scheduler.cfg") |
| 396 return &fakeEngine{}, cat | 396 return &fakeEngine{}, cat |
| 397 } | 397 } |
| 398 | 398 |
| 399 type fakeEngine struct { | 399 type fakeEngine struct { |
| 400 » getAllJobs func() ([]*engine.Job, error) | 400 » getAllJobsRA func() ([]*engine.Job, error) |
| 401 » getProjectJobs func(projectID string) ([]*engine.Job, error) | 401 » getProjectJobsRA func(projectID string) ([]*engine.Job, error) |
| 402 » getJob func(jobID string) (*engine.Job, error) | 402 » getJobRA func(jobID string) (*engine.Job, error) |
| 403 » listInvocations func(pageSize int, cursor string) ([]*engine.Invocation,
string, error) | 403 » listInvocations func(pageSize int, cursor string) ([]*engine.Invocation
, string, error) |
| 404 | 404 |
| 405 pauseJob func(jobID string, who identity.Identity) error | 405 pauseJob func(jobID string, who identity.Identity) error |
| 406 resumeJob func(jobID string, who identity.Identity) error | 406 resumeJob func(jobID string, who identity.Identity) error |
| 407 abortJob func(jobID string, who identity.Identity) error | 407 abortJob func(jobID string, who identity.Identity) error |
| 408 abortInvocation func(jobID string, invID int64, who identity.Identity) e
rror | 408 abortInvocation func(jobID string, invID int64, who identity.Identity) e
rror |
| 409 } | 409 } |
| 410 | 410 |
| 411 func (f *fakeEngine) GetAllProjects(c context.Context) ([]string, error) { | 411 func (f *fakeEngine) GetAllProjects(c context.Context) ([]string, error) { |
| 412 panic("not implemented") | 412 panic("not implemented") |
| 413 } | 413 } |
| 414 | 414 |
| 415 func (f *fakeEngine) GetAllJobs(c context.Context) ([]*engine.Job, error) { | 415 func (f *fakeEngine) GetAllJobsRA(c context.Context) ([]*engine.Job, error) { |
| 416 » return f.getAllJobs() | 416 » return f.getAllJobsRA() |
| 417 } | 417 } |
| 418 | 418 |
| 419 func (f *fakeEngine) GetProjectJobs(c context.Context, projectID string) ([]*eng
ine.Job, error) { | 419 func (f *fakeEngine) GetProjectJobsRA(c context.Context, projectID string) ([]*e
ngine.Job, error) { |
| 420 » return f.getProjectJobs(projectID) | 420 » return f.getProjectJobsRA(projectID) |
| 421 } | 421 } |
| 422 | 422 |
| 423 func (f *fakeEngine) GetJob(c context.Context, jobID string) (*engine.Job, error
) { | 423 func (f *fakeEngine) GetJobRA(c context.Context, jobID string) (*engine.Job, err
or) { |
| 424 » return f.getJob(jobID) | 424 » return f.getJobRA(jobID) |
| 425 } | 425 } |
| 426 | 426 |
| 427 func (f *fakeEngine) ListInvocations(c context.Context, jobID string, pageSize i
nt, cursor string) ([]*engine.Invocation, string, error) { | 427 func (f *fakeEngine) ListInvocations(c context.Context, jobID string, pageSize i
nt, cursor string) ([]*engine.Invocation, string, error) { |
| 428 return f.listInvocations(pageSize, cursor) | 428 return f.listInvocations(pageSize, cursor) |
| 429 } | 429 } |
| 430 | 430 |
| 431 func (f *fakeEngine) GetInvocation(c context.Context, jobID string, invID int64)
(*engine.Invocation, error) { | 431 func (f *fakeEngine) GetInvocation(c context.Context, jobID string, invID int64)
(*engine.Invocation, error) { |
| 432 panic("not implemented") | 432 panic("not implemented") |
| 433 } | 433 } |
| 434 | 434 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 return f.resumeJob(jobID, who) | 468 return f.resumeJob(jobID, who) |
| 469 } | 469 } |
| 470 | 470 |
| 471 func (f *fakeEngine) AbortInvocation(c context.Context, jobID string, invID int6
4, who identity.Identity) error { | 471 func (f *fakeEngine) AbortInvocation(c context.Context, jobID string, invID int6
4, who identity.Identity) error { |
| 472 return f.abortInvocation(jobID, invID, who) | 472 return f.abortInvocation(jobID, invID, who) |
| 473 } | 473 } |
| 474 | 474 |
| 475 func (f *fakeEngine) AbortJob(c context.Context, jobID string, who identity.Iden
tity) error { | 475 func (f *fakeEngine) AbortJob(c context.Context, jobID string, who identity.Iden
tity) error { |
| 476 return f.abortJob(jobID, who) | 476 return f.abortJob(jobID, who) |
| 477 } | 477 } |
| OLD | NEW |