Skip to content

Commit

Permalink
Changes to tests that run on Travis
Browse files Browse the repository at this point in the history
- Remove code coverage from Travis and add it to a GitHub Action
that will be run as a nightly.
- Use tag builds to exclude some tests, such as the "norace" or
JS tests. Since "go test" does not support "negative" regexs, there
is no other way.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
  • Loading branch information
kozlovic committed Apr 26, 2022
1 parent 1a80b2e commit 0e2ab5e
Show file tree
Hide file tree
Showing 14 changed files with 3,457 additions and 3,271 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/cov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: NATS Server Code Coverage
on:
workflow_dispatch: {}

schedule:
- cron: "40 4 * * *"

jobs:
nightly_coverage:
runs-on: ubuntu-latest

env:
GOPATH: /home/runner/work/nats-server
GO111MODULE: "on"

steps:
- name: Checkout code
uses: actions/checkout@v1
with:
path: src/github.com/nats-io/nats-server

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17.x

- name: Run code coverage
shell: bash --noprofile --norc -x -eo pipefail {0}
# Do not make the build fail even if code coverage reported
# a test failure.
run: |
./scripts/cov.sh upload
- name: Convert coverage.out to coverage.lcov
uses: jandelgado/gcov2lcov-action@v1.0.8
with:
infile: acc.out

- name: Coveralls
uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
33 changes: 12 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,27 @@ language: go
go:
- 1.17.x
- 1.16.x

addons:
apt:
packages:
- rpm
env:
- GO111MODULE=on
go_import_path: github.com/nats-io/nats-server
install:
- go install honnef.co/go/tools/cmd/staticcheck@v0.2.2
- go install github.com/client9/misspell/cmd/misspell@latest
before_script:
- GO_LIST=$(go list ./...)
- go build
- $(exit $(go fmt $GO_LIST | wc -l))
- go vet $GO_LIST
- find . -type f -name "*.go" | xargs misspell -error -locale US
- staticcheck $GO_LIST
script:
- set -e
- if [[ $TRAVIS_TAG ]]; then go test -v -run=TestVersionMatchesTag ./server; fi
- if [[ ! $TRAVIS_TAG ]]; then go test -v -run=TestNoRace --failfast -p=1 -timeout 30m ./...; fi
- if [[ ! $TRAVIS_TAG ]]; then if [[ "$TRAVIS_GO_VERSION" =~ 1.16 ]]; then ./scripts/cov.sh TRAVIS; else go test -v -race -p=1 --failfast -timeout 30m ./...; fi; fi
- set +e
after_success:
- if [[ ! $TRAVIS_TAG ]]; then if [[ "$TRAVIS_GO_VERSION" =~ 1.16 ]]; then $HOME/gopath/bin/goveralls -coverprofile=acc.out -service travis-ci; fi; fi

env:
- TEST_SUITE=compile
- TEST_SUITE=no_race_tests
- TEST_SUITE=js_tests
- TEST_SUITE=js_cluster_tests
- TEST_SUITE=srv_pkg_non_js_tests
- TEST_SUITE=non_srv_pkg_tests

script: ./runTestsOnTravis.sh $TEST_SUITE

deploy:
provider: script
cleanup: true
script: curl -sL http://git.io/goreleaser | bash
on:
tags: true
condition: $TRAVIS_GO_VERSION =~ 1.17
condition: ($TRAVIS_GO_VERSION =~ 1.17) && ($TEST_SUITE = "compile")
56 changes: 56 additions & 0 deletions runTestsOnTravis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh

set -e

if [ "$1" = "compile" ]; then

# We will compile and run some vet, spelling and some other checks.

go install honnef.co/go/tools/cmd/staticcheck@v0.2.2;
go install github.com/client9/misspell/cmd/misspell@latest;
GO_LIST=$(go list ./...);
go build;
$(exit $(go fmt $GO_LIST | wc -l));
go vet $GO_LIST;
find . -type f -name "*.go" | xargs misspell -error -locale US;
staticcheck $GO_LIST
if [ "$TRAVIS_TAG" != "" ]; then
go test -race -v -run=TestVersionMatchesTag ./server -count=1 -vet=off
fi

elif [ "$1" = "no_race_tests" ]; then

# Run tests without the `-race` flag. By convention, those tests start
# with `TestNoRace`.

go test -v -p=1 -run=TestNoRace ./... -count=1 -vet=off -timeout=30m -failfast

elif [ "$1" = "js_tests" ]; then

# Run JetStream non-clustere tests. By convention, all JS tests start
# with `TestJetStream`. We exclude the clustered tests by using the
# `skip_js_cluster_tests` build tag.

go test -race -v -run=TestJetStream ./server -tags=skip_js_cluster_tests -count=1 -vet=off -timeout=30m -failfast

elif [ "$1" = "js_cluster_tests" ]; then

# Run JetStream clustered tests. By convention, all JS clustered tests
# start with `TestJetStreamCluster`.

go test -race -v -run=TestJetStreamCluster ./server -count=1 -vet=off -timeout=30m -failfast

elif [ "$1" = "srv_pkg_non_js_tests" ]; then

# Run all non JetStream tests in the server package. We exclude the
# JS tests by using the `skip_js_tests` build tag.

go test -race -v -p=1 ./server/... -tags=skip_js_tests -count=1 -vet=off -timeout=30m -failfast

elif [ "$1" = "non_srv_pkg_tests" ]; then

# Run all tests of all non server package.

go test -race -v -p=1 $(go list ./... | grep -v "/server") -count=1 -vet=off -timeout=30m -failfast

fi
23 changes: 13 additions & 10 deletions scripts/cov.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
#!/bin/bash -e
#!/bin/bash
# Run from directory above via ./scripts/cov.sh

# Do not set the -e flag because we don't a flapper to prevent the push to coverall.

export GO111MODULE="on"

go get github.com/mattn/goveralls
go get github.com/wadey/gocovmerge
go install github.com/wadey/gocovmerge@latest

rm -rf ./cov
mkdir cov
go test -v -failfast -covermode=atomic -coverprofile=./cov/conf.out -run='Test[^NoRace]' ./conf -timeout=20m
go test -v -failfast -covermode=atomic -coverprofile=./cov/log.out -run='Test[^NoRace]' ./logger -timeout=20m
go test -v -failfast -covermode=atomic -coverprofile=./cov/server.out -run='Test[^NoRace]' ./server -timeout=20m
go test -v -failfast -covermode=atomic -coverprofile=./cov/test.out -coverpkg=./server -run='Test[^NoRace]' ./test -timeout=20m
# Since it is difficult to get a full run without a flapper, do not use `-failfast`.
# It is better to have one flapper or two and still get the report than have
# to re-run the whole code coverage. One or two failed tests should not affect
# so much the code coverage.
go test -v -covermode=atomic -coverprofile=./cov/conf.out ./conf -timeout=20m -tags=skip_no_race_tests
go test -v -covermode=atomic -coverprofile=./cov/log.out ./logger -timeout=20m -tags=skip_no_race_tests
go test -v -covermode=atomic -coverprofile=./cov/server.out ./server -timeout=20m -tags=skip_no_race_tests
go test -v -covermode=atomic -coverprofile=./cov/test.out -coverpkg=./server ./test -timeout=20m -tags=skip_no_race_tests
gocovmerge ./cov/*.out > acc.out
rm -rf ./cov

# Without argument, launch browser results. We are going to push to coveralls only
# from Travis.yml and after success of the build (and result of pushing will not affect
# build result).
# If no argument passed, launch a browser to see the results.
if [[ $1 == "" ]]; then
go tool cover -html=acc.out
fi
Loading

0 comments on commit 0e2ab5e

Please sign in to comment.