update backend

This commit is contained in:
Kenta420 2023-10-27 14:32:37 +07:00
parent 3fe28576d9
commit 5b01f1c431

36
server/main_test.go Normal file
View file

@ -0,0 +1,36 @@
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"testing"
"time"
)
func TestServer(t *testing.T) {
s := NewServer()
serverCtx, serverStopCtx := context.WithCancel(context.Background())
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
// start server 3 minute and stop
go func() {
time.Sleep(180 * time.Second)
serverStopCtx()
}()
// start server
go func() {
err := s.Run()
if err != nil {
log.Fatal(err)
}
}()
// stop server
<-serverCtx.Done()
}