master
dustoair 3 years ago
parent 1090a979f9
commit 750a346636

@ -5,6 +5,7 @@ import (
"IPRegion/ip2region"
"encoding/json"
"fmt"
"sync"
"testing"
)
@ -16,3 +17,48 @@ func TestIpInfo(tt *testing.T) {
fmt.Println(string(res))
}
// TestIpRangeChannel 内存测试
func TestIpRangeChannel(tt *testing.T) {
ch := make(chan struct{}, 600)
defer close(ch)
for ip1 := 1; ip1 <= 255; ip1++ {
for ip2 := 0; ip2 <= 255; ip2++ {
for ip3 := 0; ip3 <= 255; ip3++ {
for ip4 := 1; ip4 <= 254; ip4++ {
ch <- struct{}{}
go func() {
address := fmt.Sprintf("%d.%d.%d.%d", ip1, ip2, ip3, ip4)
ipInfo, _ := ip2region.GetIPInfo(address, global.SearchType)
_, _ = json.Marshal(ipInfo)
fmt.Println(address)
<-ch
}()
}
}
}
}
}
// TestIpRangeLock 不限制情况 内存漏完
func TestIpRangeLock(tt *testing.T) {
var lock sync.Mutex
for ip1 := 1; ip1 <= 255; ip1++ {
for ip2 := 0; ip2 <= 255; ip2++ {
for ip3 := 0; ip3 <= 255; ip3++ {
for ip4 := 1; ip4 <= 254; ip4++ {
go func() {
lock.Lock()
address := fmt.Sprintf("%d.%d.%d.%d", ip1, ip2, ip3, ip4)
ipInfo, _ := ip2region.GetIPInfo(address, global.SearchType)
res, _ := json.Marshal(ipInfo)
fmt.Println(string(res))
lock.Unlock()
}()
}
}
}
}
}

Loading…
Cancel
Save