mirror of https://github.com/status-im/consul.git
Replace time.Now().Sub(x) with time.Since(x)
This commit is contained in:
parent
d5a889c160
commit
85e4aea9d1
|
@ -325,7 +325,7 @@ func TestCatalogNodes_Blocking(t *testing.T) {
|
|||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
// each op. If this op took longer than the min, then the sleep
|
||||
// time will be negative and we will just move on.
|
||||
elapsed := time.Now().Sub(start)
|
||||
elapsed := time.Since(start)
|
||||
time.Sleep(minTimePerOp - elapsed)
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -250,7 +250,7 @@ func TestACLReplication_updateLocalACLs_RateLimit(t *testing.T) {
|
|||
if err := s1.updateLocalACLs(changes); err != nil {
|
||||
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())
|
||||
}
|
||||
|
||||
|
@ -268,7 +268,7 @@ func TestACLReplication_updateLocalACLs_RateLimit(t *testing.T) {
|
|||
if err := s1.updateLocalACLs(changes); err != nil {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -231,7 +231,7 @@ func TestAutopilot_PromoteNonVoter(t *testing.T) {
|
|||
if !health.Healthy {
|
||||
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")
|
||||
}
|
||||
})
|
||||
|
|
|
@ -1226,7 +1226,7 @@ func TestCatalog_ListServices_Blocking(t *testing.T) {
|
|||
}
|
||||
|
||||
// Should block at least 100ms
|
||||
if time.Now().Sub(start) < 100*time.Millisecond {
|
||||
if time.Since(start) < 100*time.Millisecond {
|
||||
t.Fatalf("too fast")
|
||||
}
|
||||
|
||||
|
@ -1273,7 +1273,7 @@ func TestCatalog_ListServices_Timeout(t *testing.T) {
|
|||
}
|
||||
|
||||
// Should block at least 100ms
|
||||
if time.Now().Sub(start) < 100*time.Millisecond {
|
||||
if time.Since(start) < 100*time.Millisecond {
|
||||
t.Fatalf("too fast")
|
||||
}
|
||||
|
||||
|
|
|
@ -270,7 +270,7 @@ TRY:
|
|||
}
|
||||
|
||||
// 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)
|
||||
select {
|
||||
case <-time.After(jitter):
|
||||
|
|
|
@ -365,7 +365,7 @@ func (c *consulFSM) applyAutopilotUpdate(buf []byte, index uint64) interface{} {
|
|||
|
||||
func (c *consulFSM) Snapshot() (raft.FSMSnapshot, error) {
|
||||
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())
|
||||
|
||||
return &consulSnapshot{c.state.Snapshot()}, nil
|
||||
|
|
|
@ -363,7 +363,7 @@ func TestKVSEndpoint_List_Blocking(t *testing.T) {
|
|||
}
|
||||
|
||||
// Should block at least 100ms
|
||||
if time.Now().Sub(start) < 100*time.Millisecond {
|
||||
if time.Since(start) < 100*time.Millisecond {
|
||||
t.Fatalf("too fast")
|
||||
}
|
||||
|
||||
|
|
|
@ -244,7 +244,7 @@ RETRY:
|
|||
if firstCheck.IsZero() {
|
||||
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)
|
||||
select {
|
||||
case <-time.After(jitter):
|
||||
|
@ -443,7 +443,7 @@ func (s *Server) setQueryMeta(m *structs.QueryMeta) {
|
|||
m.LastContact = 0
|
||||
m.KnownLeader = true
|
||||
} else {
|
||||
m.LastContact = time.Now().Sub(s.raft.LastContact())
|
||||
m.LastContact = time.Since(s.raft.LastContact())
|
||||
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.Label{{Name: "node", Value: d.agent.config.NodeName}})
|
||||
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())
|
||||
}(time.Now())
|
||||
|
||||
|
@ -231,7 +231,7 @@ func (d *DNSServer) handleQuery(resp dns.ResponseWriter, req *dns.Msg) {
|
|||
metrics.MeasureSinceWithLabels([]string{"dns", "domain_query"}, s,
|
||||
[]metrics.Label{{Name: "node", Value: d.agent.config.NodeName}})
|
||||
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())
|
||||
}(time.Now())
|
||||
|
||||
|
@ -1061,7 +1061,7 @@ func (d *DNSServer) handleRecurse(resp dns.ResponseWriter, req *dns.Msg) {
|
|||
network := "udp"
|
||||
defer func(s time.Time) {
|
||||
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())
|
||||
}(time.Now())
|
||||
|
||||
|
|
|
@ -2208,7 +2208,7 @@ func TestDNS_RecursorTimeout(t *testing.T) {
|
|||
start := time.Now()
|
||||
in, _, err := c.Exchange(m, a.DNSAddr())
|
||||
|
||||
duration := time.Now().Sub(start)
|
||||
duration := time.Since(start)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
|
|
|
@ -274,7 +274,7 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque
|
|||
// Invoke the handler
|
||||
start := time.Now()
|
||||
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)
|
||||
if err != nil {
|
||||
|
|
|
@ -46,7 +46,7 @@ func TestRexecWriter(t *testing.T) {
|
|||
if len(b) != 4 {
|
||||
t.Fatalf("Bad: %v", b)
|
||||
}
|
||||
if time.Now().Sub(start) < writer.BufIdle {
|
||||
if time.Since(start) < writer.BufIdle {
|
||||
t.Fatalf("too early")
|
||||
}
|
||||
case <-time.After(2 * writer.BufIdle):
|
||||
|
@ -66,7 +66,7 @@ func TestRexecWriter(t *testing.T) {
|
|||
if len(b) != 12 {
|
||||
t.Fatalf("Bad: %v", b)
|
||||
}
|
||||
if time.Now().Sub(start) < writer.BufIdle {
|
||||
if time.Since(start) < writer.BufIdle {
|
||||
t.Fatalf("too early")
|
||||
}
|
||||
case <-time.After(2 * writer.BufIdle):
|
||||
|
|
|
@ -661,7 +661,7 @@ func (c *Client) doRequest(r *request) (time.Duration, *http.Response, error) {
|
|||
}
|
||||
start := time.Now()
|
||||
resp, err := c.config.HttpClient.Do(req)
|
||||
diff := time.Now().Sub(start)
|
||||
diff := time.Since(start)
|
||||
return diff, resp, err
|
||||
}
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ WAIT:
|
|||
|
||||
// Handle the one-shot mode.
|
||||
if l.opts.LockTryOnce && attempts > 0 {
|
||||
elapsed := time.Now().Sub(start)
|
||||
elapsed := time.Since(start)
|
||||
if elapsed > qOpts.WaitTime {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -541,7 +541,7 @@ func TestAPI_LockOneShot(t *testing.T) {
|
|||
if ch != nil {
|
||||
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 {
|
||||
t.Fatalf("time out of bounds: %9.6f", diff.Seconds())
|
||||
}
|
||||
|
|
|
@ -198,7 +198,7 @@ WAIT:
|
|||
|
||||
// Handle the one-shot mode.
|
||||
if s.opts.SemaphoreTryOnce && attempts > 0 {
|
||||
elapsed := time.Now().Sub(start)
|
||||
elapsed := time.Since(start)
|
||||
if elapsed > qOpts.WaitTime {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
@ -499,7 +499,7 @@ func TestAPI_SemaphoreOneShot(t *testing.T) {
|
|||
if ch != nil {
|
||||
t.Fatalf("should not have acquired the semaphore")
|
||||
}
|
||||
diff := time.Now().Sub(start)
|
||||
diff := time.Since(start)
|
||||
if diff < contender.opts.SemaphoreWaitTime {
|
||||
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))
|
||||
if c.conf.verbose {
|
||||
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 {
|
||||
badExit++
|
||||
|
|
Loading…
Reference in New Issue