mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Add 'chaos' test utility and 2 example tests
'Chaos' is a new a group of test that validates behavior in presence of random failures. Overview: - Introduce a 'Chaos Monkey' controller which can unleash a monkey against a test cluster. - Introduce a monkey of type 'ClusterBouncer' which stops and restarts nodes according to some configuration - Add 2 example tests, they ensure a cluster can survive some amount of nodes bouncing - Configure the build to skip chaos tests unless explicitly requested - Add some test utility functions
This commit is contained in:
@@ -1315,6 +1315,13 @@ 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()
|
||||
@@ -1349,6 +1356,13 @@ 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 {
|
||||
@@ -1396,6 +1410,19 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user