test: make TestAgent setup reusable
Pick the random ports only once and try starting with them a number of times so that the configuration can be re-used. This is because the ports are written into the data files and a subsequent agent reading the files needs to have the same ports. For the same reason we do not remove the data directory on every attempt since this makes it impossible to re-read the data files.
This commit is contained in:
parent
b06c969deb
commit
5224699341
|
@ -121,16 +121,12 @@ func (a *TestAgent) Start() *TestAgent {
|
||||||
a.Config.DataDir = d
|
a.Config.DataDir = d
|
||||||
}
|
}
|
||||||
id := UniqueID()
|
id := UniqueID()
|
||||||
|
|
||||||
|
// since the ports are written into the data files we pick random ports
|
||||||
|
// only once and try a number of times to start with them.
|
||||||
|
pickRandomPorts(a.Config)
|
||||||
|
|
||||||
for i := 10; i >= 0; i-- {
|
for i := 10; i >= 0; i-- {
|
||||||
pickRandomPorts(a.Config)
|
|
||||||
|
|
||||||
// ports are baked into the data files so we need to clear out the
|
|
||||||
// data dir on every retry
|
|
||||||
os.RemoveAll(a.Config.DataDir)
|
|
||||||
if err := os.MkdirAll(a.Config.DataDir, 0755); err != nil {
|
|
||||||
panic(fmt.Sprintf("Error creating dir %s: %s", a.Config.DataDir, err))
|
|
||||||
}
|
|
||||||
|
|
||||||
// write the keyring
|
// write the keyring
|
||||||
if a.Key != "" {
|
if a.Key != "" {
|
||||||
writeKey := func(key, filename string) {
|
writeKey := func(key, filename string) {
|
||||||
|
|
Loading…
Reference in New Issue