1
0

Fix: orbstack udp loss case test failed

This commit is contained in:
Dreamacro 2023-08-29 21:17:06 +08:00
parent 927c0db3a9
commit 5ec4d993b8
2 changed files with 32 additions and 28 deletions

View File

@ -11,7 +11,6 @@ import (
"net/netip"
"os"
"path/filepath"
"sync"
"testing"
"time"
@ -437,28 +436,31 @@ 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()
if _, err := pc.WriteTo(buf, addr); err != nil {
t.Log(err.Error())
return
}
}(i)
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 {
return
}
cursor++
}
}()
return hashMap, nil
}
@ -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)
@ -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{

View File

@ -63,7 +63,7 @@ dns:
fake-ip-filter:
- .sslip.io
nameserver:
- 119.29.29.29
- https://doh.pub/dns-query
`
err := parseAndApply(basic)