github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/catgo/catgo_test.go (about)

     1  package catgo
     2  
     3  import (
     4  	"math/rand"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/artisanhe/tools/catgo/cat-go/cat"
     9  )
    10  
    11  const (
    12  	TestType = "Connection"
    13  )
    14  
    15  func Test_A(t *testing.T) {
    16  
    17  	(&Catgo{
    18  		Domain:      "xx.test",
    19  		Debug:       true,
    20  		HttpServers: []string{"test.dubhe.chinawayltd.com:2280"},
    21  	}).Init()
    22  
    23  	case1()
    24  	time.Sleep(time.Second)
    25  
    26  }
    27  
    28  func case1() {
    29  
    30  	for i := 0; i < 100; i++ {
    31  		cat.LogEvent("XConnection", "event-000", cat.FAIL)
    32  	}
    33  
    34  	t := cat.NewTransaction("Connection", "mammmo")
    35  	defer t.Complete()
    36  
    37  	if rand.Int31n(100) == 0 {
    38  		t.SetStatus(cat.FAIL)
    39  	}
    40  
    41  	t.AddData("foo", "bar")
    42  
    43  	t.NewEvent(TestType, "event-1")
    44  	t.Complete()
    45  
    46  	if rand.Int31n(100) == 0 {
    47  		t.LogEvent(TestType, "event-2", cat.FAIL)
    48  	} else {
    49  		t.LogEvent(TestType, "event-2")
    50  	}
    51  	t.LogEvent(TestType, "event-3", cat.SUCCESS, "k=v")
    52  
    53  	t.SetDurationStart(time.Now().Add(-5 * time.Second))
    54  	t.SetTime(time.Now().Add(-5 * time.Second))
    55  	t.SetDuration(time.Millisecond * 500)
    56  
    57  	time.Sleep(5 * time.Second)
    58  	cat.Shutdown()
    59  }