Skip to content

Commit

Permalink
Fix: orbstack udp loss case test failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamacro committed Aug 29, 2023
1 parent 927c0db commit 5ec4d99
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
52 changes: 28 additions & 24 deletions test/clash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net/netip"
"os"
"path/filepath"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -437,27 +436,30 @@ func testLargeDataWithPacketConn(t *testing.T, pc net.PacketConn) error {
pingCh, pongCh, test := newLargeDataPair()
writeRandData := func(pc net.PacketConn, addr net.Addr) (map[int][]byte, error) {
hashMap := map[int][]byte{}
mux := sync.Mutex{}
bufs := [][]byte{}

for i := 0; i < times; i++ {
go func(idx int) {
buf := make([]byte, chunkSize)
if _, err := rand.Read(buf[1:]); err != nil {
t.Log(err.Error())
return
}
buf[0] = byte(idx)
idx := i
buf := make([]byte, chunkSize)
rand.Read(buf[1:])
buf[0] = byte(idx)

hash := md5.Sum(buf)
mux.Lock()
hashMap[idx] = hash[:]
mux.Unlock()
hash := md5.Sum(buf)
hashMap[idx] = hash[:]
bufs = append(bufs, buf)
}

go func() {
cursor := 0
for {
idx := cursor % times
buf := bufs[idx]
if _, err := pc.WriteTo(buf, addr); err != nil {
t.Log(err.Error())
return
}
}(i)
}
cursor++
}
}()

return hashMap, nil
}
Expand All @@ -467,15 +469,16 @@ func testLargeDataWithPacketConn(t *testing.T, pc net.PacketConn) error {
hashMap := map[int][]byte{}
buf := make([]byte, 64*1024)

for i := 0; i < times; i++ {
for len(hashMap) != times {
_, rAddr, err = l.ReadFrom(buf)
if err != nil {
t.Log(err.Error())
return
}

hash := md5.Sum(buf[:chunkSize])
hashMap[int(buf[0])] = hash[:]
if _, ok := hashMap[int(buf[0])]; !ok {
hash := md5.Sum(buf[:chunkSize])
hashMap[int(buf[0])] = hash[:]
}
}

sendHash, err := writeRandData(l, rAddr)
Expand All @@ -500,15 +503,16 @@ func testLargeDataWithPacketConn(t *testing.T, pc net.PacketConn) error {
hashMap := map[int][]byte{}
buf := make([]byte, 64*1024)

for i := 0; i < times; i++ {
for len(hashMap) != times {
_, _, err := pc.ReadFrom(buf)
if err != nil {
t.Log(err.Error())
return
}

hash := md5.Sum(buf[:chunkSize])
hashMap[int(buf[0])] = hash[:]
if _, ok := hashMap[int(buf[0])]; !ok {
hash := md5.Sum(buf[:chunkSize])
hashMap[int(buf[0])] = hash[:]
}
}

pongCh <- hashPair{
Expand Down
2 changes: 1 addition & 1 deletion test/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dns:
fake-ip-filter:
- .sslip.io
nameserver:
- 119.29.29.29
- https://doh.pub/dns-query
`

err := parseAndApply(basic)
Expand Down

0 comments on commit 5ec4d99

Please sign in to comment.