commands: Improve server startup to make tests less flaky

Do this by announcing/listen on the local address before we start the server.
This commit is contained in:
Bjørn Erik Pedersen
2022-03-18 08:54:44 +01:00
parent 0e305d6958
commit 9539069f5e
5 changed files with 84 additions and 55 deletions

View File

@@ -17,6 +17,7 @@ import (
"bytes"
"errors"
"io/ioutil"
"net"
"os"
"path/filepath"
"regexp"
@@ -88,7 +89,8 @@ type commandeer struct {
// Used in cases where we get flooded with events in server mode.
debounce func(f func())
serverPorts []int
serverPorts []serverPortListener
languagesConfigured bool
languages langs.Languages
doLiveReload bool
@@ -105,6 +107,11 @@ type commandeer struct {
buildErr error
}
type serverPortListener struct {
p int
ln net.Listener
}
func newCommandeerHugoState() *commandeerHugoState {
return &commandeerHugoState{
created: make(chan struct{}),
@@ -420,6 +427,7 @@ func (c *commandeer) loadConfig() error {
if h == nil || c.failOnInitErr {
err = createErr
}
c.hugoSites = h
// TODO(bep) improve.
if c.buildLock == nil && h != nil {