Skip to content

Commit

Permalink
feat(dstp): simplify timeout logic
Browse files Browse the repository at this point in the history
Signed-off-by: Yagiz Degirmenci <yagizcanilbey1903@gmail.com>
  • Loading branch information
ycd committed Nov 24, 2021
1 parent d9a319a commit bc54891
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/dstp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package main
import (
"context"
"flag"
"fmt"
"github.com/ycd/dstp/config"
"github.com/ycd/dstp/pkg/dstp"
"os"
"path/filepath"
"fmt"
)

func main() {
Expand Down
5 changes: 5 additions & 0 deletions pkg/dstp/dstp.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func RunAllTests(ctx context.Context, config config.Config) error {
return err
}

if config.Timeout == -1 {
config.Timeout = 2 * config.PingCount
}

var wg sync.WaitGroup
wg.Add(5)

Expand Down Expand Up @@ -64,6 +68,7 @@ func testTLS(ctx context.Context, wg *sync.WaitGroup, address common.Address, t
result.Mu.Unlock()
return err
}

err = conn.VerifyHostname(string(address))
if err != nil {
result.Mu.Lock()
Expand Down
7 changes: 2 additions & 5 deletions pkg/ping/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ func RunDNSTest(ctx context.Context, wg *sync.WaitGroup, addr common.Address, co
}

pinger.Count = count
if timeout == -1 {
pinger.Timeout = time.Duration(2*count) * time.Second
} else {
pinger.Timeout = time.Duration(timeout) * time.Second
}
pinger.Timeout = time.Duration(timeout) * time.Second

err = pinger.Run()
if err != nil {
return fmt.Errorf("failed to run ping: %v", err.Error())
Expand Down
10 changes: 3 additions & 7 deletions pkg/ping/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (
"bytes"
"context"
"fmt"
"github.com/ycd/dstp/pkg/common"
"log"
"os/exec"
"runtime"
"strings"
"sync"
"time"

"github.com/ycd/dstp/pkg/common"
)

func RunTest(ctx context.Context, wg *sync.WaitGroup, addr common.Address, count int, timeout int, result *common.Result) error {
Expand All @@ -29,11 +28,8 @@ func runPing(ctx context.Context, wg *sync.WaitGroup, addr common.Address, count
}

pinger.Count = count
if timeout == -1 {
pinger.Timeout = time.Duration(2*count) * time.Second
} else {
pinger.Timeout = time.Duration(timeout) * time.Second
}
pinger.Timeout = time.Duration(timeout) * time.Second

err = pinger.Run()
if err != nil {
if out, err := runPingFallback(ctx, addr, count); err == nil {
Expand Down

0 comments on commit bc54891

Please sign in to comment.