Exclude chaos tests from build by default

Before: build chaos tests unless `skip_js_chaos_tests` is set
After: exclude chaos tests unless `js_chaos_tests` is set
This commit is contained in:
Marco Primi
2022-08-05 09:35:39 -07:00
parent 815948f02f
commit be460b7bf1
4 changed files with 37 additions and 34 deletions

View File

@@ -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
@@ -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
@@ -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

View File

@@ -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

View File

@@ -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 {

View File

@@ -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()
@@ -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 {
@@ -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)