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:
Hayden 2022-09-05 00:26:21 -08:00 committed by GitHub
parent 888ecfde34
commit 508e2e59bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 540 additions and 186 deletions

View file

@ -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())
}