MCPcopy Create free account
hub / github.com/apecloud/myduckserver / FindFreePort

Function FindFreePort

testutil/testutil.go:219–235  ·  view source on GitHub ↗

FindFreePort returns an available port that can be used for a server. If any errors are encountered, this function will panic and fail the current test.

()

Source from the content-addressed store, hash-verified

217 cachedDevBuildPath = fullpath
218
219 return cachedDevBuildPath
220}
221
222// FindFreePort returns an available port that can be used for a server. If any errors are
223// encountered, this function will panic and fail the current test.
224func FindFreePort() int {
225 listener, err := net.Listen("tcp", ":0")
226 if err != nil {
227 panic(fmt.Sprintf("unable to find available TCP port: %v", err.Error()))
228 }
229 freePort := listener.Addr().(*net.TCPAddr).Port
230 err = listener.Close()
231 if err != nil {
232 panic(fmt.Sprintf("unable to find available TCP port: %v", err.Error()))
233 }
234
235 if freePort < 0 {
236 panic(fmt.Sprintf("unable to find available TCP port; found port %v", freePort))
237 }
238

Callers 3

startMySqlServerFunction · 0.92
configureToxiProxyFunction · 0.92
StartDuckSqlServerFunction · 0.85

Calls 2

AddrMethod · 0.80
CloseMethod · 0.65

Tested by 2

startMySqlServerFunction · 0.74
configureToxiProxyFunction · 0.74