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

Unified Diff: appengine/cmd/dm/deps/activate_execution_test.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: self review Created 4 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
Index: appengine/cmd/dm/deps/activate_execution_test.go
diff --git a/appengine/cmd/dm/deps/activate_execution_test.go b/appengine/cmd/dm/deps/activate_execution_test.go
index d17848785bba65eb3ae9b59cae38699e62ea365e..c4790ca32ac25321722a49509bf27c44bd3ab757 100644
--- a/appengine/cmd/dm/deps/activate_execution_test.go
+++ b/appengine/cmd/dm/deps/activate_execution_test.go
@@ -7,8 +7,7 @@ package deps
import (
"testing"
- "github.com/luci/gae/service/datastore"
- "github.com/luci/luci-go/appengine/tumble"
+ "github.com/luci/luci-go/appengine/cmd/dm/distributor/fake"
dm "github.com/luci/luci-go/common/api/dm/service/v1"
. "github.com/luci/luci-go/common/testing/assertions"
. "github.com/smartystreets/goconvey/convey"
@@ -18,65 +17,62 @@ func TestActivateExecution(t *testing.T) {
t.Parallel()
Convey("Test ActivateExecution", t, func() {
- ttest := &tumble.Testing{}
- c := ttest.Context()
- ds := datastore.Get(c)
- _ = ds
- s := newDecoratedDeps()
+ ttest, c, dist, s := testSetup()
- qid := ensureQuest(c, "foo", 1)
+ qid := s.ensureQuest(c, "foo", 1)
ttest.Drain(c)
- realAuth := execute(c, dm.NewAttemptID(qid, 1))
eid := dm.NewExecutionID(qid, 1, 1)
-
- req := &dm.ActivateExecutionReq{
- Auth: &dm.Execution_Auth{Id: eid},
- ExecutionToken: []byte("newtok"),
- }
-
- Convey("bad", func() {
- Convey("wrong token", func() {
- _, err := s.ActivateExecution(c, req)
- So(err, ShouldBeRPCUnauthenticated, "failed to activate")
- })
-
- Convey("wrong token (already activated)", func() {
- req.Auth.Token = realAuth.Token
- _, err := s.ActivateExecution(c, req)
- So(err, ShouldBeNil)
-
- req.Auth.Token = []byte("bad sekret")
- req.ExecutionToken = []byte("random other tok")
- _, err = s.ActivateExecution(c, req)
- So(err, ShouldBeRPCUnauthenticated, "failed to activate")
+ dist.RunTask(c, eid, func(tsk *fake.Task) error {
+ req := &dm.ActivateExecutionReq{
+ Auth: &dm.Execution_Auth{Id: eid},
+ ExecutionToken: []byte("sufficiently long new 'random' token"),
+ }
+
+ Convey("bad", func() {
+ Convey("wrong token", func() {
+ _, err := s.ActivateExecution(c, req)
+ So(err, ShouldBeRPCUnauthenticated, "failed to activate")
+ })
+
+ Convey("wrong token (already activated)", func() {
+ req.Auth.Token = tsk.Auth.Token
+ _, err := s.ActivateExecution(c, req)
+ So(err, ShouldBeNil)
+
+ req.Auth.Token = []byte("bad sekret")
+ req.ExecutionToken = []byte("random other super duper long token")
+ _, err = s.ActivateExecution(c, req)
+ So(err, ShouldBeRPCUnauthenticated, "failed to activate")
+ })
+
+ Convey("concurrent activation", func() {
+ req.Auth.Token = tsk.Auth.Token
+ _, err := s.ActivateExecution(c, req)
+ So(err, ShouldBeNil)
+
+ req.ExecutionToken = append(req.ExecutionToken, []byte(" (but incorrect)")...)
+ _, err = s.ActivateExecution(c, req)
+ So(err, ShouldBeRPCUnauthenticated, "failed to activate")
+ })
})
- Convey("concurrent activation", func() {
- req.Auth.Token = realAuth.Token
- _, err := s.ActivateExecution(c, req)
- So(err, ShouldBeNil)
+ Convey("good", func() {
+ req.Auth.Token = tsk.Auth.Token
- req.ExecutionToken = []byte("other newtok")
- _, err = s.ActivateExecution(c, req)
- So(err, ShouldBeRPCUnauthenticated, "failed to activate")
- })
- })
-
- Convey("good", func() {
- req.Auth.Token = realAuth.Token
-
- Convey("normal activation", func() {
- _, err := s.ActivateExecution(c, req)
- So(err, ShouldBeNil)
- })
+ Convey("normal activation", func() {
+ _, err := s.ActivateExecution(c, req)
+ So(err, ShouldBeNil)
+ })
- Convey("repeated activation", func() {
- _, err := s.ActivateExecution(c, req)
- So(err, ShouldBeNil)
- _, err = s.ActivateExecution(c, req)
- So(err, ShouldBeNil)
+ Convey("repeated activation", func() {
+ _, err := s.ActivateExecution(c, req)
+ So(err, ShouldBeNil)
+ _, err = s.ActivateExecution(c, req)
+ So(err, ShouldBeNil)
+ })
})
+ return nil
})
})
}

Powered by Google App Engine
This is Rietveld 408576698