Improve test performance (better waiting logic until http server is up)

This commit is contained in:
2022-11-30 23:46:28 +01:00
parent fd182f0abb
commit 12db23d076
4 changed files with 22 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/gin-gonic/gin/binding"
"github.com/rs/zerolog/log"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"gogs.mikescher.com/BlackForestBytes/goext/syncext"
"math/rand"
"net"
"net/http"
@@ -33,12 +34,14 @@ type Application struct {
Jobs []Job
stopChan chan bool
Port string
IsRunning *syncext.AtomicBool
}
func NewApp(db *db.Database) *Application {
return &Application{
Database: db,
stopChan: make(chan bool, 8),
Database: db,
stopChan: make(chan bool),
IsRunning: syncext.NewAtomicBool(false),
}
}
@@ -51,7 +54,10 @@ func (app *Application) Init(cfg scn.Config, g *gin.Engine, fb push.Notification
}
func (app *Application) Stop() {
app.stopChan <- true
// non-blocking send
select {
case app.stopChan <- true:
}
}
func (app *Application) Run() {
@@ -80,6 +86,8 @@ func (app *Application) Run() {
app.Port = port
app.IsRunning.Set(true) // the net.Listener a few lines above is at this point actually already buffering requests
errChan <- httpserver.Serve(ln)
}()
@@ -126,6 +134,8 @@ func (app *Application) Run() {
for _, job := range app.Jobs {
job.Stop()
}
app.IsRunning.Set(false)
}
func (app *Application) GenerateRandomAuthKey() string {