forked from cwtch.im/cwtch
fix integ tests to not leak go threads, re make it an error
This commit is contained in:
parent
4d11547393
commit
c8541a5e36
|
@ -22,6 +22,7 @@ type Server struct {
|
||||||
app *application.RicochetApplication
|
app *application.RicochetApplication
|
||||||
config Config
|
config Config
|
||||||
metricsPack metrics.Monitors
|
metricsPack metrics.Monitors
|
||||||
|
closed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts a server with the given privateKey
|
// Run starts a server with the given privateKey
|
||||||
|
@ -29,6 +30,7 @@ type Server struct {
|
||||||
// TODO: handle HUP/KILL signals to exit and close Tor gracefully
|
// TODO: handle HUP/KILL signals to exit and close Tor gracefully
|
||||||
// TODO: handle user input to exit
|
// TODO: handle user input to exit
|
||||||
func (s *Server) Run(acn connectivity.ACN, serverConfig Config) {
|
func (s *Server) Run(acn connectivity.ACN, serverConfig Config) {
|
||||||
|
s.closed = false
|
||||||
s.config = serverConfig
|
s.config = serverConfig
|
||||||
cwtchserver := new(application.RicochetApplication)
|
cwtchserver := new(application.RicochetApplication)
|
||||||
s.metricsPack.Start(cwtchserver, serverConfig.ConfigDir, s.config.ServerReporting.LogMetricsToFile)
|
s.metricsPack.Start(cwtchserver, serverConfig.ConfigDir, s.config.ServerReporting.LogMetricsToFile)
|
||||||
|
@ -83,12 +85,16 @@ func (s *Server) Run(acn connectivity.ACN, serverConfig Config) {
|
||||||
} else {
|
} else {
|
||||||
s.app.Run(listenService)
|
s.app.Run(listenService)
|
||||||
}
|
}
|
||||||
|
if s.closed {
|
||||||
|
return
|
||||||
|
}
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown kills the app closing all connections and freeing all goroutines
|
// Shutdown kills the app closing all connections and freeing all goroutines
|
||||||
func (s *Server) Shutdown() {
|
func (s *Server) Shutdown() {
|
||||||
|
s.closed = true
|
||||||
s.app.Shutdown()
|
s.app.Shutdown()
|
||||||
s.metricsPack.Stop()
|
s.metricsPack.Stop()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
cwtchserver "cwtch.im/cwtch/server"
|
cwtchserver "cwtch.im/cwtch/server"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||||
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
"golang.org/x/net/proxy"
|
"golang.org/x/net/proxy"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -100,6 +101,7 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
||||||
// Hide logging "noise"
|
// Hide logging "noise"
|
||||||
numGoRoutinesStart := runtime.NumGoroutine()
|
numGoRoutinesStart := runtime.NumGoroutine()
|
||||||
|
|
||||||
|
log.AddEverythingFromPattern("connectivity")
|
||||||
acn, err := connectivity.StartTor(".", "")
|
acn, err := connectivity.StartTor(".", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Could not start Tor: %v", err)
|
t.Fatalf("Could not start Tor: %v", err)
|
||||||
|
@ -395,17 +397,22 @@ func TestCwtchPeerIntegration(t *testing.T) {
|
||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 3)
|
||||||
numGoRoutinesPostCarol := runtime.NumGoroutine()
|
numGoRoutinesPostCarol := runtime.NumGoroutine()
|
||||||
|
|
||||||
|
fmt.Println("Shutting down ACN...")
|
||||||
|
acn.Close()
|
||||||
|
time.Sleep(time.Second * 2) // Server ^^ has a 5 second loop attempting reconnect before exiting
|
||||||
|
numGoRoutinesPostACN := runtime.NumGoroutine()
|
||||||
|
|
||||||
// Printing out the current goroutines
|
// Printing out the current goroutines
|
||||||
// Very useful if we are leaking any.
|
// Very useful if we are leaking any.
|
||||||
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||||||
|
|
||||||
fmt.Printf("numGoRoutinesStart: %v\nnumGoRoutinesPostServer: %v\nnumGoRoutinesPostPeerStart: %v\nnumGoRoutinesPostPeerAndServerConnect: %v\n"+
|
fmt.Printf("numGoRoutinesStart: %v\nnumGoRoutinesPostServer: %v\nnumGoRoutinesPostPeerStart: %v\nnumGoRoutinesPostPeerAndServerConnect: %v\n"+
|
||||||
"numGoRoutinesPostAlice: %v\nnumGoRotinesPostCarolConnect: %v\nnumGoRoutinesPostBob: %v\nnumGoRoutinesPostServerShutdown: %v\nnumGoRoutinesPostCarol: %v\n",
|
"numGoRoutinesPostAlice: %v\nnumGoRotinesPostCarolConnect: %v\nnumGoRoutinesPostBob: %v\nnumGoRoutinesPostServerShutdown: %v\nnumGoRoutinesPostCarol: %v\nnumGoRoutinesPostACN: %v\n",
|
||||||
numGoRoutinesStart, numGoRoutinesPostServer, numGoRoutinesPostPeerStart, numGoRoutinesPostServerConnect,
|
numGoRoutinesStart, numGoRoutinesPostServer, numGoRoutinesPostPeerStart, numGoRoutinesPostServerConnect,
|
||||||
numGoRoutinesPostAlice, numGoRotinesPostCarolConnect, numGoRoutinesPostBob, numGoRoutinesPostServerShutdown, numGoRoutinesPostCarol)
|
numGoRoutinesPostAlice, numGoRotinesPostCarolConnect, numGoRoutinesPostBob, numGoRoutinesPostServerShutdown, numGoRoutinesPostCarol, numGoRoutinesPostACN)
|
||||||
|
|
||||||
if numGoRoutinesStart != numGoRoutinesPostCarol {
|
if numGoRoutinesStart != numGoRoutinesPostACN {
|
||||||
t.Logf("Number of GoRoutines at start (%v) does not match number of goRoutines after cleanup of peers and servers (%v), clean up failed, leak detected!", numGoRoutinesStart, numGoRoutinesPostCarol)
|
t.Errorf("Number of GoRoutines at start (%v) does not match number of goRoutines after cleanup of peers and servers (%v), clean up failed, leak detected!", numGoRoutinesStart, numGoRoutinesPostACN)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue