Remove shadowing of built-ins (#2290)
This commit is contained in:
@ -125,13 +125,13 @@ func fakeNameDialer(addr string, timeout time.Duration) (net.Conn, error) {
|
||||
// merge merges the new client stats into current stats.
|
||||
//
|
||||
// It's a test-only method. rpcStats is defined in grpclb_picker.
|
||||
func (s *rpcStats) merge(new *lbpb.ClientStats) {
|
||||
atomic.AddInt64(&s.numCallsStarted, new.NumCallsStarted)
|
||||
atomic.AddInt64(&s.numCallsFinished, new.NumCallsFinished)
|
||||
atomic.AddInt64(&s.numCallsFinishedWithClientFailedToSend, new.NumCallsFinishedWithClientFailedToSend)
|
||||
atomic.AddInt64(&s.numCallsFinishedKnownReceived, new.NumCallsFinishedKnownReceived)
|
||||
func (s *rpcStats) merge(cs *lbpb.ClientStats) {
|
||||
atomic.AddInt64(&s.numCallsStarted, cs.NumCallsStarted)
|
||||
atomic.AddInt64(&s.numCallsFinished, cs.NumCallsFinished)
|
||||
atomic.AddInt64(&s.numCallsFinishedWithClientFailedToSend, cs.NumCallsFinishedWithClientFailedToSend)
|
||||
atomic.AddInt64(&s.numCallsFinishedKnownReceived, cs.NumCallsFinishedKnownReceived)
|
||||
s.mu.Lock()
|
||||
for _, perToken := range new.CallsFinishedWithDrop {
|
||||
for _, perToken := range cs.CallsFinishedWithDrop {
|
||||
s.numCallsDropped[perToken.LoadBalanceToken] += perToken.NumCalls
|
||||
}
|
||||
s.mu.Unlock()
|
||||
@ -156,24 +156,24 @@ func atomicEqual(a, b *int64) bool {
|
||||
// equal compares two rpcStats.
|
||||
//
|
||||
// It's a test-only method. rpcStats is defined in grpclb_picker.
|
||||
func (s *rpcStats) equal(new *rpcStats) bool {
|
||||
if !atomicEqual(&s.numCallsStarted, &new.numCallsStarted) {
|
||||
func (s *rpcStats) equal(o *rpcStats) bool {
|
||||
if !atomicEqual(&s.numCallsStarted, &o.numCallsStarted) {
|
||||
return false
|
||||
}
|
||||
if !atomicEqual(&s.numCallsFinished, &new.numCallsFinished) {
|
||||
if !atomicEqual(&s.numCallsFinished, &o.numCallsFinished) {
|
||||
return false
|
||||
}
|
||||
if !atomicEqual(&s.numCallsFinishedWithClientFailedToSend, &new.numCallsFinishedWithClientFailedToSend) {
|
||||
if !atomicEqual(&s.numCallsFinishedWithClientFailedToSend, &o.numCallsFinishedWithClientFailedToSend) {
|
||||
return false
|
||||
}
|
||||
if !atomicEqual(&s.numCallsFinishedKnownReceived, &new.numCallsFinishedKnownReceived) {
|
||||
if !atomicEqual(&s.numCallsFinishedKnownReceived, &o.numCallsFinishedKnownReceived) {
|
||||
return false
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
new.mu.Lock()
|
||||
defer new.mu.Unlock()
|
||||
if !mapsEqual(s.numCallsDropped, new.numCallsDropped) {
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
if !mapsEqual(s.numCallsDropped, o.numCallsDropped) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
@ -114,14 +114,14 @@ var (
|
||||
)
|
||||
|
||||
func unaryBenchmark(startTimer func(), stopTimer func(int32), benchFeatures stats.Features, benchtime time.Duration, s *stats.Stats) {
|
||||
caller, close := makeFuncUnary(benchFeatures)
|
||||
defer close()
|
||||
caller, cleanup := makeFuncUnary(benchFeatures)
|
||||
defer cleanup()
|
||||
runBenchmark(caller, startTimer, stopTimer, benchFeatures, benchtime, s)
|
||||
}
|
||||
|
||||
func streamBenchmark(startTimer func(), stopTimer func(int32), benchFeatures stats.Features, benchtime time.Duration, s *stats.Stats) {
|
||||
caller, close := makeFuncStream(benchFeatures)
|
||||
defer close()
|
||||
caller, cleanup := makeFuncStream(benchFeatures)
|
||||
defer cleanup()
|
||||
runBenchmark(caller, startTimer, stopTimer, benchFeatures, benchtime, s)
|
||||
}
|
||||
|
||||
|
@ -51,12 +51,12 @@ func (h *lockingHistogram) add(value int64) {
|
||||
h.histogram.Add(value)
|
||||
}
|
||||
|
||||
// swap sets h.histogram to new, and returns its old value.
|
||||
func (h *lockingHistogram) swap(new *stats.Histogram) *stats.Histogram {
|
||||
// swap sets h.histogram to o and returns its old value.
|
||||
func (h *lockingHistogram) swap(o *stats.Histogram) *stats.Histogram {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
old := h.histogram
|
||||
h.histogram = new
|
||||
h.histogram = o
|
||||
return old
|
||||
}
|
||||
|
||||
|
@ -89,8 +89,8 @@ func (t *testRPCStream) Send(req *altspb.HandshakerReq) error {
|
||||
}
|
||||
} else {
|
||||
// Add delay to test concurrent calls.
|
||||
close := stat.Update()
|
||||
defer close()
|
||||
cleanup := stat.Update()
|
||||
defer cleanup()
|
||||
time.Sleep(t.delay)
|
||||
|
||||
// Generate the response to be returned by Recv() for the
|
||||
|
@ -284,7 +284,7 @@ func newHTTP2Server(conn net.Conn, config *ServerConfig) (_ ServerTransport, err
|
||||
}
|
||||
|
||||
// operateHeader takes action on the decoded headers.
|
||||
func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(*Stream), traceCtx func(context.Context, string) context.Context) (close bool) {
|
||||
func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(*Stream), traceCtx func(context.Context, string) context.Context) (fatal bool) {
|
||||
streamID := frame.Header().StreamID
|
||||
state := decodeState{serverSide: true}
|
||||
if err := state.decodeHeader(frame); err != nil {
|
||||
@ -296,7 +296,7 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
|
||||
onWrite: func() {},
|
||||
})
|
||||
}
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
buf := newRecvBuffer()
|
||||
@ -350,13 +350,13 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
|
||||
rstCode: http2.ErrCodeRefusedStream,
|
||||
onWrite: func() {},
|
||||
})
|
||||
return
|
||||
return false
|
||||
}
|
||||
}
|
||||
t.mu.Lock()
|
||||
if t.state != reachable {
|
||||
t.mu.Unlock()
|
||||
return
|
||||
return false
|
||||
}
|
||||
if uint32(len(t.activeStreams)) >= t.maxStreams {
|
||||
t.mu.Unlock()
|
||||
@ -366,7 +366,7 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
|
||||
rstCode: http2.ErrCodeRefusedStream,
|
||||
onWrite: func() {},
|
||||
})
|
||||
return
|
||||
return false
|
||||
}
|
||||
if streamID%2 != 1 || streamID <= t.maxStreamID {
|
||||
t.mu.Unlock()
|
||||
@ -417,7 +417,7 @@ func (t *http2Server) operateHeaders(frame *http2.MetaHeadersFrame, handle func(
|
||||
wq: s.wq,
|
||||
})
|
||||
handle(s)
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
// HandleStreams receives incoming streams using the given handler. This is
|
||||
|
@ -46,12 +46,12 @@ func TestPairsMD(t *testing.T) {
|
||||
func TestCopy(t *testing.T) {
|
||||
const key, val = "key", "val"
|
||||
orig := Pairs(key, val)
|
||||
copy := orig.Copy()
|
||||
if !reflect.DeepEqual(orig, copy) {
|
||||
t.Errorf("copied value not equal to the original, got %v, want %v", copy, orig)
|
||||
cpy := orig.Copy()
|
||||
if !reflect.DeepEqual(orig, cpy) {
|
||||
t.Errorf("copied value not equal to the original, got %v, want %v", cpy, orig)
|
||||
}
|
||||
orig[key][0] = "foo"
|
||||
if v := copy[key][0]; v != val {
|
||||
if v := cpy[key][0]; v != val {
|
||||
t.Errorf("change in original should not affect copy, got %q, want %q", v, val)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user