| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package services | 5 package services |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "testing" | 9 "testing" |
| 10 | 10 |
| 11 "github.com/luci/gae/filter/featureBreaker" | 11 "github.com/luci/gae/filter/featureBreaker" |
| 12 "github.com/luci/gae/impl/memory" | 12 "github.com/luci/gae/impl/memory" |
| 13 ds "github.com/luci/gae/service/datastore" | 13 ds "github.com/luci/gae/service/datastore" |
| 14 "github.com/luci/luci-go/appengine/logdog/coordinator" | 14 "github.com/luci/luci-go/appengine/logdog/coordinator" |
| 15 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest
" | 15 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest
" |
| 16 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" | 16 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" |
| 17 "github.com/luci/luci-go/common/logging/gologger" |
| 17 "github.com/luci/luci-go/common/proto/logdog/svcconfig" | 18 "github.com/luci/luci-go/common/proto/logdog/svcconfig" |
| 18 "github.com/luci/luci-go/server/auth" | 19 "github.com/luci/luci-go/server/auth" |
| 19 "github.com/luci/luci-go/server/auth/authtest" | 20 "github.com/luci/luci-go/server/auth/authtest" |
| 20 "golang.org/x/net/context" | 21 "golang.org/x/net/context" |
| 22 "google.golang.org/grpc/codes" |
| 21 | 23 |
| 22 . "github.com/luci/luci-go/common/testing/assertions" | 24 . "github.com/luci/luci-go/common/testing/assertions" |
| 23 . "github.com/smartystreets/goconvey/convey" | 25 . "github.com/smartystreets/goconvey/convey" |
| 24 ) | 26 ) |
| 25 | 27 |
| 26 func TestArchiveStream(t *testing.T) { | 28 func TestArchiveStream(t *testing.T) { |
| 27 t.Parallel() | 29 t.Parallel() |
| 28 | 30 |
| 29 Convey(`With a testing configuration`, t, func() { | 31 Convey(`With a testing configuration`, t, func() { |
| 30 c := memory.Use(context.Background()) | 32 c := memory.Use(context.Background()) |
| 33 c = gologger.Use(c) |
| 31 be := Server{} | 34 be := Server{} |
| 32 | 35 |
| 33 c = ct.UseConfig(c, &svcconfig.Coordinator{ | 36 c = ct.UseConfig(c, &svcconfig.Coordinator{ |
| 34 ServiceAuthGroup: "test-services", | 37 ServiceAuthGroup: "test-services", |
| 35 }) | 38 }) |
| 36 fs := authtest.FakeState{} | 39 fs := authtest.FakeState{} |
| 37 c = auth.WithState(c, &fs) | 40 c = auth.WithState(c, &fs) |
| 38 | 41 |
| 39 // Register a testing log stream (not archived). | 42 // Register a testing log stream (not archived). |
| 40 ls := ct.TestLogStream(c, ct.TestLogStreamDescriptor(c, "foo")) | 43 ls := ct.TestLogStream(c, ct.TestLogStreamDescriptor(c, "foo")) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 109 |
| 107 _, err := be.ArchiveStream(c, req) | 110 _, err := be.ArchiveStream(c, req) |
| 108 So(err, ShouldBeNil) | 111 So(err, ShouldBeNil) |
| 109 | 112 |
| 110 ls.TerminalIndex = -1 // To make sure it reloade
d. | 113 ls.TerminalIndex = -1 // To make sure it reloade
d. |
| 111 So(ds.Get(c).Get(ls), ShouldBeNil) | 114 So(ds.Get(c).Get(ls), ShouldBeNil) |
| 112 So(ls.Archived(), ShouldBeTrue) | 115 So(ls.Archived(), ShouldBeTrue) |
| 113 So(ls.TerminalIndex, ShouldEqual, 1337) | 116 So(ls.TerminalIndex, ShouldEqual, 1337) |
| 114 }) | 117 }) |
| 115 | 118 |
| 119 Convey(`If the archive has failed`, func() { |
| 120 req.Error = true |
| 121 |
| 122 Convey(`If the stream is below error threshold,
will increment error count and return FailedPrecondition.`, func() { |
| 123 ls.ArchiveErrors = 0 |
| 124 So(ls.ArchiveErrors, ShouldBeLessThan, m
axArchiveErrors) |
| 125 So(ls.Put(ds.Get(c)), ShouldBeNil) |
| 126 |
| 127 _, err := be.ArchiveStream(c, req) |
| 128 So(err, ShouldHaveRPCCode, codes.FailedP
recondition) |
| 129 |
| 130 So(ds.Get(c).Get(ls), ShouldBeNil) |
| 131 So(ls.Archived(), ShouldBeFalse) |
| 132 So(ls.ArchiveErrors, ShouldEqual, 1) |
| 133 }) |
| 134 |
| 135 Convey(`If the stream is above error threshold,
will succeed.`, func() { |
| 136 ls.ArchiveErrors = maxArchiveErrors |
| 137 So(ls.Put(ds.Get(c)), ShouldBeNil) |
| 138 |
| 139 _, err := be.ArchiveStream(c, req) |
| 140 So(err, ShouldBeNil) |
| 141 So(ds.Get(c).Get(ls), ShouldBeNil) |
| 142 So(ls.Archived(), ShouldBeTrue) |
| 143 So(ls.TerminalIndex, ShouldEqual, 13) |
| 144 }) |
| 145 }) |
| 146 |
| 116 Convey(`When datastore Get fails, returns internal error
.`, func() { | 147 Convey(`When datastore Get fails, returns internal error
.`, func() { |
| 117 c, fb := featureBreaker.FilterRDS(c, nil) | 148 c, fb := featureBreaker.FilterRDS(c, nil) |
| 118 fb.BreakFeatures(errors.New("test error"), "GetM
ulti") | 149 fb.BreakFeatures(errors.New("test error"), "GetM
ulti") |
| 119 | 150 |
| 120 _, err := be.ArchiveStream(c, req) | 151 _, err := be.ArchiveStream(c, req) |
| 121 So(err, ShouldBeRPCInternal) | 152 So(err, ShouldBeRPCInternal) |
| 122 }) | 153 }) |
| 123 | 154 |
| 124 Convey(`When datastore Put fails, returns internal error
.`, func() { | 155 Convey(`When datastore Put fails, returns internal error
.`, func() { |
| 125 c, fb := featureBreaker.FilterRDS(c, nil) | 156 c, fb := featureBreaker.FilterRDS(c, nil) |
| 126 fb.BreakFeatures(errors.New("test error"), "PutM
ulti") | 157 fb.BreakFeatures(errors.New("test error"), "PutM
ulti") |
| 127 | 158 |
| 128 _, err := be.ArchiveStream(c, req) | 159 _, err := be.ArchiveStream(c, req) |
| 129 So(err, ShouldBeRPCInternal) | 160 So(err, ShouldBeRPCInternal) |
| 130 }) | 161 }) |
| 131 }) | 162 }) |
| 132 }) | 163 }) |
| 133 } | 164 } |
| OLD | NEW |