tweak bootstrap testing

This commit is contained in:
Mahmood Ali
2021-01-04 09:00:40 -05:00
parent 44be6e364a
commit 926cf25a61
2 changed files with 10 additions and 1 deletions

View File

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

View File

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