fstest/test_all: stop test servers on signal, panic, or exit
Until now test_all relied entirely on per-goroutine defer finish() calls in fstest/runs to stop test servers. A Ctrl-C, kill, or panic aborted those defers and left docker containers running, breaking the next run. Register testserver.CleanupAll with lib/atexit so SIGINT/SIGTERM delivery runs the sweep automatically. Also defer atexit.Run for the normal exit and unrecovered-panic paths, and call it explicitly before os.Exit(1) since os.Exit does not fire defers. The fs.Fatalf call sites above only fire before any server starts so they need no explicit sweep.
This commit is contained in:
@@ -24,6 +24,8 @@ import (
|
|||||||
"github.com/rclone/rclone/fs"
|
"github.com/rclone/rclone/fs"
|
||||||
"github.com/rclone/rclone/fs/config/configfile"
|
"github.com/rclone/rclone/fs/config/configfile"
|
||||||
"github.com/rclone/rclone/fstest/runs"
|
"github.com/rclone/rclone/fstest/runs"
|
||||||
|
"github.com/rclone/rclone/fstest/testserver"
|
||||||
|
"github.com/rclone/rclone/lib/atexit"
|
||||||
"github.com/rclone/rclone/lib/pacer"
|
"github.com/rclone/rclone/lib/pacer"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,6 +53,13 @@ func init() {
|
|||||||
var Opt = &runs.RunOpt{}
|
var Opt = &runs.RunOpt{}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// Make sure any test servers we start get stopped on exit or
|
||||||
|
// signal. Without this, a killed test_all run leaves docker
|
||||||
|
// containers behind (refcount never decrements) and breaks
|
||||||
|
// subsequent runs.
|
||||||
|
atexit.Register(testserver.CleanupAll)
|
||||||
|
defer atexit.Run()
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
conf, err := runs.NewConfig(Opt.ConfigFile)
|
conf, err := runs.NewConfig(Opt.ConfigFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -144,6 +153,7 @@ func main() {
|
|||||||
report.EmailHTML(*Opt)
|
report.EmailHTML(*Opt)
|
||||||
report.Upload(*Opt)
|
report.Upload(*Opt)
|
||||||
if !report.AllPassed() {
|
if !report.AllPassed() {
|
||||||
|
atexit.Run()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user