mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2025-12-31 15:36:37 +08:00
改进获取随机端口算法
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package nodeconfigs
|
||||
|
||||
import (
|
||||
"net"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTOAConfig_RandLocalPort(t *testing.T) {
|
||||
@@ -27,6 +29,19 @@ func TestTOAConfig_RandLocalPort(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTOAConfig_FreePort(t *testing.T) {
|
||||
before := time.Now()
|
||||
listener, err := net.Listen("tcp", ":0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(listener.Addr())
|
||||
_ = listener.Close()
|
||||
t.Log(time.Since(before).Seconds()*1000, "ms")
|
||||
time.Sleep(30 * time.Second)
|
||||
}
|
||||
|
||||
|
||||
func TestTOAConfig_AsArgs(t *testing.T) {
|
||||
toa := &TOAConfig{
|
||||
IsOn: false,
|
||||
|
||||
Reference in New Issue
Block a user