mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-02 15:50: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 (
|
||||
"net/http"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -72,14 +73,14 @@ func Test_GracefulServerShutdownWithWorkers(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_GracefulServerShutdownWithRequests(t *testing.T) {
|
||||
isFinished := false
|
||||
var isFinished atomic.Bool
|
||||
|
||||
router := http.NewServeMux()
|
||||
|
||||
// add long running handler func
|
||||
router.HandleFunc("/test", func(rw http.ResponseWriter, r *http.Request) {
|
||||
time.Sleep(time.Second * 3)
|
||||
isFinished = true
|
||||
isFinished.Store(true)
|
||||
})
|
||||
|
||||
svr := testServer(t, router)
|
||||
|
@ -94,5 +95,5 @@ func Test_GracefulServerShutdownWithRequests(t *testing.T) {
|
|||
err := svr.Shutdown("test")
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.True(t, isFinished)
|
||||
assert.True(t, isFinished.Load())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue