Skip to content

Commit

Permalink
Merge pull request #1136 from apernet/wip-speedtest-grace
Browse files Browse the repository at this point in the history
feat: graceful speed test shutdown
  • Loading branch information
tobyxdd committed Jul 1, 2024
2 parents 988b86a + 6a90fe1 commit 5315b60
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 5315b60

Please sign in to comment.