Skip to content

Commit

Permalink
Add staticcheck static analyzer to travis.
Browse files Browse the repository at this point in the history
Included are small fixes to address warnings found in test code.  No functional changes.
  • Loading branch information
Colin Sullivan committed Oct 27, 2016
1 parent c3753d4 commit 6281894
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ install:
- go get github.com/nats-io/nats
- go get github.com/mattn/goveralls
- go get github.com/wadey/gocovmerge
- go get honnef.co/go/staticcheck/cmd/staticcheck
script:
- go build
- go fmt ./...
- go vet ./...
- go test -i -race ./...
- go test -v -race ./...
- staticcheck ./...
after_script:
- if [ "$TRAVIS_GO_VERSION" = "1.6.3" ]; then ./scripts/cov.sh TRAVIS; fi
- if [ "$TRAVIS_GO_VERSION" = "1.6.3" ] && [ "$TRAVIS_TAG" != "" ]; then ./scripts/cross_compile.sh $TRAVIS_TAG; ghr --username nats-io --token $GITHUB_TOKEN --replace $TRAVIS_TAG pkg/; fi
8 changes: 8 additions & 0 deletions server/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func BenchmarkParseSize(b *testing.B) {
func deferUnlock(mu *sync.Mutex) {
mu.Lock()
defer mu.Unlock()
// see noDeferUnlock
if false {
return
}
}

func BenchmarkDeferMutex(b *testing.B) {
Expand All @@ -61,6 +65,10 @@ func BenchmarkDeferMutex(b *testing.B) {

func noDeferUnlock(mu *sync.Mutex) {
mu.Lock()
// prevent staticcheck warning about empty critical section
if false {
return
}
mu.Unlock()
}

Expand Down
5 changes: 3 additions & 2 deletions test/client_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ func TestServerRestartReSliceIssue(t *testing.T) {
defer srvB.Shutdown()

// Check that all expected clients have reconnected
for i := 0; i < numClients/2; i++ {
done := false
for i := 0; i < numClients/2 && !done; i++ {
select {
case <-reconnectsDone:
break
done = true
case <-time.After(3 * time.Second):
t.Fatalf("Expected %d reconnects, got %d\n", numClients/2, reconnects)
}
Expand Down

0 comments on commit 6281894

Please sign in to comment.