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 "time" | 10 "time" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 . "github.com/luci/luci-go/common/testing/assertions" | 23 . "github.com/luci/luci-go/common/testing/assertions" |
24 . "github.com/smartystreets/goconvey/convey" | 24 . "github.com/smartystreets/goconvey/convey" |
25 ) | 25 ) |
26 | 26 |
27 func TestRegisterStream(t *testing.T) { | 27 func TestRegisterStream(t *testing.T) { |
28 t.Parallel() | 28 t.Parallel() |
29 | 29 |
30 Convey(`With a testing configuration`, t, func() { | 30 Convey(`With a testing configuration`, t, func() { |
31 c, env := ct.Install() | 31 c, env := ct.Install() |
32 » » env.ModServiceConfig(c, func(cfg *svcconfig.Coordinator) { | 32 » » ds.Get(c).Testable().Consistent(true) |
33 » » » cfg.ArchiveDelayMax = google.NewDuration(time.Hour) | 33 |
| 34 » » // Set our archival delays. The project delay is smaller than th
e service |
| 35 » » // delay, so it should be used. |
| 36 » » env.ModServiceConfig(c, func(cfg *svcconfig.Config) { |
| 37 » » » cfg.Coordinator.ArchiveDelayMax = google.NewDuration(24
* time.Hour) |
34 }) | 38 }) |
35 » » ds.Get(c).Testable().Consistent(true) | 39 » » env.ModProjectConfig(c, "proj-foo", func(pcfg *svcconfig.Project
Config) { |
| 40 » » » pcfg.MaxStreamAge = google.NewDuration(time.Hour) |
| 41 » » }) |
36 | 42 |
37 svr := New() | 43 svr := New() |
38 | 44 |
39 Convey(`Returns Forbidden error if not a service.`, func() { | 45 Convey(`Returns Forbidden error if not a service.`, func() { |
40 _, err := svr.RegisterStream(c, &logdog.RegisterStreamRe
quest{}) | 46 _, err := svr.RegisterStream(c, &logdog.RegisterStreamRe
quest{}) |
41 So(err, ShouldBeRPCPermissionDenied) | 47 So(err, ShouldBeRPCPermissionDenied) |
42 }) | 48 }) |
43 | 49 |
44 Convey(`When logged in as a service`, func() { | 50 Convey(`When logged in as a service`, func() { |
45 env.JoinGroup("services") | 51 env.JoinGroup("services") |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 }) | 142 }) |
137 }) | 143 }) |
138 | 144 |
139 Convey(`Will not re-register if secrets
don't match.`, func() { | 145 Convey(`Will not re-register if secrets
don't match.`, func() { |
140 req.Secret[0] = 0xAB | 146 req.Secret[0] = 0xAB |
141 _, err := svr.RegisterStream(c,
&req) | 147 _, err := svr.RegisterStream(c,
&req) |
142 So(err, ShouldBeRPCAlreadyExists
, "Log prefix is already registered") | 148 So(err, ShouldBeRPCAlreadyExists
, "Log prefix is already registered") |
143 }) | 149 }) |
144 }) | 150 }) |
145 | 151 |
| 152 Convey(`Will schedule the correct archival expir
ation delay`, func() { |
| 153 Convey(`When there is no project config
delay.`, func() { |
| 154 env.ModProjectConfig(c, "proj-fo
o", func(pcfg *svcconfig.ProjectConfig) { |
| 155 pcfg.MaxStreamAge = nil |
| 156 }) |
| 157 |
| 158 _, err := svr.RegisterStream(c,
&req) |
| 159 So(err, ShouldBeRPCOK) |
| 160 ds.Get(c).Testable().CatchupInde
xes() |
| 161 |
| 162 // The cleanup archival should b
e scheduled for 24 hours, so advance |
| 163 // 12, confirm no archival, then
advance another 12 and confirm that |
| 164 // archival was tasked. |
| 165 env.Clock.Add(12 * time.Hour) |
| 166 env.DrainTumbleAll(c) |
| 167 So(env.ArchivalPublisher.Hashes(
), ShouldHaveLength, 0) |
| 168 |
| 169 env.Clock.Add(12 * time.Hour) |
| 170 env.DrainTumbleAll(c) |
| 171 So(env.ArchivalPublisher.Hashes(
), ShouldResemble, []string{string(tls.Stream.ID)}) |
| 172 }) |
| 173 |
| 174 Convey(`When there is no service or proj
ect config delay.`, func() { |
| 175 env.ModServiceConfig(c, func(cfg
*svcconfig.Config) { |
| 176 cfg.Coordinator.ArchiveD
elayMax = nil |
| 177 }) |
| 178 env.ModProjectConfig(c, "proj-fo
o", func(pcfg *svcconfig.ProjectConfig) { |
| 179 pcfg.MaxStreamAge = nil |
| 180 }) |
| 181 |
| 182 _, err := svr.RegisterStream(c,
&req) |
| 183 So(err, ShouldBeRPCOK) |
| 184 ds.Get(c).Testable().CatchupInde
xes() |
| 185 |
| 186 // The cleanup archival should b
e scheduled immediately. |
| 187 env.DrainTumbleAll(c) |
| 188 So(env.ArchivalPublisher.Hashes(
), ShouldResemble, []string{string(tls.Stream.ID)}) |
| 189 }) |
| 190 }) |
| 191 |
146 Convey(`Returns internal server error if the dat
astore Get() fails.`, func() { | 192 Convey(`Returns internal server error if the dat
astore Get() fails.`, func() { |
147 c, fb := featureBreaker.FilterRDS(c, nil
) | 193 c, fb := featureBreaker.FilterRDS(c, nil
) |
148 fb.BreakFeatures(errors.New("test error"
), "GetMulti") | 194 fb.BreakFeatures(errors.New("test error"
), "GetMulti") |
149 | 195 |
150 _, err := svr.RegisterStream(c, &req) | 196 _, err := svr.RegisterStream(c, &req) |
151 So(err, ShouldBeRPCInternal) | 197 So(err, ShouldBeRPCInternal) |
152 }) | 198 }) |
153 | 199 |
154 Convey(`Returns internal server error if the Pre
fix Put() fails.`, func() { | 200 Convey(`Returns internal server error if the Pre
fix Put() fails.`, func() { |
155 c, fb := featureBreaker.FilterRDS(c, nil
) | 201 c, fb := featureBreaker.FilterRDS(c, nil
) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 fb.BreakFeatures(errors.New("tes
t error"), "PutMulti") | 260 fb.BreakFeatures(errors.New("tes
t error"), "PutMulti") |
215 | 261 |
216 _, err := rsm.RollForward(c) | 262 _, err := rsm.RollForward(c) |
217 So(err, ShouldBeRPCInternal) | 263 So(err, ShouldBeRPCInternal) |
218 }) | 264 }) |
219 }) | 265 }) |
220 }) | 266 }) |
221 }) | 267 }) |
222 }) | 268 }) |
223 } | 269 } |
OLD | NEW |