add a failing test for unexpected bootstrapping

This commit is contained in:
Mahmood Ali 2020-12-17 15:52:40 -05:00
parent 52549b3b77
commit 421380a300
1 changed files with 40 additions and 0 deletions

View File

@ -6,11 +6,13 @@ import (
"os"
"path"
"strings"
"sync/atomic"
"testing"
"time"
"github.com/hashicorp/nomad/testutil"
"github.com/hashicorp/serf/serf"
"github.com/stretchr/testify/require"
)
func TestNomad_JoinPeer(t *testing.T) {
@ -442,3 +444,41 @@ func TestNomad_BadExpect(t *testing.T) {
t.Fatalf("should have 0 peers: %v", err)
})
}
// TestNomad_NonBootstraping_ShouldntBootstap asserts that if BootstrapExpect is zero,
// the server shouldn't bootstrap
func TestNomad_NonBootstraping_ShouldntBootstap(t *testing.T) {
t.Parallel()
dir := tmpDir(t)
defer os.RemoveAll(dir)
s1, cleanupS1 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 0
c.DevMode = false
c.DataDir = path.Join(dir, "node")
})
defer cleanupS1()
testutil.WaitForResult(func() (bool, error) {
s1.peerLock.Lock()
p := len(s1.localPeers)
s1.peerLock.Unlock()
if p != 1 {
return false, fmt.Errorf("%d", p)
}
return true, nil
}, func(err error) {
t.Fatalf("expected 1 local peer: %v", err)
})
time.Sleep(500 * time.Millisecond)
bootstrapped := atomic.LoadInt32(&s1.config.Bootstrapped)
require.Zero(t, bootstrapped, "expecting non-bootstrapped servers")
p, _ := s1.numPeers()
require.Zero(t, p, "number of peers in Raft")
}