Added waitForPortSet func to ensure server is running
This commit is contained in:
parent
9a2e9fbc3c
commit
ce52aad877
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/status-im/status-go/logutils"
|
"github.com/status-im/status-go/logutils"
|
||||||
|
@ -37,10 +38,16 @@ func makeCert(address net.IP) (*tls.Certificate, []byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeAndStartServer(cert *tls.Certificate, address net.IP) (string, func() error, error) {
|
func makeAndStartServer(cert *tls.Certificate, address net.IP) (string, func() error, error) {
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
wg.Add(1)
|
||||||
|
waitForPortSet := func(int) {
|
||||||
|
wg.Done()
|
||||||
|
}
|
||||||
|
|
||||||
s := server.NewServer(
|
s := server.NewServer(
|
||||||
cert,
|
cert,
|
||||||
address.String(),
|
address.String(),
|
||||||
nil,
|
waitForPortSet,
|
||||||
logutils.ZapLogger().Named("Preflight Server"),
|
logutils.ZapLogger().Named("Preflight Server"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,9 +57,7 @@ func makeAndStartServer(cert *tls.Certificate, address net.IP) (string, func() e
|
||||||
return "", nil, err
|
return "", nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// hack : sleep to give server time
|
wg.Wait()
|
||||||
// TODO something funky with the afterPortChanged func. Maybe waitgroup magic
|
|
||||||
time.Sleep(500 * time.Millisecond)
|
|
||||||
return s.GetHostname() + ":" + strconv.Itoa(s.GetPort()), s.Stop, nil
|
return s.GetHostname() + ":" + strconv.Itoa(s.GetPort()), s.Stop, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue