mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
agent: make unit tests much faster
This commit is contained in:
@@ -65,7 +65,10 @@ func (a *Agent) setupServer() error {
|
||||
}
|
||||
|
||||
// Setup the configuration
|
||||
conf := nomad.DefaultConfig()
|
||||
conf := a.config.NomadConfig
|
||||
if conf == nil {
|
||||
conf = nomad.DefaultConfig()
|
||||
}
|
||||
conf.LogOutput = a.logOutput
|
||||
conf.DevMode = a.config.DevMode
|
||||
conf.Build = fmt.Sprintf("%s%s", a.config.Version, a.config.VersionPrerelease)
|
||||
@@ -130,7 +133,10 @@ func (a *Agent) setupClient() error {
|
||||
}
|
||||
|
||||
// Setup the configuration
|
||||
conf := client.DefaultConfig()
|
||||
conf := a.config.ClientConfig
|
||||
if conf == nil {
|
||||
conf = client.DefaultConfig()
|
||||
}
|
||||
if a.server != nil {
|
||||
conf.RPCHandler = a.server
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/nomad/nomad"
|
||||
)
|
||||
|
||||
var nextPort uint32 = 17000
|
||||
@@ -25,6 +30,32 @@ func makeAgent(t *testing.T, cb func(*Config)) (string, *Agent) {
|
||||
dir := tmpDir(t)
|
||||
conf := DevConfig()
|
||||
|
||||
// Customize the server configuration
|
||||
config := nomad.DefaultConfig()
|
||||
conf.NomadConfig = config
|
||||
|
||||
// Only use loopback
|
||||
config.RPCAddr = &net.TCPAddr{
|
||||
IP: []byte{127, 0, 0, 1},
|
||||
Port: getPort(),
|
||||
}
|
||||
config.NodeName = fmt.Sprintf("Node %d", config.RPCAddr.Port)
|
||||
|
||||
// Tighten the Serf timing
|
||||
config.SerfConfig.MemberlistConfig.BindAddr = "127.0.0.1"
|
||||
config.SerfConfig.MemberlistConfig.BindPort = getPort()
|
||||
config.SerfConfig.MemberlistConfig.SuspicionMult = 2
|
||||
config.SerfConfig.MemberlistConfig.RetransmitMult = 2
|
||||
config.SerfConfig.MemberlistConfig.ProbeTimeout = 50 * time.Millisecond
|
||||
config.SerfConfig.MemberlistConfig.ProbeInterval = 100 * time.Millisecond
|
||||
config.SerfConfig.MemberlistConfig.GossipInterval = 100 * time.Millisecond
|
||||
|
||||
// Tighten the Raft timing
|
||||
config.RaftConfig.LeaderLeaseTimeout = 20 * time.Millisecond
|
||||
config.RaftConfig.HeartbeatTimeout = 40 * time.Millisecond
|
||||
config.RaftConfig.ElectionTimeout = 40 * time.Millisecond
|
||||
config.RaftTimeout = 500 * time.Millisecond
|
||||
|
||||
if cb != nil {
|
||||
cb(conf)
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
|
||||
"github.com/hashicorp/hcl"
|
||||
hclobj "github.com/hashicorp/hcl/hcl"
|
||||
client "github.com/hashicorp/nomad/client/config"
|
||||
"github.com/hashicorp/nomad/nomad"
|
||||
)
|
||||
|
||||
// Config is the configuration for the Nomad agent.
|
||||
@@ -57,6 +59,14 @@ type Config struct {
|
||||
VersionPrerelease string
|
||||
|
||||
DevMode bool `hcl:"-"`
|
||||
|
||||
// NomadConfig is used to override the default config.
|
||||
// This is largly used for testing purposes.
|
||||
NomadConfig *nomad.Config `hcl:"-" json:"-"`
|
||||
|
||||
// ClientConfig is used to override the default config.
|
||||
// This is largly used for testing purposes.
|
||||
ClientConfig *client.Config `hcl:"-" json:"-"`
|
||||
}
|
||||
|
||||
type ClientConfig struct {
|
||||
|
||||
Reference in New Issue
Block a user