Merge pull request #3582 from ryanslade/time-since
Replace time.Now().Sub(x) with time.Since(x)
This commit is contained in:
commit
64e4afede3
|
@ -325,7 +325,7 @@ func TestCatalogNodes_Blocking(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should block for a while
|
// Should block for a while
|
||||||
if d := time.Now().Sub(start); d < 50*time.Millisecond {
|
if d := time.Since(start); d < 50*time.Millisecond {
|
||||||
errch <- fmt.Errorf("too fast: %v", d)
|
errch <- fmt.Errorf("too fast: %v", d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,7 +192,7 @@ func (s *Server) updateLocalACLs(changes structs.ACLRequests) error {
|
||||||
// Do a smooth rate limit to wait out the min time allowed for
|
// Do a smooth rate limit to wait out the min time allowed for
|
||||||
// each op. If this op took longer than the min, then the sleep
|
// each op. If this op took longer than the min, then the sleep
|
||||||
// time will be negative and we will just move on.
|
// time will be negative and we will just move on.
|
||||||
elapsed := time.Now().Sub(start)
|
elapsed := time.Since(start)
|
||||||
time.Sleep(minTimePerOp - elapsed)
|
time.Sleep(minTimePerOp - elapsed)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -250,7 +250,7 @@ func TestACLReplication_updateLocalACLs_RateLimit(t *testing.T) {
|
||||||
if err := s1.updateLocalACLs(changes); err != nil {
|
if err := s1.updateLocalACLs(changes); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if dur := time.Now().Sub(start); dur < time.Second {
|
if dur := time.Since(start); dur < time.Second {
|
||||||
t.Fatalf("too slow: %9.6f", dur.Seconds())
|
t.Fatalf("too slow: %9.6f", dur.Seconds())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ func TestACLReplication_updateLocalACLs_RateLimit(t *testing.T) {
|
||||||
if err := s1.updateLocalACLs(changes); err != nil {
|
if err := s1.updateLocalACLs(changes); err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
if dur := time.Now().Sub(start); dur < 2*time.Second {
|
if dur := time.Since(start); dur < 2*time.Second {
|
||||||
t.Fatalf("too fast: %9.6f", dur.Seconds())
|
t.Fatalf("too fast: %9.6f", dur.Seconds())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ func TestAutopilot_PromoteNonVoter(t *testing.T) {
|
||||||
if !health.Healthy {
|
if !health.Healthy {
|
||||||
r.Fatalf("bad: %v", health)
|
r.Fatalf("bad: %v", health)
|
||||||
}
|
}
|
||||||
if time.Now().Sub(health.StableSince) < s1.config.AutopilotConfig.ServerStabilizationTime {
|
if time.Since(health.StableSince) < s1.config.AutopilotConfig.ServerStabilizationTime {
|
||||||
r.Fatal("stable period not elapsed")
|
r.Fatal("stable period not elapsed")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1226,7 +1226,7 @@ func TestCatalog_ListServices_Blocking(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should block at least 100ms
|
// Should block at least 100ms
|
||||||
if time.Now().Sub(start) < 100*time.Millisecond {
|
if time.Since(start) < 100*time.Millisecond {
|
||||||
t.Fatalf("too fast")
|
t.Fatalf("too fast")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1273,7 +1273,7 @@ func TestCatalog_ListServices_Timeout(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should block at least 100ms
|
// Should block at least 100ms
|
||||||
if time.Now().Sub(start) < 100*time.Millisecond {
|
if time.Since(start) < 100*time.Millisecond {
|
||||||
t.Fatalf("too fast")
|
t.Fatalf("too fast")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -270,7 +270,7 @@ TRY:
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can wait a bit and retry!
|
// We can wait a bit and retry!
|
||||||
if time.Now().Sub(firstCheck) < c.config.RPCHoldTimeout {
|
if time.Since(firstCheck) < c.config.RPCHoldTimeout {
|
||||||
jitter := lib.RandomStagger(c.config.RPCHoldTimeout / jitterFraction)
|
jitter := lib.RandomStagger(c.config.RPCHoldTimeout / jitterFraction)
|
||||||
select {
|
select {
|
||||||
case <-time.After(jitter):
|
case <-time.After(jitter):
|
||||||
|
|
|
@ -365,7 +365,7 @@ func (c *consulFSM) applyAutopilotUpdate(buf []byte, index uint64) interface{} {
|
||||||
|
|
||||||
func (c *consulFSM) Snapshot() (raft.FSMSnapshot, error) {
|
func (c *consulFSM) Snapshot() (raft.FSMSnapshot, error) {
|
||||||
defer func(start time.Time) {
|
defer func(start time.Time) {
|
||||||
c.logger.Printf("[INFO] consul.fsm: snapshot created in %v", time.Now().Sub(start))
|
c.logger.Printf("[INFO] consul.fsm: snapshot created in %v", time.Since(start))
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
|
|
||||||
return &consulSnapshot{c.state.Snapshot()}, nil
|
return &consulSnapshot{c.state.Snapshot()}, nil
|
||||||
|
|
|
@ -363,7 +363,7 @@ func TestKVSEndpoint_List_Blocking(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should block at least 100ms
|
// Should block at least 100ms
|
||||||
if time.Now().Sub(start) < 100*time.Millisecond {
|
if time.Since(start) < 100*time.Millisecond {
|
||||||
t.Fatalf("too fast")
|
t.Fatalf("too fast")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -244,7 +244,7 @@ RETRY:
|
||||||
if firstCheck.IsZero() {
|
if firstCheck.IsZero() {
|
||||||
firstCheck = time.Now()
|
firstCheck = time.Now()
|
||||||
}
|
}
|
||||||
if time.Now().Sub(firstCheck) < s.config.RPCHoldTimeout {
|
if time.Since(firstCheck) < s.config.RPCHoldTimeout {
|
||||||
jitter := lib.RandomStagger(s.config.RPCHoldTimeout / jitterFraction)
|
jitter := lib.RandomStagger(s.config.RPCHoldTimeout / jitterFraction)
|
||||||
select {
|
select {
|
||||||
case <-time.After(jitter):
|
case <-time.After(jitter):
|
||||||
|
@ -443,7 +443,7 @@ func (s *Server) setQueryMeta(m *structs.QueryMeta) {
|
||||||
m.LastContact = 0
|
m.LastContact = 0
|
||||||
m.KnownLeader = true
|
m.KnownLeader = true
|
||||||
} else {
|
} else {
|
||||||
m.LastContact = time.Now().Sub(s.raft.LastContact())
|
m.LastContact = time.Since(s.raft.LastContact())
|
||||||
m.KnownLeader = (s.raft.Leader() != "")
|
m.KnownLeader = (s.raft.Leader() != "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,7 @@ func (d *DNSServer) handlePtr(resp dns.ResponseWriter, req *dns.Msg) {
|
||||||
metrics.MeasureSinceWithLabels([]string{"dns", "ptr_query"}, s,
|
metrics.MeasureSinceWithLabels([]string{"dns", "ptr_query"}, s,
|
||||||
[]metrics.Label{{Name: "node", Value: d.agent.config.NodeName}})
|
[]metrics.Label{{Name: "node", Value: d.agent.config.NodeName}})
|
||||||
d.logger.Printf("[DEBUG] dns: request for %v (%v) from client %s (%s)",
|
d.logger.Printf("[DEBUG] dns: request for %v (%v) from client %s (%s)",
|
||||||
q, time.Now().Sub(s), resp.RemoteAddr().String(),
|
q, time.Since(s), resp.RemoteAddr().String(),
|
||||||
resp.RemoteAddr().Network())
|
resp.RemoteAddr().Network())
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
|
|
||||||
|
@ -231,7 +231,7 @@ func (d *DNSServer) handleQuery(resp dns.ResponseWriter, req *dns.Msg) {
|
||||||
metrics.MeasureSinceWithLabels([]string{"dns", "domain_query"}, s,
|
metrics.MeasureSinceWithLabels([]string{"dns", "domain_query"}, s,
|
||||||
[]metrics.Label{{Name: "node", Value: d.agent.config.NodeName}})
|
[]metrics.Label{{Name: "node", Value: d.agent.config.NodeName}})
|
||||||
d.logger.Printf("[DEBUG] dns: request for %v (%v) from client %s (%s)",
|
d.logger.Printf("[DEBUG] dns: request for %v (%v) from client %s (%s)",
|
||||||
q, time.Now().Sub(s), resp.RemoteAddr().String(),
|
q, time.Since(s), resp.RemoteAddr().String(),
|
||||||
resp.RemoteAddr().Network())
|
resp.RemoteAddr().Network())
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
|
|
||||||
|
@ -1061,7 +1061,7 @@ func (d *DNSServer) handleRecurse(resp dns.ResponseWriter, req *dns.Msg) {
|
||||||
network := "udp"
|
network := "udp"
|
||||||
defer func(s time.Time) {
|
defer func(s time.Time) {
|
||||||
d.logger.Printf("[DEBUG] dns: request for %v (%s) (%v) from client %s (%s)",
|
d.logger.Printf("[DEBUG] dns: request for %v (%s) (%v) from client %s (%s)",
|
||||||
q, network, time.Now().Sub(s), resp.RemoteAddr().String(),
|
q, network, time.Since(s), resp.RemoteAddr().String(),
|
||||||
resp.RemoteAddr().Network())
|
resp.RemoteAddr().Network())
|
||||||
}(time.Now())
|
}(time.Now())
|
||||||
|
|
||||||
|
|
|
@ -2208,7 +2208,7 @@ func TestDNS_RecursorTimeout(t *testing.T) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
in, _, err := c.Exchange(m, a.DNSAddr())
|
in, _, err := c.Exchange(m, a.DNSAddr())
|
||||||
|
|
||||||
duration := time.Now().Sub(start)
|
duration := time.Since(start)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
|
|
|
@ -274,7 +274,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
|
||||||
// Invoke the handler
|
// Invoke the handler
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
s.agent.logger.Printf("[DEBUG] http: Request %s %v (%v) from=%s", req.Method, logURL, time.Now().Sub(start), req.RemoteAddr)
|
s.agent.logger.Printf("[DEBUG] http: Request %s %v (%v) from=%s", req.Method, logURL, time.Since(start), req.RemoteAddr)
|
||||||
}()
|
}()
|
||||||
obj, err := handler(resp, req)
|
obj, err := handler(resp, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -46,7 +46,7 @@ func TestRexecWriter(t *testing.T) {
|
||||||
if len(b) != 4 {
|
if len(b) != 4 {
|
||||||
t.Fatalf("Bad: %v", b)
|
t.Fatalf("Bad: %v", b)
|
||||||
}
|
}
|
||||||
if time.Now().Sub(start) < writer.BufIdle {
|
if time.Since(start) < writer.BufIdle {
|
||||||
t.Fatalf("too early")
|
t.Fatalf("too early")
|
||||||
}
|
}
|
||||||
case <-time.After(2 * writer.BufIdle):
|
case <-time.After(2 * writer.BufIdle):
|
||||||
|
@ -66,7 +66,7 @@ func TestRexecWriter(t *testing.T) {
|
||||||
if len(b) != 12 {
|
if len(b) != 12 {
|
||||||
t.Fatalf("Bad: %v", b)
|
t.Fatalf("Bad: %v", b)
|
||||||
}
|
}
|
||||||
if time.Now().Sub(start) < writer.BufIdle {
|
if time.Since(start) < writer.BufIdle {
|
||||||
t.Fatalf("too early")
|
t.Fatalf("too early")
|
||||||
}
|
}
|
||||||
case <-time.After(2 * writer.BufIdle):
|
case <-time.After(2 * writer.BufIdle):
|
||||||
|
|
|
@ -661,7 +661,7 @@ func (c *Client) doRequest(r *request) (time.Duration, *http.Response, error) {
|
||||||
}
|
}
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
resp, err := c.config.HttpClient.Do(req)
|
resp, err := c.config.HttpClient.Do(req)
|
||||||
diff := time.Now().Sub(start)
|
diff := time.Since(start)
|
||||||
return diff, resp, err
|
return diff, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,7 @@ WAIT:
|
||||||
|
|
||||||
// Handle the one-shot mode.
|
// Handle the one-shot mode.
|
||||||
if l.opts.LockTryOnce && attempts > 0 {
|
if l.opts.LockTryOnce && attempts > 0 {
|
||||||
elapsed := time.Now().Sub(start)
|
elapsed := time.Since(start)
|
||||||
if elapsed > qOpts.WaitTime {
|
if elapsed > qOpts.WaitTime {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -541,7 +541,7 @@ func TestAPI_LockOneShot(t *testing.T) {
|
||||||
if ch != nil {
|
if ch != nil {
|
||||||
t.Fatalf("should not be leader")
|
t.Fatalf("should not be leader")
|
||||||
}
|
}
|
||||||
diff := time.Now().Sub(start)
|
diff := time.Since(start)
|
||||||
if diff < contender.opts.LockWaitTime || diff > 2*contender.opts.LockWaitTime {
|
if diff < contender.opts.LockWaitTime || diff > 2*contender.opts.LockWaitTime {
|
||||||
t.Fatalf("time out of bounds: %9.6f", diff.Seconds())
|
t.Fatalf("time out of bounds: %9.6f", diff.Seconds())
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ WAIT:
|
||||||
|
|
||||||
// Handle the one-shot mode.
|
// Handle the one-shot mode.
|
||||||
if s.opts.SemaphoreTryOnce && attempts > 0 {
|
if s.opts.SemaphoreTryOnce && attempts > 0 {
|
||||||
elapsed := time.Now().Sub(start)
|
elapsed := time.Since(start)
|
||||||
if elapsed > qOpts.WaitTime {
|
if elapsed > qOpts.WaitTime {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -499,7 +499,7 @@ func TestAPI_SemaphoreOneShot(t *testing.T) {
|
||||||
if ch != nil {
|
if ch != nil {
|
||||||
t.Fatalf("should not have acquired the semaphore")
|
t.Fatalf("should not have acquired the semaphore")
|
||||||
}
|
}
|
||||||
diff := time.Now().Sub(start)
|
diff := time.Since(start)
|
||||||
if diff < contender.opts.SemaphoreWaitTime {
|
if diff < contender.opts.SemaphoreWaitTime {
|
||||||
t.Fatalf("time out of bounds: %9.6f", diff.Seconds())
|
t.Fatalf("time out of bounds: %9.6f", diff.Seconds())
|
||||||
}
|
}
|
||||||
|
|
|
@ -324,7 +324,7 @@ OUTER:
|
||||||
c.UI.Info(fmt.Sprintf("%d / %d node(s) completed / acknowledged", exitCount, ackCount))
|
c.UI.Info(fmt.Sprintf("%d / %d node(s) completed / acknowledged", exitCount, ackCount))
|
||||||
if c.conf.verbose {
|
if c.conf.verbose {
|
||||||
c.UI.Info(fmt.Sprintf("Completed in %0.2f seconds",
|
c.UI.Info(fmt.Sprintf("Completed in %0.2f seconds",
|
||||||
float64(time.Now().Sub(start))/float64(time.Second)))
|
float64(time.Since(start))/float64(time.Second)))
|
||||||
}
|
}
|
||||||
if exitCount < ackCount {
|
if exitCount < ackCount {
|
||||||
badExit++
|
badExit++
|
||||||
|
|
Loading…
Reference in New Issue