mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-03 16:20:27 +00:00
use atomic for test shutdown
This commit is contained in:
parent
0c6fe4ea62
commit
d10ae78725
1 changed files with 4 additions and 3 deletions
|
@ -2,6 +2,7 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -72,14 +73,14 @@ func Test_GracefulServerShutdownWithWorkers(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_GracefulServerShutdownWithRequests(t *testing.T) {
|
func Test_GracefulServerShutdownWithRequests(t *testing.T) {
|
||||||
isFinished := false
|
var isFinished atomic.Bool
|
||||||
|
|
||||||
router := http.NewServeMux()
|
router := http.NewServeMux()
|
||||||
|
|
||||||
// add long running handler func
|
// add long running handler func
|
||||||
router.HandleFunc("/test", func(rw http.ResponseWriter, r *http.Request) {
|
router.HandleFunc("/test", func(rw http.ResponseWriter, r *http.Request) {
|
||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 3)
|
||||||
isFinished = true
|
isFinished.Store(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
svr := testServer(t, router)
|
svr := testServer(t, router)
|
||||||
|
@ -94,5 +95,5 @@ func Test_GracefulServerShutdownWithRequests(t *testing.T) {
|
||||||
err := svr.Shutdown("test")
|
err := svr.Shutdown("test")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.True(t, isFinished)
|
assert.True(t, isFinished.Load())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue