feat: graceful speed test shutdown

This commit is contained in:
Toby 2024-06-30 20:16:55 -07:00
parent 988b86ae55
commit 6a90fe18ee

View File

@ -3,6 +3,9 @@ package cmd
import ( import (
"errors" "errors"
"fmt" "fmt"
"os"
"os/signal"
"syscall"
"time" "time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -68,11 +71,26 @@ func runSpeedtest(cmd *cobra.Command, args []string) {
zap.Bool("udpEnabled", info.UDPEnabled), zap.Bool("udpEnabled", info.UDPEnabled),
zap.Uint64("tx", info.Tx)) zap.Uint64("tx", info.Tx))
if !skipDownload { signalChan := make(chan os.Signal, 1)
runDownloadTest(c) signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
} defer signal.Stop(signalChan)
if !skipUpload {
runUploadTest(c) runChan := make(chan struct{}, 1)
go func() {
if !skipDownload {
runDownloadTest(c)
}
if !skipUpload {
runUploadTest(c)
}
runChan <- struct{}{}
}()
select {
case <-signalChan:
logger.Info("received signal, shutting down gracefully")
case <-runChan:
logger.Info("speed test complete")
} }
} }