update backend
This commit is contained in:
parent
3fe28576d9
commit
5b01f1c431
1 changed files with 36 additions and 0 deletions
36
server/main_test.go
Normal file
36
server/main_test.go
Normal 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()
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue