diff --git a/nomad/serf.go b/nomad/serf.go index 67c9ddfff..0e63630bb 100644 --- a/nomad/serf.go +++ b/nomad/serf.go @@ -91,6 +91,12 @@ func (s *Server) nodeJoin(me serf.MemberEvent) { // maybeBootstrap is used to handle bootstrapping when a new server joins func (s *Server) maybeBootstrap() { + + // redundant check to ease testing + if s.config.BootstrapExpect == 0 { + return + } + // Bootstrap can only be done if there are no committed logs, remove our // expectations of bootstrapping. This is slightly cheaper than the full // check that BootstrapCluster will do, so this is a good pre-filter. diff --git a/nomad/serf_test.go b/nomad/serf_test.go index ce97b9970..de747df0d 100644 --- a/nomad/serf_test.go +++ b/nomad/serf_test.go @@ -473,7 +473,10 @@ func TestNomad_NonBootstraping_ShouldntBootstap(t *testing.T) { t.Fatalf("expected 1 local peer: %v", err) }) - time.Sleep(500 * time.Millisecond) + // as non-bootstrap mode is the initial state, we must wait long enough to assert that + // we don't bootstrap even if enough time has elapsed. Also, explicitly attempt bootstrap. + s1.maybeBootstrap() + time.Sleep(100 * time.Millisecond) bootstrapped := atomic.LoadInt32(&s1.config.Bootstrapped) require.Zero(t, bootstrapped, "expecting non-bootstrapped servers")