Skip to content

Commit

Permalink
feat: graceful speed test shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyxdd committed Jul 1, 2024
1 parent 988b86a commit 6a90fe1
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions app/cmd/speedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package cmd
import (
"errors"
"fmt"
"os"
"os/signal"
"syscall"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -68,11 +71,26 @@ func runSpeedtest(cmd *cobra.Command, args []string) {
zap.Bool("udpEnabled", info.UDPEnabled),
zap.Uint64("tx", info.Tx))

if !skipDownload {
runDownloadTest(c)
}
if !skipUpload {
runUploadTest(c)
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(signalChan)

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")
}
}

Expand Down

0 comments on commit 6a90fe1

Please sign in to comment.