github.com/TeaOSLab/EdgeNode@v1.3.8/internal/utils/agents/queue_test.go (about)

     1  // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  
     3  package agents_test
     4  
     5  import (
     6  	"github.com/TeaOSLab/EdgeNode/internal/utils/agents"
     7  	"github.com/TeaOSLab/EdgeNode/internal/utils/testutils"
     8  	"github.com/iwind/TeaGo/assert"
     9  	_ "github.com/iwind/TeaGo/bootstrap"
    10  	"testing"
    11  	"time"
    12  )
    13  
    14  func TestParseQueue_Process(t *testing.T) {
    15  	if !testutils.IsSingleTesting() {
    16  		return
    17  	}
    18  
    19  	var queue = agents.NewQueue()
    20  	go queue.Start()
    21  	time.Sleep(1 * time.Second)
    22  	queue.Push("220.181.13.100")
    23  	time.Sleep(1 * time.Second)
    24  }
    25  
    26  func TestParseQueue_ParseIP(t *testing.T) {
    27  	if !testutils.IsSingleTesting() {
    28  		return
    29  	}
    30  
    31  	var queue = agents.NewQueue()
    32  	for _, ip := range []string{
    33  		"192.168.1.100",
    34  		"42.120.160.1",
    35  		"42.236.10.98",
    36  		"124.115.0.100",
    37  	} {
    38  		ptr, err := queue.ParseIP(ip)
    39  		if err != nil {
    40  			t.Log(ip, "=>", err)
    41  			continue
    42  		}
    43  		t.Log(ip, "=>", ptr)
    44  	}
    45  }
    46  
    47  func TestParseQueue_ParsePtr(t *testing.T) {
    48  	var a = assert.NewAssertion(t)
    49  
    50  	var queue = agents.NewQueue()
    51  	for _, s := range [][]string{
    52  		{"baiduspider-220-181-108-101.crawl.baidu.com.", "baidu"},
    53  		{"crawl-66-249-71-219.googlebot.com.", "google"},
    54  		{"msnbot-40-77-167-31.search.msn.com.", "bing"},
    55  		{"sogouspider-49-7-20-129.crawl.sogou.com.", "sogou"},
    56  		{"m13102.mail.163.com.", "youdao"},
    57  		{"yeurosport.pat1.tc2.yahoo.com.", "yahoo"},
    58  		{"shenmaspider-42-120-160-1.crawl.sm.cn.", "sm"},
    59  		{"93-158-161-39.spider.yandex.com.", "yandex"},
    60  		{"25.bl.bot.semrush.com.", "semrush"},
    61  	} {
    62  		a.IsTrue(queue.ParsePtr(s[0]) == s[1])
    63  	}
    64  }
    65  
    66  func BenchmarkQueue_ParsePtr(b *testing.B) {
    67  	var queue = agents.NewQueue()
    68  
    69  	for i := 0; i < b.N; i++ {
    70  		for _, s := range [][]string{
    71  			{"baiduspider-220-181-108-101.crawl.baidu.com.", "baidu"},
    72  			{"crawl-66-249-71-219.googlebot.com.", "google"},
    73  			{"msnbot-40-77-167-31.search.msn.com.", "bing"},
    74  			{"sogouspider-49-7-20-129.crawl.sogou.com.", "sogou"},
    75  			{"m13102.mail.163.com.", "youdao"},
    76  			{"yeurosport.pat1.tc2.yahoo.com.", "yahoo"},
    77  			{"shenmaspider-42-120-160-1.crawl.sm.cn.", "sm"},
    78  			{"93-158-161-39.spider.yandex.com.", "yandex"},
    79  			{"93.158.164.218-red.dhcp.yndx.net.", "yandex"},
    80  			{"25.bl.bot.semrush.com.", "semrush"},
    81  		} {
    82  			queue.ParsePtr(s[0])
    83  		}
    84  	}
    85  }