OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 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 mutate | 5 package mutate |
6 | 6 |
7 import ( | 7 import ( |
| 8 "fmt" |
8 "testing" | 9 "testing" |
| 10 "time" |
9 | 11 |
10 » "github.com/luci/gae/impl/memory" | 12 » . "github.com/smartystreets/goconvey/convey" |
| 13 |
| 14 » "github.com/luci/gae/service/datastore" |
| 15 » "github.com/luci/luci-go/appengine/cmd/dm/distributor/fake" |
| 16 » "github.com/luci/luci-go/appengine/cmd/dm/model" |
11 "github.com/luci/luci-go/common/api/dm/service/v1" | 17 "github.com/luci/luci-go/common/api/dm/service/v1" |
12 » . "github.com/smartystreets/goconvey/convey" | 18 » "github.com/luci/luci-go/common/errors" |
13 » "golang.org/x/net/context" | 19 » . "github.com/luci/luci-go/common/testing/assertions" |
14 ) | 20 ) |
15 | 21 |
16 func TestScheduleExecution(t *testing.T) { | 22 func TestScheduleExecution(t *testing.T) { |
17 t.Parallel() | 23 t.Parallel() |
18 | 24 |
19 Convey("ScheduleExecution", t, func() { | 25 Convey("ScheduleExecution", t, func() { |
20 » » c := memory.Use(context.Background()) | 26 » » _, c, dist, _ := fake.Setup(FinishExecutionFn) |
21 » » se := &ScheduleExecution{dm.NewAttemptID("quest", 1)} | 27 |
| 28 » » qdesc := fake.QuestDesc("quest") |
| 29 » » qid := qdesc.QuestID() |
| 30 » » se := &ScheduleExecution{dm.NewAttemptID(qid, 1)} |
22 | 31 |
23 Convey("Root", func() { | 32 Convey("Root", func() { |
24 » » » So(se.Root(c).String(), ShouldEqual, `dev~app::/Attempt,
"quest|fffffffe"`) | 33 » » » So(se.Root(c).String(), ShouldEqual, fmt.Sprintf(`dev~ap
p::/Attempt,"%s|fffffffe"`, qid)) |
25 }) | 34 }) |
26 | 35 |
27 Convey("RollForward", func() { | 36 Convey("RollForward", func() { |
28 » » » muts, err := se.RollForward(c) | 37 » » » ds := datastore.Get(c) |
29 » » » So(err, ShouldBeNil) | 38 » » » q := &model.Quest{ID: qid, Desc: *qdesc} |
30 » » » So(muts, ShouldBeNil) | 39 » » » a := &model.Attempt{ |
| 40 » » » » ID: *se.For, |
| 41 » » » » State: dm.Attempt_SCHEDULING, |
| 42 » » » } |
| 43 » » » e := model.ExecutionFromID(c, dm.NewExecutionID(qid, 1,
1)) |
| 44 » » » So(ds.PutMulti([]interface{}{q, a}), ShouldBeNil) |
| 45 |
| 46 » » » Convey("basic", func() { |
| 47 » » » » dist.TimeToStart = time.Minute * 5 |
| 48 |
| 49 » » » » muts, err := se.RollForward(c) |
| 50 » » » » So(err, ShouldBeNil) |
| 51 » » » » So(muts, ShouldBeNil) |
| 52 |
| 53 » » » » So(ds.GetMulti([]interface{}{a, e}), ShouldBeNil
) |
| 54 » » » » Convey("distributor information is saved", func(
) { |
| 55 » » » » » tok := fake.MkToken(dm.NewExecutionID(qi
d, 1, 1)) |
| 56 |
| 57 » » » » » So(a.State, ShouldEqual, dm.Attempt_EXEC
UTING) |
| 58 » » » » » So(e.State, ShouldEqual, dm.Execution_SC
HEDULING) |
| 59 » » » » » So(e.DistributorConfigName, ShouldEqual,
"fakeDistributor") |
| 60 » » » » » So(e.DistributorToken, ShouldEqual, tok) |
| 61 » » » » » So(e.DistributorConfigVersion, ShouldEqu
al, "testing") |
| 62 » » » » » So(e.TimeToStart, ShouldEqual, time.Minu
te*5) |
| 63 » » » » }) |
| 64 » » » » Convey("a timeout is set", func() { |
| 65 » » » » » ex, err := ds.Exists(ds.MakeKey( |
| 66 » » » » » » "Attempt", a.ID.DMEncoded(), |
| 67 » » » » » » "Execution", 1, |
| 68 » » » » » » "tumble.Mutation", "n:timeout")) |
| 69 » » » » » So(err, ShouldBeNil) |
| 70 » » » » » So(ex.All(), ShouldBeTrue) |
| 71 » » » » }) |
| 72 » » » }) |
| 73 |
| 74 » » » Convey("transient", func() { |
| 75 » » » » dist.RunError = errors.WrapTransient(errors.New(
"transient failure")) |
| 76 |
| 77 » » » » muts, err := se.RollForward(c) |
| 78 » » » » So(err, ShouldErrLike, "transient") |
| 79 » » » » So(muts, ShouldBeNil) |
| 80 » » » }) |
| 81 |
| 82 » » » Convey("rejection", func() { |
| 83 » » » » dist.RunError = errors.New("no soup for you") |
| 84 |
| 85 » » » » muts, err := se.RollForward(c) |
| 86 » » » » So(err, ShouldBeNil) |
| 87 » » » » So(muts, ShouldBeNil) |
| 88 |
| 89 » » » » So(ds.GetMulti([]interface{}{a, e}), ShouldBeNil
) |
| 90 » » » » So(a.State, ShouldEqual, dm.Attempt_ABNORMAL_FIN
ISHED) |
| 91 » » » » So(a.AbnormalFinish.Status, ShouldEqual, dm.Abno
rmalFinish_REJECTED) |
| 92 » » » » So(a.AbnormalFinish.Reason, ShouldContainSubstri
ng, "non-transient") |
| 93 |
| 94 » » » » So(e.State, ShouldEqual, dm.Execution_ABNORMAL_F
INISHED) |
| 95 » » » » So(e.AbnormalFinish.Status, ShouldEqual, dm.Abno
rmalFinish_REJECTED) |
| 96 » » » » So(e.AbnormalFinish.Reason, ShouldContainSubstri
ng, "non-transient") |
| 97 » » » }) |
| 98 |
31 }) | 99 }) |
32 }) | 100 }) |
33 } | 101 } |
OLD | NEW |