Skip to content

Commit

Permalink
Exclude chaos tests from build by default
Browse files Browse the repository at this point in the history
Before: build chaos tests unless `skip_js_chaos_tests` is set
After: exclude chaos tests unless `js_chaos_tests` is set
  • Loading branch information
mprimi committed Aug 5, 2022
1 parent 815948f commit be460b7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 34 deletions.
6 changes: 3 additions & 3 deletions scripts/runTestsOnTravis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [ "$1" = "compile" ]; then
$(exit $(go fmt $GO_LIST | wc -l));
go vet $GO_LIST;
find . -type f -name "*.go" | xargs misspell -error -locale US;
staticcheck $GO_LIST
staticcheck -tags=js_chaos_tests $GO_LIST
if [ "$TRAVIS_TAG" != "" ]; then
go test -race -v -run=TestVersionMatchesTag ./server -count=1 -vet=off
fi
Expand All @@ -35,7 +35,7 @@ elif [ "$1" = "js_tests" ]; then
# tests by using the `skip_js_cluster_tests` and `skip_js_super_cluster_tests`
# build tags.

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

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

Expand All @@ -56,7 +56,7 @@ elif [ "$1" = "js_chaos_tests" ]; then
# Run JetStream chaos tests. By convention, all JS cluster chaos
# tests with `TestJetStreamChaos`.

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

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

Expand Down
4 changes: 2 additions & 2 deletions server/jetstream_chaos_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !skip_js_tests && !skip_js_cluster_tests && !skip_js_chaos_tests
// +build !skip_js_tests,!skip_js_cluster_tests,!skip_js_chaos_tests
//go:build js_chaos_tests
// +build js_chaos_tests

package server

Expand Down
34 changes: 32 additions & 2 deletions server/jetstream_chaos_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,48 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !skip_js_tests && !skip_js_cluster_tests && !skip_js_chaos_tests
// +build !skip_js_tests,!skip_js_cluster_tests,!skip_js_chaos_tests
//go:build js_chaos_tests
// +build js_chaos_tests

package server

import (
"fmt"
"math/rand"
"sync"
"testing"
"time"
)

// Additional cluster helpers

func (c *cluster) waitOnClusterHealthz() {
c.t.Helper()
for _, cs := range c.servers {
c.waitOnServerHealthz(cs)
}
}

func (c *cluster) stopSubset(toStop []*Server) {
c.t.Helper()
for _, s := range toStop {
s.Shutdown()
}
}

func (c *cluster) selectRandomServers(numServers int) []*Server {
c.t.Helper()
if numServers > len(c.servers) {
panic(fmt.Sprintf("Can't select %d servers in a cluster of %d", numServers, len(c.servers)))
}
var selectedServers []*Server
selectedServers = append(selectedServers, c.servers...)
rand.Shuffle(len(selectedServers), func(x, y int) {
selectedServers[x], selectedServers[y] = selectedServers[y], selectedServers[x]
})
return selectedServers[0:numServers]
}

// Support functions for "chaos" testing (random injected failures)

type ChaosMonkeyController interface {
Expand Down
27 changes: 0 additions & 27 deletions server/jetstream_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1315,13 +1315,6 @@ func (c *cluster) waitOnClusterReadyWithNumPeers(numPeersExpected int) {
}
}

func (c *cluster) waitOnClusterHealthz() {
c.t.Helper()
for _, cs := range c.servers {
c.waitOnServerHealthz(cs)
}
}

// Helper function to remove JetStream from a server.
func (c *cluster) removeJetStream(s *Server) {
c.t.Helper()
Expand Down Expand Up @@ -1356,13 +1349,6 @@ func (c *cluster) stopAll() {
}
}

func (c *cluster) stopSubset(toStop []*Server) {
c.t.Helper()
for _, s := range toStop {
s.Shutdown()
}
}

func (c *cluster) restartAll() {
c.t.Helper()
for i, s := range c.servers {
Expand Down Expand Up @@ -1410,19 +1396,6 @@ func (c *cluster) stableTotalSubs() (total int) {

}

func (c *cluster) selectRandomServers(numServers int) []*Server {
c.t.Helper()
if numServers > len(c.servers) {
panic(fmt.Sprintf("Can't select %d servers in a cluster of %d", numServers, len(c.servers)))
}
var selectedServers []*Server
selectedServers = append(selectedServers, c.servers...)
rand.Shuffle(len(selectedServers), func(x, y int) {
selectedServers[x], selectedServers[y] = selectedServers[y], selectedServers[x]
})
return selectedServers[0:numServers]
}

func addStream(t *testing.T, nc *nats.Conn, cfg *StreamConfig) *StreamInfo {
t.Helper()
req, err := json.Marshal(cfg)
Expand Down

0 comments on commit be460b7

Please sign in to comment.