mirror of
https://github.com/status-im/consul.git
synced 2025-02-19 17:14:37 +00:00
Add debugging logs to freeport
This commit is contained in:
parent
0455b5e720
commit
b374250d08
@ -195,6 +195,8 @@ func checkFreedPortsOnce() {
|
|||||||
if used := isPortInUse(port); !used {
|
if used := isPortInUse(port); !used {
|
||||||
freePorts.PushBack(port)
|
freePorts.PushBack(port)
|
||||||
remove = append(remove, elem)
|
remove = append(remove, elem)
|
||||||
|
} else {
|
||||||
|
logf("WARN", "port %d still being used", port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +316,6 @@ func Take(n int) (ports []int, err error) {
|
|||||||
ports = append(ports, port)
|
ports = append(ports, port)
|
||||||
}
|
}
|
||||||
|
|
||||||
// logf("DEBUG", "free ports: %v", ports)
|
|
||||||
return ports, nil
|
return ports, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,9 +401,10 @@ func logf(severity string, format string, a ...interface{}) {
|
|||||||
// In the future new methods may be added to this interface, but those methods
|
// In the future new methods may be added to this interface, but those methods
|
||||||
// should always be implemented by *testing.T
|
// should always be implemented by *testing.T
|
||||||
type TestingT interface {
|
type TestingT interface {
|
||||||
|
Cleanup(func())
|
||||||
Helper()
|
Helper()
|
||||||
Fatalf(format string, args ...interface{})
|
Fatalf(format string, args ...interface{})
|
||||||
Cleanup(func())
|
Name() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetN returns n free ports from the reserved port block, and returns the
|
// GetN returns n free ports from the reserved port block, and returns the
|
||||||
@ -413,8 +415,10 @@ func GetN(t TestingT, n int) []int {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to take %v ports: %w", n, err)
|
t.Fatalf("failed to take %v ports: %w", n, err)
|
||||||
}
|
}
|
||||||
|
logf("DEBUG", "Test %q took ports %v", t.Name(), ports)
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
Return(ports)
|
Return(ports)
|
||||||
|
logf("DEBUG", "Test %q returned ports %v", t.Name(), ports)
|
||||||
})
|
})
|
||||||
return ports
|
return ports
|
||||||
}
|
}
|
||||||
|
@ -156,10 +156,7 @@ func defaultServerConfig(t TestingTB) *TestServerConfig {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ports, err := freeport.Take(7)
|
ports := freeport.GetN(t, 7)
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to take ports: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
logBuffer := NewLogBuffer(t)
|
logBuffer := NewLogBuffer(t)
|
||||||
|
|
||||||
@ -194,9 +191,6 @@ func defaultServerConfig(t TestingTB) *TestServerConfig {
|
|||||||
"cluster_id": "11111111-2222-3333-4444-555555555555",
|
"cluster_id": "11111111-2222-3333-4444-555555555555",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ReturnPorts: func() {
|
|
||||||
freeport.Return(ports)
|
|
||||||
},
|
|
||||||
Stdout: logBuffer,
|
Stdout: logBuffer,
|
||||||
Stderr: logBuffer,
|
Stderr: logBuffer,
|
||||||
Peering: &TestPeeringConfig{Enabled: true},
|
Peering: &TestPeeringConfig{Enabled: true},
|
||||||
@ -271,7 +265,6 @@ func NewTestServerConfigT(t TestingTB, cb ServerConfigCallback) (*TestServer, er
|
|||||||
|
|
||||||
b, err := json.Marshal(cfg)
|
b, err := json.Marshal(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cfg.ReturnPorts()
|
|
||||||
os.RemoveAll(tmpdir)
|
os.RemoveAll(tmpdir)
|
||||||
return nil, errors.Wrap(err, "failed marshaling json")
|
return nil, errors.Wrap(err, "failed marshaling json")
|
||||||
}
|
}
|
||||||
@ -279,7 +272,6 @@ func NewTestServerConfigT(t TestingTB, cb ServerConfigCallback) (*TestServer, er
|
|||||||
t.Logf("CONFIG JSON: %s", string(b))
|
t.Logf("CONFIG JSON: %s", string(b))
|
||||||
configFile := filepath.Join(tmpdir, "config.json")
|
configFile := filepath.Join(tmpdir, "config.json")
|
||||||
if err := ioutil.WriteFile(configFile, b, 0644); err != nil {
|
if err := ioutil.WriteFile(configFile, b, 0644); err != nil {
|
||||||
cfg.ReturnPorts()
|
|
||||||
os.RemoveAll(tmpdir)
|
os.RemoveAll(tmpdir)
|
||||||
return nil, errors.Wrap(err, "failed writing config content")
|
return nil, errors.Wrap(err, "failed writing config content")
|
||||||
}
|
}
|
||||||
@ -291,7 +283,6 @@ func NewTestServerConfigT(t TestingTB, cb ServerConfigCallback) (*TestServer, er
|
|||||||
cmd.Stdout = cfg.Stdout
|
cmd.Stdout = cfg.Stdout
|
||||||
cmd.Stderr = cfg.Stderr
|
cmd.Stderr = cfg.Stderr
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
cfg.ReturnPorts()
|
|
||||||
os.RemoveAll(tmpdir)
|
os.RemoveAll(tmpdir)
|
||||||
return nil, errors.Wrap(err, "failed starting command")
|
return nil, errors.Wrap(err, "failed starting command")
|
||||||
}
|
}
|
||||||
@ -336,7 +327,6 @@ func NewTestServerConfigT(t TestingTB, cb ServerConfigCallback) (*TestServer, er
|
|||||||
// Stop stops the test Consul server, and removes the Consul data
|
// Stop stops the test Consul server, and removes the Consul data
|
||||||
// directory once we are done.
|
// directory once we are done.
|
||||||
func (s *TestServer) Stop() error {
|
func (s *TestServer) Stop() error {
|
||||||
defer s.Config.ReturnPorts()
|
|
||||||
defer os.RemoveAll(s.tmpdir)
|
defer os.RemoveAll(s.tmpdir)
|
||||||
|
|
||||||
// There was no process
|
// There was no process
|
||||||
|
@ -9,4 +9,5 @@ type TestingTB interface {
|
|||||||
Logf(format string, args ...interface{})
|
Logf(format string, args ...interface{})
|
||||||
Name() string
|
Name() string
|
||||||
Fatalf(fmt string, args ...interface{})
|
Fatalf(fmt string, args ...interface{})
|
||||||
|
Helper()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user