| 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 "testing" | 8 "testing" |
| 9 | 9 |
| 10 "github.com/luci/gae/impl/memory" | 10 "github.com/luci/gae/impl/memory" |
| 11 "github.com/luci/gae/service/datastore" | 11 "github.com/luci/gae/service/datastore" |
| 12 "github.com/luci/luci-go/appengine/cmd/dm/distributor" |
| 12 "github.com/luci/luci-go/appengine/cmd/dm/model" | 13 "github.com/luci/luci-go/appengine/cmd/dm/model" |
| 13 "github.com/luci/luci-go/common/api/dm/service/v1" | 14 "github.com/luci/luci-go/common/api/dm/service/v1" |
| 14 . "github.com/luci/luci-go/common/testing/assertions" | 15 . "github.com/luci/luci-go/common/testing/assertions" |
| 15 . "github.com/smartystreets/goconvey/convey" | 16 . "github.com/smartystreets/goconvey/convey" |
| 16 "golang.org/x/net/context" | 17 "golang.org/x/net/context" |
| 17 ) | 18 ) |
| 18 | 19 |
| 19 func TestAddDeps(t *testing.T) { | 20 func TestAddDeps(t *testing.T) { |
| 20 t.Parallel() | 21 t.Parallel() |
| 21 | 22 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 77 |
| 77 Convey("None added already", func() { | 78 Convey("None added already", func() { |
| 78 muts, err := ad.RollForward(c) | 79 muts, err := ad.RollForward(c) |
| 79 So(err, ShouldBeNil) | 80 So(err, ShouldBeNil) |
| 80 So(len(muts), ShouldEqual, len(fds)) | 81 So(len(muts), ShouldEqual, len(fds)) |
| 81 | 82 |
| 82 So(muts[0], ShouldResemble, &AddBackDep{ | 83 So(muts[0], ShouldResemble, &AddBackDep{ |
| 83 Dep: fds[0].Edge(), NeedsAck: tr
ue}) | 84 Dep: fds[0].Edge(), NeedsAck: tr
ue}) |
| 84 | 85 |
| 85 So(ds.Get(a, fds), ShouldBeNil) | 86 So(ds.Get(a, fds), ShouldBeNil) |
| 86 » » » » » So(a.AddingDepsBitmap.Size(), ShouldEqua
l, len(fds)) | 87 » » » » » So(a.DepMap.Size(), ShouldEqual, len(fds
)) |
| 87 » » » » » So(a.WaitingDepBitmap.Size(), ShouldEqua
l, len(fds)) | 88 » » » » » So(a.State, ShouldEqual, dm.Attempt_EXEC
UTING) |
| 88 » » » » » So(a.State, ShouldEqual, dm.Attempt_ADDI
NG_DEPS) | |
| 89 So(fds[0].ForExecution, ShouldEqual, 1) | 89 So(fds[0].ForExecution, ShouldEqual, 1) |
| 90 |
| 91 muts, err = (&FinishExecution{ |
| 92 ad.Auth.Id, &distributor.TaskRes
ult{PersistentState: "hi"}, |
| 93 }).RollForward(c) |
| 94 So(err, ShouldBeNil) |
| 95 So(muts, ShouldBeNil) |
| 96 |
| 97 So(ds.Get(a), ShouldBeNil) |
| 98 So(a.State, ShouldEqual, dm.Attempt_WAIT
ING) |
| 90 }) | 99 }) |
| 91 | 100 |
| 92 Convey("adding new Attempts at the same time", f
unc() { | 101 Convey("adding new Attempts at the same time", f
unc() { |
| 93 » » » » » ad.Atmpts = dm.NewAttemptList(map[string
][]uint32{ | 102 » » » » » ad.Attempts = dm.NewAttemptList(map[stri
ng][]uint32{ |
| 94 "to": {2, 3}, | 103 "to": {2, 3}, |
| 95 "tp": {1}, | 104 "tp": {1}, |
| 96 }) | 105 }) |
| 97 | 106 |
| 98 muts, err := ad.RollForward(c) | 107 muts, err := ad.RollForward(c) |
| 99 So(err, ShouldBeNil) | 108 So(err, ShouldBeNil) |
| 100 So(len(muts), ShouldEqual, len(fds)+3) | 109 So(len(muts), ShouldEqual, len(fds)+3) |
| 101 | 110 |
| 102 So(muts[0], ShouldResemble, &EnsureAttem
pt{dm.NewAttemptID("to", 3)}) | 111 So(muts[0], ShouldResemble, &EnsureAttem
pt{dm.NewAttemptID("to", 3)}) |
| 103 So(muts[1], ShouldResemble, &AddBackDep{ | 112 So(muts[1], ShouldResemble, &AddBackDep{ |
| 104 Dep: fds[0].Edge(), NeedsAck: tr
ue}) | 113 Dep: fds[0].Edge(), NeedsAck: tr
ue}) |
| 105 | 114 |
| 106 So(ds.Get(a, fds), ShouldBeNil) | 115 So(ds.Get(a, fds), ShouldBeNil) |
| 107 » » » » » So(a.AddingDepsBitmap.Size(), ShouldEqua
l, len(fds)) | 116 » » » » » So(a.DepMap.Size(), ShouldEqual, len(fds
)) |
| 108 » » » » » So(a.WaitingDepBitmap.Size(), ShouldEqua
l, len(fds)) | 117 » » » » » So(a.State, ShouldEqual, dm.Attempt_EXEC
UTING) |
| 109 » » » » » So(a.State, ShouldEqual, dm.Attempt_ADDI
NG_DEPS) | |
| 110 So(fds[0].ForExecution, ShouldEqual, 1) | 118 So(fds[0].ForExecution, ShouldEqual, 1) |
| 119 |
| 120 muts, err = (&FinishExecution{ |
| 121 ad.Auth.Id, &distributor.TaskRes
ult{PersistentState: "hi"}, |
| 122 }).RollForward(c) |
| 123 So(err, ShouldBeNil) |
| 124 So(muts, ShouldBeNil) |
| 125 |
| 126 So(ds.Get(a), ShouldBeNil) |
| 127 So(a.State, ShouldEqual, dm.Attempt_WAIT
ING) |
| 111 }) | 128 }) |
| 112 }) | 129 }) |
| 113 }) | 130 }) |
| 114 }) | 131 }) |
| 115 } | 132 } |
| OLD | NEW |