Travis: add staticcheck (#1019)

Also only run golint and go vet in Go 1.8, and fix some vet failures.
This commit is contained in:
Tamir Duberstein
2017-05-15 20:05:27 -04:00
committed by dfawley
parent e2f22b027b
commit 3773797869
5 changed files with 172 additions and 166 deletions

View File

@ -1,19 +1,20 @@
language: go
go:
- 1.6.3
- 1.7
- 1.8
- 1.6.x
- 1.7.x
- 1.8.x
go_import_path: google.golang.org/grpc
before_install:
- go get github.com/golang/lint/golint
- if [[ $TRAVIS_GO_VERSION = 1.8* ]]; then go get -u github.com/golang/lint/golint honnef.co/go/tools/cmd/staticcheck; fi
- go get -u golang.org/x/tools/cmd/goimports github.com/axw/gocov/gocov github.com/mattn/goveralls golang.org/x/tools/cmd/cover
script:
- '! gofmt -s -d -l . 2>&1 | read'
- '! goimports -l . | read'
- '! golint ./... | grep -vE "(_mock|_string|\.pb)\.go:"'
- '! go tool vet -all . 2>&1 | grep -vE "constant [0-9]+ not a string in call to Errorf" | grep -vF .pb.go:' # https://github.com/golang/protobuf/issues/214
- 'if [[ $TRAVIS_GO_VERSION = 1.8* ]]; then ! golint ./... | grep -vE "(_mock|_string|\.pb)\.go:"; fi'
- 'if [[ $TRAVIS_GO_VERSION = 1.8* ]]; then ! go tool vet -all . 2>&1 | grep -vF .pb.go:; fi' # https://github.com/golang/protobuf/issues/214
- make test testrace
- 'if [[ $TRAVIS_GO_VERSION = 1.8* ]]; then staticcheck -ignore google.golang.org/grpc/transport/transport_test.go:SA2002 ./...; fi' # TODO(menghanl): fix these

View File

@ -73,7 +73,7 @@ func runStream(b *testing.B, maxConcurrentCalls int) {
streamCaller(stream)
}
ch := make(chan int, maxConcurrentCalls*4)
ch := make(chan struct{}, maxConcurrentCalls*4)
var (
mu sync.Mutex
wg sync.WaitGroup
@ -82,11 +82,11 @@ func runStream(b *testing.B, maxConcurrentCalls int) {
// Distribute the b.N calls over maxConcurrentCalls workers.
for i := 0; i < maxConcurrentCalls; i++ {
go func() {
stream, err := tc.StreamingCall(context.Background())
if err != nil {
b.Fatalf("%v.StreamingCall(_) = _, %v", tc, err)
}
go func() {
for range ch {
start := time.Now()
streamCaller(stream)
@ -100,7 +100,7 @@ func runStream(b *testing.B, maxConcurrentCalls int) {
}
b.StartTimer()
for i := 0; i < b.N; i++ {
ch <- i
ch <- struct{}{}
}
b.StopTimer()
close(ch)

View File

@ -295,17 +295,20 @@ func (b *emptyBalancer) Close() error {
func TestNonblockingDialWithEmptyBalancer(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
dialDone := make(chan struct{})
defer cancel()
dialDone := make(chan error)
go func() {
dialDone <- func() error {
conn, err := DialContext(ctx, "Non-Existent.Server:80", WithInsecure(), WithBalancer(newEmptyBalancer()))
if err != nil {
t.Fatalf("unexpected error dialing connection: %v", err)
return err
}
conn.Close()
close(dialDone)
return conn.Close()
}()
<-dialDone
cancel()
}()
if err := <-dialDone; err != nil {
t.Fatalf("unexpected error dialing connection: %s", err)
}
}
func TestClientUpdatesParamsAfterGoAway(t *testing.T) {

View File

@ -690,7 +690,6 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
stream.SetSendCompress(s.opts.cp.Type())
}
p := &parser{r: stream}
for { // TODO: delete
pf, req, err := p.recvMsg(s.opts.maxMsgSize)
if err == io.EOF {
// The entire stream is done (for unary RPC only).
@ -823,7 +822,6 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
// error or allow the stats handler to see it?
return t.WriteStatus(stream, status.New(codes.OK, ""))
}
}
func (s *Server) processStreamingRPC(t transport.ServerTransport, stream *transport.Stream, srv *service, sd *StreamDesc, trInfo *traceInfo) (err error) {
sh := s.opts.statsHandler

View File

@ -2423,8 +2423,8 @@ func testMetadataStreamingRPC(t *testing.T, e env) {
if err != nil || !reflect.DeepEqual(testMetadata, headerMD) {
t.Errorf("#2 %v.Header() = %v, %v, want %v, <nil>", stream, headerMD, err, testMetadata)
}
var index int
for index < len(reqSizes) {
err = func() error {
for index := 0; index < len(reqSizes); index++ {
respParam := []*testpb.ResponseParameters{
{
Size: proto.Int32(int32(respSizes[index])),
@ -2433,7 +2433,7 @@ func testMetadataStreamingRPC(t *testing.T, e env) {
payload, err := newPayload(testpb.PayloadType_COMPRESSABLE, int32(reqSizes[index]))
if err != nil {
t.Fatal(err)
return err
}
req := &testpb.StreamingOutputCallRequest{
@ -2442,13 +2442,16 @@ func testMetadataStreamingRPC(t *testing.T, e env) {
Payload: payload,
}
if err := stream.Send(req); err != nil {
t.Errorf("%v.Send(%v) = %v, want <nil>", stream, req, err)
return
return fmt.Errorf("%v.Send(%v) = %v, want <nil>", stream, req, err)
}
index++
}
return nil
}()
// Tell the server we're done sending args.
stream.CloseSend()
if err != nil {
t.Error(err)
}
}()
for {
if _, err := stream.Recv(); err != nil {
@ -2844,7 +2847,8 @@ func testStreamsQuotaRecovery(t *testing.T, e env) {
defer wg.Done()
payload, err := newPayload(testpb.PayloadType_COMPRESSABLE, 314)
if err != nil {
t.Fatal(err)
t.Error(err)
return
}
req := &testpb.SimpleRequest{
ResponseType: testpb.PayloadType_COMPRESSABLE.Enum(),