mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-19 00:50:29 +00:00
tests: improve repo package coverage (#3)
* refactor and add repo tests * add CI name * use atomic for test shutdown * use go 1.19 * add timeout
This commit is contained in:
parent
888ecfde34
commit
508e2e59bd
20 changed files with 540 additions and 186 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