File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,10 @@ package tests
33import (
44 "bytes"
55 "compress/gzip"
6+ "fmt"
67 "io"
78 "log"
9+ "net"
810 "net/http"
911 "os"
1012 "testing"
@@ -19,18 +21,33 @@ import (
1921)
2022
2123const (
22- srvAddr = ":10200"
23- srvRoot = "http://127.0.0.1:10200"
2424 namespaceKey = "req"
2525 group = "test"
2626)
2727
2828var (
29- srv = fastglue .NewGlue ()
29+ srv = fastglue .NewGlue ()
30+ srvAddr = dummyServAddr ()
31+ srvRoot = "http://127.0.0.1" + srvAddr
3032
3133 content = []byte ("this is the reasonbly long test content that may be compressed" )
3234)
3335
36+ // dummyServeAddr returns a random port address.
37+ func dummyServAddr () string {
38+ // Dynamically allocate an available port
39+ listener , err := net .Listen ("tcp" , ":0" )
40+ if err != nil {
41+ panic (err )
42+ }
43+ defer listener .Close ()
44+
45+ // Get the actual port that was allocated
46+ port := listener .Addr ().(* net.TCPAddr ).Port
47+
48+ return fmt .Sprintf (":%d" , port )
49+ }
50+
3451func init () {
3552 // Setup fastcache.
3653 rd , err := miniredis .Run ()
You can’t perform that action at this time.
0 commit comments