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" "net/netip"
"os" "os"
"path/filepath" "path/filepath"
"sync"
"testing" "testing"
"time" "time"
@ -437,28 +436,31 @@ func testLargeDataWithPacketConn(t *testing.T, pc net.PacketConn) error {
pingCh, pongCh, test := newLargeDataPair() pingCh, pongCh, test := newLargeDataPair()
writeRandData := func(pc net.PacketConn, addr net.Addr) (map[int][]byte, error) { writeRandData := func(pc net.PacketConn, addr net.Addr) (map[int][]byte, error) {
hashMap := map[int][]byte{} hashMap := map[int][]byte{}
mux := sync.Mutex{} bufs := [][]byte{}
for i := 0; i < times; i++ { for i := 0; i < times; i++ {
go func(idx int) { idx := i
buf := make([]byte, chunkSize) buf := make([]byte, chunkSize)
if _, err := rand.Read(buf[1:]); err != nil { rand.Read(buf[1:])
t.Log(err.Error()) buf[0] = byte(idx)
return
}
buf[0] = byte(idx)
hash := md5.Sum(buf) hash := md5.Sum(buf)
mux.Lock() hashMap[idx] = hash[:]
hashMap[idx] = hash[:] bufs = append(bufs, buf)
mux.Unlock()
if _, err := pc.WriteTo(buf, addr); err != nil {
t.Log(err.Error())
return
}
}(i)
} }
go func() {
cursor := 0
for {
idx := cursor % times
buf := bufs[idx]
if _, err := pc.WriteTo(buf, addr); err != nil {
return
}
cursor++
}
}()
return hashMap, nil return hashMap, nil
} }
@ -467,15 +469,16 @@ func testLargeDataWithPacketConn(t *testing.T, pc net.PacketConn) error {
hashMap := map[int][]byte{} hashMap := map[int][]byte{}
buf := make([]byte, 64*1024) buf := make([]byte, 64*1024)
for i := 0; i < times; i++ { for len(hashMap) != times {
_, rAddr, err = l.ReadFrom(buf) _, rAddr, err = l.ReadFrom(buf)
if err != nil { if err != nil {
t.Log(err.Error())
return return
} }
hash := md5.Sum(buf[:chunkSize]) if _, ok := hashMap[int(buf[0])]; !ok {
hashMap[int(buf[0])] = hash[:] hash := md5.Sum(buf[:chunkSize])
hashMap[int(buf[0])] = hash[:]
}
} }
sendHash, err := writeRandData(l, rAddr) sendHash, err := writeRandData(l, rAddr)
@ -500,15 +503,16 @@ func testLargeDataWithPacketConn(t *testing.T, pc net.PacketConn) error {
hashMap := map[int][]byte{} hashMap := map[int][]byte{}
buf := make([]byte, 64*1024) buf := make([]byte, 64*1024)
for i := 0; i < times; i++ { for len(hashMap) != times {
_, _, err := pc.ReadFrom(buf) _, _, err := pc.ReadFrom(buf)
if err != nil { if err != nil {
t.Log(err.Error())
return return
} }
hash := md5.Sum(buf[:chunkSize]) if _, ok := hashMap[int(buf[0])]; !ok {
hashMap[int(buf[0])] = hash[:] hash := md5.Sum(buf[:chunkSize])
hashMap[int(buf[0])] = hash[:]
}
} }
pongCh <- hashPair{ pongCh <- hashPair{

View File

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