Skip to content

Commit bc54891

Browse files
committed
feat(dstp): simplify timeout logic
Signed-off-by: Yagiz Degirmenci <yagizcanilbey1903@gmail.com>
1 parent d9a319a commit bc54891

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

cmd/dstp/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package main
33
import (
44
"context"
55
"flag"
6+
"fmt"
67
"github.com/ycd/dstp/config"
78
"github.com/ycd/dstp/pkg/dstp"
89
"os"
910
"path/filepath"
10-
"fmt"
1111
)
1212

1313
func main() {

pkg/dstp/dstp.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ func RunAllTests(ctx context.Context, config config.Config) error {
2525
return err
2626
}
2727

28+
if config.Timeout == -1 {
29+
config.Timeout = 2 * config.PingCount
30+
}
31+
2832
var wg sync.WaitGroup
2933
wg.Add(5)
3034

@@ -64,6 +68,7 @@ func testTLS(ctx context.Context, wg *sync.WaitGroup, address common.Address, t
6468
result.Mu.Unlock()
6569
return err
6670
}
71+
6772
err = conn.VerifyHostname(string(address))
6873
if err != nil {
6974
result.Mu.Lock()

pkg/ping/dns.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ func RunDNSTest(ctx context.Context, wg *sync.WaitGroup, addr common.Address, co
1717
}
1818

1919
pinger.Count = count
20-
if timeout == -1 {
21-
pinger.Timeout = time.Duration(2*count) * time.Second
22-
} else {
23-
pinger.Timeout = time.Duration(timeout) * time.Second
24-
}
20+
pinger.Timeout = time.Duration(timeout) * time.Second
21+
2522
err = pinger.Run()
2623
if err != nil {
2724
return fmt.Errorf("failed to run ping: %v", err.Error())

pkg/ping/ping.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import (
55
"bytes"
66
"context"
77
"fmt"
8+
"github.com/ycd/dstp/pkg/common"
89
"log"
910
"os/exec"
1011
"runtime"
1112
"strings"
1213
"sync"
1314
"time"
14-
15-
"github.com/ycd/dstp/pkg/common"
1615
)
1716

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

3130
pinger.Count = count
32-
if timeout == -1 {
33-
pinger.Timeout = time.Duration(2*count) * time.Second
34-
} else {
35-
pinger.Timeout = time.Duration(timeout) * time.Second
36-
}
31+
pinger.Timeout = time.Duration(timeout) * time.Second
32+
3733
err = pinger.Run()
3834
if err != nil {
3935
if out, err := runPingFallback(ctx, addr, count); err == nil {

0 commit comments

Comments
 (0)