random ip test
continuous-integration/drone/push Build is passing Details
continuous-integration/drone Build is passing Details

master
dustoair 3 years ago
parent dae1b7ff4d
commit 8596e9b4a0

@ -5,8 +5,10 @@ import (
"IPRegion/ip2region"
"encoding/json"
"fmt"
"math/rand"
"sync"
"testing"
"time"
)
func TestIpInfo(tt *testing.T) {
@ -18,6 +20,48 @@ func TestIpInfo(tt *testing.T) {
}
func TestRandomIpInfo(tt *testing.T) {
rand.Seed(time.Now().UnixNano())
var ipInfo ip2region.IpInfo
for {
address := fmt.Sprintf("%d.%d.%d.%d", rand.Intn(255), rand.Intn(255), rand.Intn(255), rand.Intn(255))
done := make(chan struct{}, 1)
go func() {
fmt.Println(address)
ipInfo, _ = ip2region.GetIPInfo(address, global.SearchType)
res, _ := json.Marshal(ipInfo)
fmt.Println(string(res))
}()
select {
case <-done:
fmt.Println("call successfully!!!")
continue
case <-time.After(time.Duration(100 * time.Millisecond)):
fmt.Println("timeout!!!")
continue
}
}
}
func AsyncCall() {
done := make(chan struct{}, 1)
//go func(ctx context.Context) {
// // 发送HTTP请求
// done <- struct{}{}
//}(ctx)
select {
case <-done:
fmt.Println("call successfully!!!")
return
case <-time.After(time.Duration(100 * time.Millisecond)):
fmt.Println("timeout!!!")
return
}
}
// TestIpRangeChannel 内存测试
func TestIpRangeChannel(tt *testing.T) {
ch := make(chan struct{}, 600)

Loading…
Cancel
Save