Skip to content

Commit af1db06

Browse files
committed
fix test status printing
1 parent b15ea1b commit af1db06

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ OPTIONS:
2424
print version and exit
2525
```
2626

27-
Stargate now operates as a single SOCKS5 proxy server that randomly selects egress IP addresses from your specified CIDR range. This approach is much more memory-efficient and suitable for large IPv6 ranges.
27+
Stargate operates as a single SOCKS5 proxy server that randomly selects egress IP addresses from your specified CIDR range. This approach is much more memory-efficient and suitable for large IPv6 ranges.
2828

2929
## Test Flag - Preventing IP Address Leakage
3030

test.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,27 @@ func test(ctx context.Context, parsedNetwork netip.Prefix, cidrSize uint) error
6767
})
6868

6969
// print testing status
70-
statusStop := make(chan bool)
70+
statusStop := make(chan bool, 1)
71+
statusDone := make(chan bool, 1)
7172
if !*verbose {
72-
defer func() { statusStop <- true }()
7373
go func() {
74+
ticker := time.NewTicker(time.Second / 4)
75+
defer ticker.Stop()
76+
done := false
7477
for {
7578
select {
7679
case <-statusStop:
80+
done = true
81+
case <-ticker.C:
82+
}
83+
testedCount := tested.Load()
84+
totalHosts := ipItr.Size()
85+
progress := float64(testedCount) / float64(totalHosts) * 100
86+
fmt.Printf("\r Testing %d/%d (%.1f%%) failures: %d", testedCount, totalHosts, progress, failed.Load())
87+
if done {
7788
fmt.Printf("\n") // Clear the status
89+
close(statusDone)
7890
return
79-
default:
80-
testedCount := tested.Load()
81-
totalHosts := ipItr.Size()
82-
progress := float64(testedCount) / float64(totalHosts) * 100
83-
fmt.Printf("\r Testing %d/%d (%.1f%%) failures: %d", testedCount, totalHosts, progress, failed.Load())
8491
}
8592
}
8693
}()
@@ -115,9 +122,17 @@ func test(ctx context.Context, parsedNetwork netip.Prefix, cidrSize uint) error
115122

116123
// Wait for all goroutines to complete
117124
if err := group.Wait(); err != nil {
125+
statusStop <- true
118126
return err
119127
}
120128

129+
// stop status printing
130+
if !*verbose {
131+
statusStop <- true
132+
// wait for last status print
133+
<-statusDone
134+
}
135+
121136
if failedCount := failed.Load(); failedCount > 0 {
122137
return fmt.Errorf("test finished with %d/%d failures", failedCount, ipItr.Size())
123138
}

0 commit comments

Comments
 (0)