当前位置: 首页>>代码示例>>Golang>>正文


Golang T.Critical方法代码示例

本文整理汇总了Golang中testing.T.Critical方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Critical方法的具体用法?Golang T.Critical怎么用?Golang T.Critical使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在testing.T的用法示例。


在下文中一共展示了T.Critical方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestThrottle

func TestThrottle(t *testing.T) {
	l, err := net.Listen("tcp", "")
	if err != nil {
		t.Critical("could not initialize listener: %v", err)
	}
	throttled := NewThrottledListener(l, 10, 3)
	go http.Serve(throttled, nil)

	start := time.Now()
	var wg sync.WaitGroup
	for i := 1; i <= 3; i++ {
		conn, err := net.Dial("tcp", l.Addr().String())
		if err != nil {
			t.Error(err)
		}
		wg.Add(1)
		go func() {
			defer wg.Done()
			defer conn.Close()
			if _, err = conn.Write([]byte("hello\n\n")); err != nil {
				t.Error(err)
			}
			b := make([]byte, 1000)
			if _, err = conn.Read(b); err != nil {
				t.Error(err)
			}
		}()
	}
	wg.Wait()
	diff := time.Now().Sub(start)
	if diff < 300*time.Millisecond {
		t.Error("want >= 300ms, got %v", diff)
	}
	l.Close()
}
开发者ID:dongzerun,项目名称:RationalDb,代码行数:35,代码来源:throttled_listener_test.go

示例2: TestPublished

func TestPublished(t *testing.T) {
	l, err := Listen("")
	if err != nil {
		t.Critical("could not initialize listener: %v", err)
	}
	go http.Serve(l, nil)

	for i := 1; i <= 3; i++ {
		resp, err := http.Get(fmt.Sprintf("http://%s/debug/vars", l.Addr().String()))
		if err != nil {
			t.Fatal(err)
		}
		val, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			t.Fatal(err)
		}
		http.DefaultTransport.(*http.Transport).CloseIdleConnections()
		vars := make(map[string]interface{})
		err = json.Unmarshal(val, &vars)
		if err != nil {
			t.Error(err)
		}
		if vars["ConnCount"].(float64) != 1 {
			t.Errorf("want 1, got %v", vars["connection-count"])
		}
		if vars["ConnAccepted"].(float64) != float64(i) {
			t.Errorf("want %d, got %v", i, vars["connection-count"])
		}
	}
	l.Close()
}
开发者ID:dongzerun,项目名称:RationalDb,代码行数:31,代码来源:counting_listener_test.go

示例3: testLaunch

func testLaunch(t *testing.T) {
	var err error
	l, err := net.Listen("tcp", "")
	if err != nil {
		t.Critical("could not initialize listener: %v", err)
	}
	hostport := l.Addr().String()
	l.Close()
	_, port, err := net.SplitHostPort(hostport)
	if err != nil {
		t.Fatal(err)
	}

	cmd1 := launchServer(t, port, 1)
	defer cmd1.Process.Kill()
	testPid(t, port, cmd1.Process.Pid)

	cmd2 := launchServer(t, port, 2)
	defer cmd2.Process.Kill()
	err = cmd1.Wait()
	if err != nil {
		t.Error(err)
	}
	testPid(t, port, cmd2.Process.Pid)

	err = syscall.Kill(cmd2.Process.Pid, syscall.SIGTERM)
	if err != nil {
		t.Error(err)
	}
	err = cmd2.Wait()
	if err != nil {
		t.Error(err)
	}
}
开发者ID:dongzerun,项目名称:RationalDb,代码行数:34,代码来源:proc_test.go

示例4: TestCondSignalGenerations

func TestCondSignalGenerations(t *testing.T) {
	var m sync.Mutex
	c := NewCond(&m)
	n := 100
	running := make(chan bool, n)
	awake := make(chan int, n)
	for i := 0; i < n; i++ {
		go func(i int) {
			m.Lock()
			running <- true
			c.Wait()
			awake <- i
			m.Unlock()
		}(i)
		if i > 0 {
			a := <-awake
			if a != i-1 {
				t.Critical("wrong goroutine woke up: want %d, got %d", i-1, a)
			}
		}
		<-running
		m.Lock()
		c.Signal()
		m.Unlock()
	}
}
开发者ID:dongzerun,项目名称:RationalDb,代码行数:26,代码来源:cond_test.go

示例5: testServer

func testServer(t *testing.T, want syscall.Signal) {
	l, err := Listen(os.Getenv("PORT"))
	if err != nil {
		t.Critical("could not initialize listener: %v", err)
	}
	go http.Serve(l, nil)
	got := Wait()
	l.Close()
	if want != got {
		t.Errorf("want %v, got %v", want, got)
	}
}
开发者ID:dongzerun,项目名称:RationalDb,代码行数:12,代码来源:proc_test.go

示例6: testPid

func testPid(t *testing.T, port string, want int) {
	var resp *http.Response
	var err error
	for i := 0; i < 20; i++ {
		resp, err = http.Get(fmt.Sprintf("http://localhost:%s%s", port, pidURL))
		if err != nil {
			if i == 19 {
				t.Fatal(err)
			}
			if strings.Contains(err.Error(), "connection refused") {
				time.Sleep(1000 * time.Millisecond)
				continue
			}
			t.Critical("unexpected error on port %v: %v", port, err)
		}
		break
	}
	num, err := ioutil.ReadAll(resp.Body)
	resp.Body.Close()
	if err != nil {
		t.Critical("could not read pid: %vd", err)
	}
	got, err := strconv.Atoi(string(num))
	if err != nil {
		t.Critical("could not read pid: %vd", err)
	}
	if want != got {
		t.Errorf("want %d, got %d", want, got)
	}
}
开发者ID:dongzerun,项目名称:RationalDb,代码行数:30,代码来源:proc_test.go

示例7: TestBalancerConfiguration

func TestBalancerConfiguration(t *testing.T) {
	configure := InitDldbConfiguration("")
	receiveBalancer := configure.BalancersConfiguration.GetBalancerConfiguration("engine")
	if receiveBalancer.InitRoutineNum != 500 {
		t.Critical("receive balancer read error, initroutineNum = %d, want %d", receiveBalancer.InitRoutineNum, 500)
	}
	if receiveBalancer.ManagerAutoDetect {
		t.Critical("receive balancer read error, ManagerAutoDetect is true, want false")
	}
	if configure.ServerConfiguration.Addr != "localhost" {
		t.Critical("server configuration init err!")
	}
}
开发者ID:dongzerun,项目名称:RationalDb,代码行数:13,代码来源:configuration_test.go

示例8: TestTypes

func TestTypes(t *testing.T) {
	in := make(map[string]interface{})
	in["bytes"] = []byte("bytes")
	in["float64"] = float64(64)
	in["string"] = "string"
	in["bool"] = true
	in["time"] = time.Unix(1136243045, 0)
	in["int32"] = int32(-0x80000000)
	in["int"] = int(-0x80000000)
	in["int64"] = int64(-0x8000000000000000)
	in["uint"] = uint(0xFFFFFFFF)
	in["uint32"] = uint32(0xFFFFFFFF)
	in["uint64"] = uint64(0xFFFFFFFFFFFFFFFF)
	in["slice"] = []interface{}{1, nil}
	in["nil"] = nil
	encoded := VerifyMarshal(t, in)

	out := make(map[string]interface{})
	err := Unmarshal(encoded, &out)
	if err != nil {
		t.Critical("unmarshal fail: %v\n", err)
	}

	if string(in["bytes"].([]byte)) != "bytes" {
		t.Error("bytes fail")
	}
	if out["float64"].(float64) != float64(64) {
		t.Error("float fail")
	}
	if string(out["string"].([]byte)) != "string" {
		t.Error("string fail")
	}
	if out["bool"].(bool) == false {
		t.Error("bool fail")
	}
	tm, ok := out["time"].(time.Time)
	if !ok {
		t.Error("time type failed")
	}
	if tm.Unix() != 1136243045 {
		t.Error("time failed")
	}
	if v := out["int32"].(int32); v != int32(-0x80000000) {
		t.Error("int32 fail: %v", v)
	}
	if v := out["int"].(int64); v != int64(-0x80000000) {
		t.Error("int fail: %v", v)
	}
	if v := out["int64"].(int64); v != int64(-0x8000000000000000) {
		t.Error("int64 fail: %v", v)
	}
	if v := out["uint"].(uint64); v != uint64(0xFFFFFFFF) {
		t.Error("uint fail: %v", v)
	}
	if v := out["uint32"].(uint64); v != uint64(0xFFFFFFFF) {
		t.Error("uint32 fail: %v", v)
	}
	if v := out["uint64"].(uint64); v != uint64(0xFFFFFFFFFFFFFFFF) {
		t.Error("uint64 fail: %v", v)
	}
	if v := out["slice"].([]interface{})[0].(int64); v != 1 {
		t.Error("slice fail: %v", v)
	}
	if v := out["slice"].([]interface{})[1]; v != nil {
		t.Error("slice fail: %v", v)
	}
	if nilval, ok := out["nil"]; !ok || nilval != nil {
		t.Error("nil fail")
	}
}
开发者ID:dongzerun,项目名称:RationalDb,代码行数:70,代码来源:bson_test.go

示例9: TestCustom

// TestCustom tests custom unmarshalling
func TestCustom(t *testing.T) {
	a := alltypes{
		Bytes:   []byte("bytes"),
		Float64: float64(64),
		String:  "string",
		Bool:    true,
		Time:    time.Unix(1136243045, 0),
		Int32:   int32(-0x80000000),
		Int:     int(-0x80000000),
		Int64:   int64(-0x8000000000000000),
		Uint64:  uint64(0xFFFFFFFFFFFFFFFF),
		Strings: []string{"a", "b"},
		Nil:     nil,
	}
	encoded := VerifyMarshal(t, a)
	var out alltypes
	err := Unmarshal(encoded, &out)
	if err != nil {
		t.Critical("unmarshal fail: %v\n", err)
	}
	if string(out.Bytes) != "bytes" {
		t.Error("bytes fail: %s", out.Bytes)
	}
	if out.Float64 != 64 {
		t.Error("float fail: %v", out.Float64)
	}
	if out.String != "string" {
		t.Error("string fail: %v", out.String)
	}
	if !out.Bool {
		t.Error("bool fail: %v", out.Bool)
	}
	if out.Time.Unix() != 1136243045 {
		t.Error("time fail: %v", out.Time)
	}
	if out.Int32 != -0x80000000 {
		t.Error("int32 fail: %v", out.Int32)
	}
	if out.Int != -0x80000000 {
		t.Error("int fail: %v", out.Int)
	}
	if out.Int64 != -0x8000000000000000 {
		t.Error("int64 fail: %v", out.Int64)
	}
	if out.Uint64 != 0xFFFFFFFFFFFFFFFF {
		t.Error("uint64 fail: %v", out.Uint64)
	}
	if out.Strings[0] != "a" || out.Strings[1] != "b" {
		t.Error("strings fail: %v", out.Strings)
	}

	b := alltypes{Bytes: []byte(""), Strings: []string{"a"}}
	encoded = VerifyMarshal(t, b)
	var outb alltypes
	err = Unmarshal(encoded, &outb)
	if err != nil {
		t.Critical("unmarshal fail: %v\n", err)
	}
	if outb.Bytes == nil || len(outb.Bytes) != 0 {
		t.Error("nil bytes fail: %s", outb.Bytes)
	}
}
开发者ID:dongzerun,项目名称:RationalDb,代码行数:63,代码来源:bson_test.go

示例10: TestServer

func TestServer(t *testing.T) {
	type addResp struct {
		Id     interface{} `json:"id"`
		Result Reply       `json:"result"`
		Error  interface{} `json:"error"`
	}

	cli, srv := net.Pipe()
	defer cli.Close()
	go ServeConn(srv)
	dec := json.NewDecoder(cli)

	// Send hand-coded requests to server, parse responses.
	for i := 0; i < 10; i++ {
		fmt.Fprintf(cli, `{"method": "Arith.Add", "id": "\u%04d", "params": [{"A": %d, "B": %d}]}`, i, i, i+1)
		var resp addResp
		err := dec.Decode(&resp)
		if err != nil {
			t.Critical("Decode: %s", err)
		}
		if resp.Error != nil {
			t.Critical("resp.Error: %s", resp.Error)
		}
		if resp.Id.(string) != string(i) {
			t.Critical("resp: bad id %q want %q", resp.Id.(string), string(i))
		}
		if resp.Result.C != 2*i+1 {
			t.Critical("resp: bad result: %d+%d=%d", i, i+1, resp.Result.C)
		}
	}

	fmt.Fprintf(cli, "{}\n")
	var resp addResp
	if err := dec.Decode(&resp); err != nil {
		t.Critical("Decode after empty: %s", err)
	}
	if resp.Error == nil {
		t.Critical("Expected error, got nil")
	}
}
开发者ID:dongzerun,项目名称:RationalDb,代码行数:40,代码来源:all_test.go


注:本文中的testing.T.Critical方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。