Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Bootstrap logic in tests #7252

Merged
merged 3 commits into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func TestRpc_streamingRpcConn_badEndpoint_TLS(t *testing.T) {
s1, cleanupS1 := nomad.TestServer(t, func(c *nomad.Config) {
c.Region = "regionFoo"
c.BootstrapExpect = 1
c.DevDisableBootstrap = true
c.TLSConfig = &sconfig.TLSConfig{
EnableHTTP: true,
EnableRPC: true,
Expand Down
7 changes: 1 addition & 6 deletions command/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"runtime"
"strings"
"sync"
"sync/atomic"
"time"

metrics "github.com/armon/go-metrics"
Expand Down Expand Up @@ -157,11 +156,7 @@ func convertServerConfig(agentConfig *Config) (*nomad.Config, error) {
conf.NodeName = agentConfig.NodeName
}
if agentConfig.Server.BootstrapExpect > 0 {
if agentConfig.Server.BootstrapExpect == 1 {
conf.Bootstrap = true
} else {
atomic.StoreInt32(&conf.BootstrapExpect, int32(agentConfig.Server.BootstrapExpect))
}
conf.BootstrapExpect = agentConfig.Server.BootstrapExpect
}
if agentConfig.DataDir != "" {
conf.DataDir = filepath.Join(agentConfig.DataDir, "server")
Expand Down
6 changes: 2 additions & 4 deletions command/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,12 @@ func TestAgent_ServerConfig(t *testing.T) {
conf.Server.BootstrapExpect = 1
out, err = a.serverConfig()
require.NoError(t, err)
require.True(t, out.Bootstrap)
require.Equal(t, int32(0), out.BootstrapExpect)
require.Equal(t, 1, out.BootstrapExpect)

conf.Server.BootstrapExpect = 3
out, err = a.serverConfig()
require.NoError(t, err)
require.False(t, out.Bootstrap)
require.Equal(t, int32(3), out.BootstrapExpect)
require.Equal(t, 3, out.BootstrapExpect)
}

func TestAgent_ServerConfig_SchedulerFlags(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion command/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,8 @@ func DevConfig(mode *devModeConfig) *Config {
conf.LogLevel = "DEBUG"
conf.Client.Enabled = true
conf.Server.Enabled = true
conf.DevMode = mode != nil
conf.DevMode = true
conf.Server.BootstrapExpect = 1
conf.EnableDebug = true
conf.DisableAnonymousSignature = true
conf.Consul.AutoAdvertise = helper.BoolToPtr(true)
Expand Down
6 changes: 1 addition & 5 deletions command/agent/testagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ RETRY:
}

failed := false
if a.Config.NomadConfig.Bootstrap && a.Config.Server.Enabled {
if a.Config.NomadConfig.BootstrapExpect == 1 && a.Config.Server.Enabled {
testutil.WaitForResult(func() (bool, error) {
args := &structs.GenericRequest{}
var leader string
Expand Down Expand Up @@ -358,10 +358,6 @@ func (a *TestAgent) config() *Config {
config.ServerHealthInterval = 50 * time.Millisecond
config.AutopilotInterval = 100 * time.Millisecond

// Bootstrap ourselves
config.Bootstrap = true
config.BootstrapExpect = 1

// Tighten the fingerprinter timeouts
if conf.Client.Options == nil {
conf.Client.Options = make(map[string]string)
Expand Down
2 changes: 0 additions & 2 deletions nomad/acl_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1077,8 +1077,6 @@ func TestACLEndpoint_Bootstrap_Reset(t *testing.T) {
c.ACLEnabled = true
c.DataDir = dir
c.DevMode = false
c.Bootstrap = true
c.DevDisableBootstrap = false
})
defer cleanupS1()
codec := rpcClient(t, s1)
Expand Down
33 changes: 16 additions & 17 deletions nomad/autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func TestAutopilot_CleanupDeadServer(t *testing.T) {

func testCleanupDeadServer(t *testing.T, raftVersion int) {
conf := func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 3
c.RaftConfig.ProtocolVersion = raft.ProtocolVersion(raftVersion)
}
Expand Down Expand Up @@ -127,13 +126,13 @@ func testCleanupDeadServer(t *testing.T, raftVersion int) {
func TestAutopilot_CleanupDeadServerPeriodic(t *testing.T) {
t.Parallel()

s1, cleanupS1 := TestServer(t, nil)
defer cleanupS1()

conf := func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 5
}

s1, cleanupS1 := TestServer(t, conf)
defer cleanupS1()

s2, cleanupS2 := TestServer(t, conf)
defer cleanupS2()

Expand Down Expand Up @@ -174,16 +173,14 @@ func TestAutopilot_CleanupDeadServerPeriodic(t *testing.T) {
func TestAutopilot_RollingUpdate(t *testing.T) {
t.Parallel()

s1, cleanupS1 := TestServer(t, func(c *Config) {
c.RaftConfig.ProtocolVersion = 3
})
defer cleanupS1()

conf := func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 3
c.RaftConfig.ProtocolVersion = 3
}

s1, cleanupS1 := TestServer(t, conf)
defer cleanupS1()

s2, cleanupS2 := TestServer(t, conf)
defer cleanupS2()

Expand Down Expand Up @@ -248,19 +245,21 @@ func TestAutopilot_CleanupStaleRaftServer(t *testing.T) {
t.Skip("TestAutopilot_CleanupDeadServer is very flaky, removing it for now")
t.Parallel()

s1, cleanupS1 := TestServer(t, nil)
defer cleanupS1()

conf := func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 3
}
s1, cleanupS1 := TestServer(t, conf)
defer cleanupS1()

s2, cleanupS2 := TestServer(t, conf)
defer cleanupS2()

s3, cleanupS3 := TestServer(t, conf)
defer cleanupS3()

s4, cleanupS4 := TestServer(t, conf)
s4, cleanupS4 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 0
})
defer cleanupS4()

servers := []*Server{s1, s2, s3}
Expand Down Expand Up @@ -304,7 +303,7 @@ func TestAutopilot_PromoteNonVoter(t *testing.T) {
testutil.WaitForLeader(t, s1.RPC)

s2, cleanupS2 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 0
c.RaftConfig.ProtocolVersion = 3
})
defer cleanupS2()
Expand Down
20 changes: 12 additions & 8 deletions nomad/client_agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ func TestMonitor_Monitor_Remote_Client(t *testing.T) {
require := require.New(t)

// start server and client
s1, cleanupS1 := TestServer(t, nil)
s1, cleanupS1 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
})
defer cleanupS1()
s2, cleanupS2 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanupS2()
TestJoin(t, s1, s2)
Expand Down Expand Up @@ -125,15 +127,16 @@ func TestMonitor_Monitor_RemoteServer(t *testing.T) {
foreignRegion := "foo"

// start servers
s1, cleanupS1 := TestServer(t, nil)
s1, cleanupS1 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
})
defer cleanupS1()
s2, cleanupS2 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanupS2()

s3, cleanupS3 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.Region = foreignRegion
})
defer cleanupS3()
Expand Down Expand Up @@ -516,12 +519,12 @@ func TestAgentProfile_RemoteClient(t *testing.T) {

// start server and client
s1, cleanup := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanup()

s2, cleanup := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanup()

Expand Down Expand Up @@ -640,12 +643,13 @@ func TestAgentProfile_Server(t *testing.T) {

// start servers
s1, cleanup := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
c.EnableDebug = true
})
defer cleanup()

s2, cleanup := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
c.EnableDebug = true
})
defer cleanup()
Expand Down
30 changes: 20 additions & 10 deletions nomad/client_alloc_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ func TestClientAllocations_GarbageCollectAll_Remote(t *testing.T) {
require := require.New(t)

// Start a server and client
s1, cleanupS1 := TestServer(t, nil)
s1, cleanupS1 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
})
defer cleanupS1()
s2, cleanupS2 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanupS2()
TestJoin(t, s1, s2)
Expand Down Expand Up @@ -432,10 +434,12 @@ func TestClientAllocations_GarbageCollect_Remote(t *testing.T) {
require := require.New(t)

// Start a server and client
s1, cleanupS1 := TestServer(t, nil)
s1, cleanupS1 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
})
defer cleanupS1()
s2, cleanupS2 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanupS2()
TestJoin(t, s1, s2)
Expand Down Expand Up @@ -720,10 +724,12 @@ func TestClientAllocations_Stats_Remote(t *testing.T) {
require := require.New(t)

// Start a server and client
s1, cleanupS1 := TestServer(t, nil)
s1, cleanupS1 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
})
defer cleanupS1()
s2, cleanupS2 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanupS2()
TestJoin(t, s1, s2)
Expand Down Expand Up @@ -915,10 +921,12 @@ func TestClientAllocations_Restart_Remote(t *testing.T) {
require := require.New(t)

// Start a server and client
s1, cleanupS1 := TestServer(t, nil)
s1, cleanupS1 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
})
defer cleanupS1()
s2, cleanupS2 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanupS2()
TestJoin(t, s1, s2)
Expand Down Expand Up @@ -1071,11 +1079,13 @@ func TestAlloc_ExecStreaming(t *testing.T) {
t.Parallel()

////// Nomad clusters topology - not specific to test
localServer, cleanupLS := TestServer(t, nil)
localServer, cleanupLS := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
})
defer cleanupLS()

remoteServer, cleanupRS := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanupRS()

Expand Down
24 changes: 16 additions & 8 deletions nomad/client_fs_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,12 @@ func TestClientFS_List_Remote(t *testing.T) {
require := require.New(t)

// Start a server and client
s1, cleanupS1 := TestServer(t, nil)
s1, cleanupS1 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
})
defer cleanupS1()
s2, cleanupS2 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanupS2()
TestJoin(t, s1, s2)
Expand Down Expand Up @@ -451,10 +453,12 @@ func TestClientFS_Stat_Remote(t *testing.T) {
require := require.New(t)

// Start a server and client
s1, cleanupS1 := TestServer(t, nil)
s1, cleanupS1 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
})
defer cleanupS1()
s2, cleanupS2 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanupS2()
TestJoin(t, s1, s2)
Expand Down Expand Up @@ -1000,10 +1004,12 @@ func TestClientFS_Streaming_Remote_Server(t *testing.T) {
require := require.New(t)

// Start a server and client
s1, cleanupS1 := TestServer(t, nil)
s1, cleanupS1 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
})
defer cleanupS1()
s2, cleanupS2 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanupS2()
TestJoin(t, s1, s2)
Expand Down Expand Up @@ -1829,10 +1835,12 @@ func TestClientFS_Logs_Remote_Server(t *testing.T) {
require := require.New(t)

// Start a server and client
s1, cleanupS1 := TestServer(t, nil)
s1, cleanupS1 := TestServer(t, func(c *Config) {
c.BootstrapExpect = 2
})
defer cleanupS1()
s2, cleanupS2 := TestServer(t, func(c *Config) {
c.DevDisableBootstrap = true
c.BootstrapExpect = 2
})
defer cleanupS2()
TestJoin(t, s1, s2)
Expand Down
Loading