| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 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 coordinator | 5 package coordinator |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "sync" | 9 "sync" |
| 10 "sync/atomic" | 10 "sync/atomic" |
| 11 "testing" | 11 "testing" |
| 12 "time" | 12 "time" |
| 13 | 13 |
| 14 "github.com/luci/luci-go/common/clock/testclock" | 14 "github.com/luci/luci-go/common/clock/testclock" |
| 15 "github.com/luci/luci-go/common/errors" | 15 "github.com/luci/luci-go/common/errors" |
| 16 "github.com/luci/luci-go/common/retry" |
| 16 "github.com/luci/luci-go/logdog/common/types" | 17 "github.com/luci/luci-go/logdog/common/types" |
| 17 "github.com/luci/luci-go/luci_config/common/cfgtypes" | 18 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 18 | 19 |
| 19 "golang.org/x/net/context" | 20 "golang.org/x/net/context" |
| 20 | 21 |
| 21 . "github.com/smartystreets/goconvey/convey" | 22 . "github.com/smartystreets/goconvey/convey" |
| 22 ) | 23 ) |
| 23 | 24 |
| 24 // testCoordinator is an implementation of Coordinator that can be used for | 25 // testCoordinator is an implementation of Coordinator that can be used for |
| 25 // testing. | 26 // testing. |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 r2 := <-resultC | 239 r2 := <-resultC |
| 239 | 240 |
| 240 So(r1.ProtoVersion, ShouldEqual, "remote") | 241 So(r1.ProtoVersion, ShouldEqual, "remote") |
| 241 So(r2.ProtoVersion, ShouldEqual, "remote") | 242 So(r2.ProtoVersion, ShouldEqual, "remote") |
| 242 So(tcc.calls, ShouldEqual, 2) | 243 So(tcc.calls, ShouldEqual, 2) |
| 243 }) | 244 }) |
| 244 | 245 |
| 245 Convey(`RegisterStream`, func() { | 246 Convey(`RegisterStream`, func() { |
| 246 Convey(`A transient registration error will resu
lt in a RegisterStream error.`, func() { | 247 Convey(`A transient registration error will resu
lt in a RegisterStream error.`, func() { |
| 247 tcc.errC = make(chan error, 1) | 248 tcc.errC = make(chan error, 1) |
| 248 » » » » » tcc.errC <- errors.WrapTransient(errors.
New("test error")) | 249 » » » » » tcc.errC <- errors.New("test error", ret
ry.Tag) |
| 249 | 250 |
| 250 _, err := ssc.RegisterStream(c, &st, nil
) | 251 _, err := ssc.RegisterStream(c, &st, nil
) |
| 251 So(err, ShouldNotBeNil) | 252 So(err, ShouldNotBeNil) |
| 252 So(tcc.calls, ShouldEqual, 1) | 253 So(tcc.calls, ShouldEqual, 1) |
| 253 | 254 |
| 254 Convey(`A second request will call throu
gh, try again, and succeed.`, func() { | 255 Convey(`A second request will call throu
gh, try again, and succeed.`, func() { |
| 255 tcc.errC = nil | 256 tcc.errC = nil |
| 256 | 257 |
| 257 _, err := ssc.RegisterStream(c,
&st, nil) | 258 _, err := ssc.RegisterStream(c,
&st, nil) |
| 258 So(err, ShouldBeNil) | 259 So(err, ShouldBeNil) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 280 | 281 |
| 281 Convey(`TerminateStream`, func() { | 282 Convey(`TerminateStream`, func() { |
| 282 tr := TerminateRequest{ | 283 tr := TerminateRequest{ |
| 283 Project: st.Project, | 284 Project: st.Project, |
| 284 ID: st.ID, | 285 ID: st.ID, |
| 285 TerminalIndex: 1337, | 286 TerminalIndex: 1337, |
| 286 } | 287 } |
| 287 | 288 |
| 288 Convey(`The termination endpoint returns a trans
ient error, it will propagate.`, func() { | 289 Convey(`The termination endpoint returns a trans
ient error, it will propagate.`, func() { |
| 289 tcc.errC = make(chan error, 1) | 290 tcc.errC = make(chan error, 1) |
| 290 » » » » » tcc.errC <- errors.WrapTransient(errors.
New("test error")) | 291 » » » » » tcc.errC <- errors.New("test error", ret
ry.Tag) |
| 291 | 292 |
| 292 err := ssc.TerminateStream(c, &tr) | 293 err := ssc.TerminateStream(c, &tr) |
| 293 » » » » » So(errors.IsTransient(err), ShouldBeTrue
) | 294 » » » » » So(retry.Tag.In(err), ShouldBeTrue) |
| 294 So(tcc.calls, ShouldEqual, 1) | 295 So(tcc.calls, ShouldEqual, 1) |
| 295 | 296 |
| 296 Convey(`A second attempt will call throu
gh, try again, and succeed.`, func() { | 297 Convey(`A second attempt will call throu
gh, try again, and succeed.`, func() { |
| 297 tcc.errC = nil | 298 tcc.errC = nil |
| 298 | 299 |
| 299 err := ssc.TerminateStream(c, &t
r) | 300 err := ssc.TerminateStream(c, &t
r) |
| 300 So(err, ShouldBeNil) | 301 So(err, ShouldBeNil) |
| 301 So(tcc.calls, ShouldEqual, 2) | 302 So(tcc.calls, ShouldEqual, 2) |
| 302 }) | 303 }) |
| 303 }) | 304 }) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 remotes := 0 | 389 remotes := 0 |
| 389 for i := 0; i < count; i++ { | 390 for i := 0; i < count; i++ { |
| 390 if state[i].ProtoVersion == "remote" { | 391 if state[i].ProtoVersion == "remote" { |
| 391 remotes++ | 392 remotes++ |
| 392 } | 393 } |
| 393 } | 394 } |
| 394 So(remotes, ShouldEqual, count) | 395 So(remotes, ShouldEqual, count) |
| 395 }) | 396 }) |
| 396 }) | 397 }) |
| 397 } | 398 } |
| OLD | NEW |