rpc/lib/client: jitter test updates and only to-be run on releases

* Updated code with feedback from @melekes, @ebuchman and @silasdavis.
* Added Makefile clause `release` to only run the test on seeing tag
`release` during releases i.e
```shell
make release
```
which will run the comprehensive and long integration-ish tests.
This commit is contained in:
Emmanuel Odeke
2017-10-25 19:20:33 -07:00
parent 5504920ba3
commit 6e5cd10399
4 changed files with 73 additions and 58 deletions

View File

@ -254,10 +254,11 @@ func (c *WSClient) reconnect() error {
c.mtx.Unlock()
}()
_1sAsNs := float64(time.Second.Nanoseconds())
// 1s == (1e9 ns) == (1 Billion ns)
billionNs := float64(time.Second.Nanoseconds())
for {
jitter := time.Duration(rand.Float64() * _1sAsNs)
backoffDuration := jitter + ((1 << uint(attempt)) * time.Second)
jitterSeconds := time.Duration(rand.Float64() * billionNs)
backoffDuration := jitterSeconds + ((1 << uint(attempt)) * time.Second)
c.Logger.Info("reconnecting", "attempt", attempt+1, "backoff_duration", backoffDuration)
time.Sleep(backoffDuration)