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


Golang testing.Fatalf函数代码示例

本文整理汇总了Golang中testing.Fatalf函数的典型用法代码示例。如果您正苦于以下问题:Golang Fatalf函数的具体用法?Golang Fatalf怎么用?Golang Fatalf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: TestName

func TestName(t *testing.T) {
	debug = testing.Verbose()
	d := zx.Dir{
		"path":  "/a/b",
		"name":  "b",
		"type":  "d",
		"mode":  "0755",
		"spath": "/a/b",
		"tpath": "/tmp/lfs_test",
		"proto": "lfs",
	}
	preds := []string{
		`name=b`,
		`! name=b`,
		`name!=b`,
	}
	matches := []bool{true, false, false}
	prunes := []bool{false, true, true}
	for i, pr := range preds {
		p, err := New(pr)
		if err != nil {
			t.Fatalf("parse %s", err)
		}
		t.Logf("eval %s\n", p.DebugString())
		m, prune, err := p.EvalAt(d, 0)
		t.Logf("match %v prune %v sts %v", m, prune, err)
		if err != nil || m != matches[i] || prune != prunes[i] {
			t.Logf("wrong result %v %v %v", err, m, prune)
			t.Fail()
		}
	}
}
开发者ID:Christopheraburns,项目名称:clive,代码行数:32,代码来源:pred_test.go

示例2: TestUnbackslash

func TestUnbackslash(t *testing.T) {
	for _, test := range []struct {
		isString bool
		in       string
		out      string
	}{
		{false, "", ""},
		{true, "", ""},
		// from CSS2 4.1.3 examples:
		{true, "\\26 B", "&B"},
		{true, "\\000026B", "&B"},
		{true, "\\26G", "&G"},
		{true, "\\2aG", "*G"},
		{true, "\\2AG", "*G"},
		{true, "\\2fG", "/G"},
		{true, "\\2FG", "/G"},
		// standard does not appear to require an even number of digits
		{true, "\\026 B", "&B"},
		{true, "\\026  B", "& B"},
		{true, "\\026", "&"},
		{true, "\\", "\\"},
		{true, "\\{", "{"},

		// Check the special string handling
		{true, "a\\\nb", "ab"},
		{true, "a\\\r\nb", "ab"},
	} {
		result := unbackslash(test.in, test.isString)
		if result != test.out {
			t.Fatalf("Error in TestUnbackslash. In: %q\nOut: %q\nExpected: %q",
				test.in, result, test.out)
		}
	}
}
开发者ID:thejerf,项目名称:css,代码行数:34,代码来源:scanner_test.go

示例3: TestSimple

func TestSimple(t *testing.T) {
	value := 1
	expected := 2
	if value != expected {
		t.Fatalf("Expected %v, but %d:", value, expected)
	}
}
开发者ID:potix2,项目名称:sonictemplate-vim,代码行数:7,代码来源:base-test.go

示例4: TestLoadFile

func TestLoadFile(t *testing.T){
	fp := "path-to-file"

	h := hive.HiveConfig(...)
	e := hdc.LoadFile(h, fp, "table", true)
	fatalCheck(t, "LoadFile", e)

	q := "select count(*) recordCount from table"
	var ms []toolkit.M
	e = h.Populate(q, &ms)
	fatalCheck(t, "Populate", e)

	if ms[0].GetInt("recordCount", 0)==0 {
		t.Fatalf("No data imported")
	}
}
开发者ID:eaciit,项目名称:hdc,代码行数:16,代码来源:loader_test.go

示例5: TestCliveOutChan

func TestCliveOutChan(t *testing.T) {
	debug = testing.Verbose()
	out2 := make(chan face{})
	adj := func(c *cmd.Ctx) {
		c.ForkEnv()
		c.ForkNS()
		c.ForkDot()
		c.SetOut("out2", out2)
	}
	c, err := CtxCmd(adj, "eco", "-o", "out2", "-m", "a", "b", "c")
	if err != nil {
		t.Fatalf("sts %v", err)
	}
	out := []string{}
	for x := range ch.Merge(c.Out, c.Err, out2) {
		switch x := x.(type) {
		case []byte:
			printf("-> [%s]\n", x)
			out = append(out, string(x))
		default:
			t.Fatalf("got type %T", x)
		}
	}
	err = c.Wait()
	printf("sts %v\n", err)
	if err != nil {
		t.Fatalf("did fail")
	}
}
开发者ID:fjballest,项目名称:clive,代码行数:29,代码来源:run_test.go

示例6: TestLf

func TestLf(t *testing.T) {
	app.New()	// prevent app.Fatal from calling dbg.Fatal
	app.Debug = testing.Verbose()
	for i := range tests {
		lt := tests[i]
		dprintf("run %v\n", lt.args)
		out := make(chan interface{})
		go func() {
			c := app.New()
			c.Args = lt.args
			defer app.Exiting()
			app.DupIO()
			app.SetIO(out, 1)
			app.Cd("/zx/sys/src/clive")
			Run()
		}()
		outs := []string{}
		for x := range out {
			d, ok := x.(zx.Dir)
			if !ok {
				dprintf("got %T %v\n", x, x)
				t.Fatalf("not a dir")
			}
			dprintf("got %T %s\n", d, d["upath"])
			outs = append(outs, d["upath"])
		}
		err := cerror(out)
		dprintf("got sts %v\n", err)
		if lt.fails && err == nil {
			t.Fatalf("didn't fail")
		}
		if !lt.fails && err != nil {
			t.Fatalf("failed: %s", err)
		}
		if lt.out != nil && strings.Join(lt.out, " ") != strings.Join(outs, " ") {
			t.Fatalf("bad output %#v", outs)
		}
		if lt.out == nil {
			dprintf("out: %#v\n", outs)
		}
	}
}
开发者ID:Christopheraburns,项目名称:clive,代码行数:42,代码来源:lf_test.go

示例7: TestCliveIn2Chan

func TestCliveIn2Chan(t *testing.T) {
	debug = testing.Verbose()
	in := make(chan face{}, 3)
	adj := func(c *cmd.Ctx) {
		c.ForkEnv()
		c.ForkNS()
		c.ForkDot()
		c.SetIn("in2", in)
	}
	c, err := CtxCmd(adj, "eco", "-i", "in2", "-m", "a", "b", "c")
	if err != nil {
		t.Fatalf("sts %v", err)
	}
	for _, m := range []string{"x", "y", "z"} {
		in <- []byte(m)
	}
	close(in)
	out := []string{}
	for x := range ch.Merge(c.Out, c.Err) {
		switch x := x.(type) {
		case []byte:
			printf("-> [%s]\n", x)
			out = append(out, string(x))
		default:
			t.Fatalf("got type %T", x)
		}
	}
	err = c.Wait()
	printf("sts %v\n", err)
	if err != nil {
		t.Fatalf("did fail")
	}
	if strings.Join(out, "|") != "a|b|c|x|y|z" {
		t.Fatalf("bad output")
	}
}
开发者ID:fjballest,项目名称:clive,代码行数:36,代码来源:run_test.go

示例8: TestClientTimeout

func TestClientTimeout(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	topicName := "test_client_timeout_v2" + strconv.Itoa(int(time.Now().Unix()))

	options := NewNsqdOptions()
	options.clientTimeout = 50 * time.Millisecond
	tcpAddr, _ := mustStartNSQd(options)
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	identify(t, conn)
	sub(t, conn, topicName, "ch")

	time.Sleep(50 * time.Millisecond)

	// depending on timing there may be 1 or 2 hearbeats sent
	// just read until we get an error
	timer := time.After(100 * time.Millisecond)
	for {
		select {
		case <-timer:
			t.Fatalf("test timed out")
		default:
			_, err := nsq.ReadResponse(conn)
			if err != nil {
				goto done
			}
		}
	}
done:
}

func TestClientHeartbeat(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	topicName := "test_hb_v2" + strconv.Itoa(int(time.Now().Unix()))

	options := NewNsqdOptions()
	options.clientTimeout = 100 * time.Millisecond
	tcpAddr, _ := mustStartNSQd(options)
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	identify(t, conn)
	sub(t, conn, topicName, "ch")

	err = nsq.Ready(1).Write(conn)
	assert.Equal(t, err, nil)

	resp, _ := nsq.ReadResponse(conn)
	_, data, _ := nsq.UnpackResponse(resp)
	assert.Equal(t, data, []byte("_heartbeat_"))

	time.Sleep(10 * time.Millisecond)

	err = nsq.Nop().Write(conn)
	assert.Equal(t, err, nil)

	// wait long enough that would have timed out (had we not sent the above cmd)
	time.Sleep(50 * time.Millisecond)

	err = nsq.Nop().Write(conn)
	assert.Equal(t, err, nil)
}

func TestClientHeartbeatDisableSUB(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	topicName := "test_hb_v2" + strconv.Itoa(int(time.Now().Unix()))

	options := NewNsqdOptions()
	options.clientTimeout = 200 * time.Millisecond
	tcpAddr, _ := mustStartNSQd(options)
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	identifyHeartbeatInterval(t, conn, -1, nsq.FrameTypeResponse, "OK")
	subFail(t, conn, topicName, "ch")
}

func TestClientHeartbeatDisable(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	options := NewNsqdOptions()
	options.clientTimeout = 100 * time.Millisecond
	tcpAddr, _ := mustStartNSQd(options)
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
//.........这里部分代码省略.........
开发者ID:kiloboot,项目名称:nsq,代码行数:101,代码来源:protocol_v2_test.go

示例9: TestNS

func TestNS(t *testing.T) {
	ns := mkns(t, testing.Verbose())
	defer fstest.RmTree(t, tdir)
	d2 := zx.Dir{"path": "x", "name": "x", "proto": "p2"}
	err := <-ns.Mount("d", d2, After)
	if err == nil {
		t.Fatalf("mount: could mount")
	}
	err = <-ns.Unmount("/d", d2)
	if err != nil {
		t.Fatalf("unmount dir: %s", err)
	}
	printf("ns is `%s`\n", ns)

	s := ns.String()
	ns2, err := Parse(s)
	if err != nil {
		t.Fatalf("parse: %s", err)
	}
	printf("ns2 is `%s`\n", ns2)
	if ns2.String() != s {
		t.Fatalf("parsed ns differs")
	}

	outs := `path:"/" name:"/" type:"d" mode:"0755" proto:"lfs" spath:"/" tpath:"/tmp/lfs_test"
path:"/a/b" name:"b" type:"d" mode:"0755" proto:"lfs" spath:"/" tpath:"/tmp/lfs_test"
path:"/d" name:"d" type:"p" mode:"0644" proto:"p1"
path:"/d" name:"d" type:"p" mode:"0644" proto:"p2"
path:"/d" name:"d" type:"p" mode:"0644" proto:"p2"
`
	if s != outs {
		t.Fatalf("bad ns contents")
	}
	err = <-ns.Unmount("/a/b", nil)
	if err != nil {
		t.Fatalf("unmount dir: %s", err)
	}
	printf("ns is `%s`\n", ns)
}
开发者ID:Christopheraburns,项目名称:clive,代码行数:39,代码来源:ns_test.go

示例10: TestResolve

func TestResolve(t *testing.T) {
	ns := mkns(t, false)
	defer fstest.RmTree(t, tdir)
	ns.Debug = testing.Verbose()
	ns.DebugFind = testing.Verbose()

	for _, r := range resolves {
		_, dirs, paths, err := ns.Resolve(r.Path)
		printf("sts %v\n", err)
		if err!=nil && !r.Fails {
			t.Fatalf("failed with %v", err)
		}
		if err==nil && r.Fails {
			t.Fatal("didn't fail")
		}
		if len(dirs) != len(paths) {
			t.Fatal("wrong lengths")
		}
		printf("dirs:\n")
		for _, d := range dirs {
			delete(d, "Uid")
			delete(d, "Gid")
			delete(d, "Wuid")
			delete(d, "Sum")
			printf("\t`%s`,\n", d)
		}
		printf("paths:\n")
		for _, p := range paths {
			printf("\t`%s`,\n", p)
		}
		for i := 0; i<len(r.Dirs) && i<len(dirs); i++ {
			if r.Dirs[i] != dirs[i].String() {
				t.Fatalf("bad result [%d]\n\tgot %s\n\twant %s\n",
					i, dirs[i], r.Dirs[i])
			}
		}
		if r.Dirs != nil {
			if len(dirs) > len(r.Dirs) {
				t.Fatalf("unexpected %s", dirs[len(r.Dirs)])
			}
			if len(dirs) < len(r.Dirs) {
				t.Fatalf("did expect %s", r.Dirs[len(dirs)])
			}
		}
		for i := 0; i<len(r.Paths) && i<len(paths); i++ {
			if r.Paths[i] != paths[i] {
				t.Fatalf("bad result [%d]\n\tgot %s\n\twant %s\n",
					i, paths[i], r.Paths[i])
			}
		}
		if r.Paths != nil {
			if len(paths) > len(r.Paths) {
				t.Fatalf("unexpected %s", paths[len(r.Paths)])
			}
			if len(paths) < len(r.Paths) {
				t.Fatalf("did expect %s", r.Paths[len(paths)])
			}
		}
	}
}
开发者ID:Christopheraburns,项目名称:clive,代码行数:60,代码来源:ns_test.go

示例11: _

func _(t *testing.T) {
	fmt.Printf(<warning descr="Got 1 placeholder(s) for 2 arguments(s)">s</warning>, 1, 2)

	fmt.Printf(<warning descr="Value used for formatting text does not appear to be a string">s1</warning>, 1, 2)

	fmt.Printf(<warning descr="Value used for formatting text does not appear to be a string">s2</warning>, 1, 2)

	fmt.Errorf("%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d",
		1, 2, 3, 4, 5, 6, 7, 8, 9,
	)
	fmt.Fprintf(nil, "%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d",
		1, 2, 3, 4, 5, 6, 7, 8, 9,
	)
	fmt.Fscanf(nil, "%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d",
		1, 2, 3, 4, 5, 6, 7, 8, 9,
	)
	fmt.Printf("%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d",
		1, 2, 3, 4, 5, 6, 7, 8, 9,
	)
	fmt.Scanf("%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d",
		1, 2, 3, 4, 5, 6, 7, 8, 9,
	)
	fmt.Sprintf("%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d",
		1, 2, 3, 4, 5, 6, 7, 8, 9,
	)
	fmt.Sscanf(nil, "%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d",
		1, 2, 3, 4, 5, 6, 7, 8, 9,
	)
	log.Fatalf("%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d",
		1, 2, 3, 4, 5, 6, 7, 8, 9,
	)
	log.Panicf("%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d",
		1, 2, 3, 4, 5, 6, 7, 8, 9,
	)
	log.Printf("%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d",
		1, 2, 3, 4, 5, 6, 7, 8, 9,
	)

	fmt.Printf("eq (as-is): %.3f%% score: %v offset: %v descr: [%v]\n", 3.14, 1, 1, "descr")

	fmt.Printf("a: %+v", 1)

	fmt.Printf("%-4d", 999)

	fmt.Printf("a: %%%+v", 1)

	fmt.Printf(<warning descr="Got 0 placeholder(s) for 1 arguments(s)">"a: %%%%+v"</warning>, 1)

	fmt.Printf("#%02X%02X%02X", 1, 2, 3)

	fmt.Printf(<warning descr="Got 3 placeholder(s) for 4 arguments(s)">"#%02X%02X%02X"</warning>, 1, 2, 3, 4)

	myFormatVar := "%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d"
	log.Printf(myFormatVar, 1, 2, 3, 4, 5, 6, 7, 8, 9)

	myWrongFormatVar := "%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d"
	log.Printf(<warning descr="Got 9 placeholder(s) for 8 arguments(s)">myWrongFormatVar</warning>, 1, 2, 3, 4, 5, 6, 7, 8)

	log.Printf(myFormatConst, 1, 2, 3, 4, 5, 6, 7, 8, 9)
	t.Errorf(myFormatConst, 1, 2, 3, 4, 5, 6, 7, 8, 9)
	t.Fatalf(myFormatConst, 1, 2, 3, 4, 5, 6, 7, 8, 9)
	t.Logf(myFormatConst, 1, 2, 3, 4, 5, 6, 7, 8, 9)
	t.Skipf(myFormatConst, 1, 2, 3, 4, 5, 6, 7, 8, 9)

	log.Printf(<warning descr="Got 9 placeholder(s) for 8 arguments(s)">myWrongFormatConst</warning>, 1, 2, 3, 4, 5, 6, 7, 8)
	t.Errorf(<warning descr="Got 9 placeholder(s) for 8 arguments(s)">myWrongFormatConst</warning>, 1, 2, 3, 4, 5, 6, 7, 8)
	t.Fatalf(<warning descr="Got 9 placeholder(s) for 8 arguments(s)">myWrongFormatConst</warning>, 1, 2, 3, 4, 5, 6, 7, 8)
	t.Logf(<warning descr="Got 9 placeholder(s) for 8 arguments(s)">myWrongFormatConst</warning>, 1, 2, 3, 4, 5, 6, 7, 8)
	t.Skipf(<warning descr="Got 9 placeholder(s) for 8 arguments(s)">myWrongFormatConst</warning>, 1, 2, 3, 4, 5, 6, 7, 8)

	printf("%d", 1)
	printf("%[2]d %[1]d", 1, 2)
	printf("%[2]d %[1]d %d", 1, 2)
	printf("%[2]d %[1]d %[2]d", 1, 2)
	printf("%d")

	myNonFormatFunc := func () int {
		return 1
	}
	log.Printf(<warning descr="Value used for formatting text does not appear to be a string">myNonFormatFunc()</warning>, 1, 2, 3, 4, 5, 6, 7, 8, 9)

	log.Printf(<warning descr="Got 9 placeholder(s) for 8 arguments(s)">"%d %d %#[1]x %#x %2.f %d %2.2f %.f %.3f %[9]*.[2]*[3]f %d %f %#[1]x %#x %[2]d %v % d"</warning>,
		1, 2, 3, 4, 5, 6, 7, 8,
	)
	fmt.Sprintf(<warning descr="Got 1 placeholder(s) for 0 arguments(s)">"%d"</warning>)

	log.Printf(<warning descr="Got 7 placeholder(s) for 13 arguments(s)">"%d %d %#[1]x %#x %f %2.f %2.2f %.f %.3f %[3]*.[2]*[1]f %d %d %#[1]x %#x %*[2]d %v % d"</warning>,
		1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
	)
	fmt.Sprintf(<warning descr="Got 1 placeholder(s) for 2 arguments(s)">"%d"</warning>, 1, 2)

	fmt.Print(<warning descr="Possible formatting directive in '\"%[2]*.[1]*[3]d\"'">"%[2]*.[1]*[3]d"</warning>, 2, 3, myNonFormatFunc)
	fmt.Print(<warning descr="Possible formatting directive in '\"%[2]*.[1]*[3]d\"'">"%[2]*.[1]*[3]d"</warning>, 2, 3, printf)

	fmt.Println("demo<warning descr="Function already ends with new line">\n</warning>", 2, 3, <warning descr="Argument 'myNonFormatFunc' is not a function call">myNonFormatFunc</warning>)
	fmt.Println("demo<warning descr="Function already ends with new line">\n</warning>", 2, 3, <warning descr="Argument 'printf' is not a function call">printf</warning>)

	fmt.Print("demo\n", 2, 3, <warning descr="Argument 'myNonFormatFunc' is not a function call">myNonFormatFunc</warning>)
	fmt.Print("demo\n", 2, 3, <warning descr="Argument 'printf' is not a function call">printf</warning>)

//.........这里部分代码省略.........
开发者ID:sjamesr,项目名称:go-lang-idea-plugin,代码行数:101,代码来源:placeholderCount.go

示例12: TestClientTimeout

func TestClientTimeout(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	topicName := "test_client_timeout_v2" + strconv.Itoa(int(time.Now().Unix()))

	options := NewNsqdOptions()
	options.clientTimeout = 50 * time.Millisecond
	tcpAddr, _ := mustStartNSQd(options)
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	err = nsq.SendCommand(conn, nsq.Subscribe(topicName, "ch", "TestClientTimeoutV2", "TestClientTimeoutV2"))
	assert.Equal(t, err, nil)

	time.Sleep(50 * time.Millisecond)

	// depending on timing there may be 1 or 2 hearbeats sent
	// just read until we get an error
	timer := time.After(100 * time.Millisecond)
	for {
		select {
		case <-timer:
			t.Fatalf("test timed out")
		default:
			_, err := nsq.ReadResponse(conn)
			if err != nil {
				goto done
			}
		}
	}
done:
}

func TestClientHeartbeat(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	topicName := "test_hb_v2" + strconv.Itoa(int(time.Now().Unix()))

	options := NewNsqdOptions()
	options.clientTimeout = 100 * time.Millisecond
	tcpAddr, _ := mustStartNSQd(options)
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	err = nsq.SendCommand(conn, nsq.Subscribe(topicName, "ch", "TestClientHeartbeatV2", "TestClientHeartbeatV2"))
	assert.Equal(t, err, nil)

	err = nsq.SendCommand(conn, nsq.Ready(1))
	assert.Equal(t, err, nil)

	resp, _ := nsq.ReadResponse(conn)
	_, data, _ := nsq.UnpackResponse(resp)
	assert.Equal(t, data, []byte("_heartbeat_"))

	time.Sleep(10 * time.Millisecond)

	err = nsq.SendCommand(conn, nsq.Nop())
	assert.Equal(t, err, nil)

	// wait long enough that would have timed out (had we not sent the above cmd)
	time.Sleep(50 * time.Millisecond)

	err = nsq.SendCommand(conn, nsq.Nop())
	assert.Equal(t, err, nil)
}

func TestPausing(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	topicName := "test_pause_v2" + strconv.Itoa(int(time.Now().Unix()))

	tcpAddr, _ := mustStartNSQd(NewNsqdOptions())
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	err = nsq.SendCommand(conn, nsq.Subscribe(topicName, "ch", "TestPausing", "TestPausing"))
	assert.Equal(t, err, nil)

	err = nsq.SendCommand(conn, nsq.Ready(1))
	assert.Equal(t, err, nil)

	topic := nsqd.GetTopic(topicName)
	msg := nsq.NewMessage(<-nsqd.idChan, []byte("test body"))
	channel := topic.GetChannel("ch")
	topic.PutMessage(msg)

	// receive the first message via the client, finish it, and send new RDY
	resp, _ := nsq.ReadResponse(conn)
	_, data, _ := nsq.UnpackResponse(resp)
	msg, err = nsq.DecodeMessage(data)
	assert.Equal(t, msg.Body, []byte("test body"))
//.........这里部分代码省略.........
开发者ID:perryhau,项目名称:nsq,代码行数:101,代码来源:protocol_v2_test.go

示例13: TestClientTimeout

func TestClientTimeout(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	topicName := "test_client_timeout_v2" + strconv.Itoa(int(time.Now().Unix()))

	options := NewNsqdOptions()
	options.clientTimeout = 50 * time.Millisecond
	tcpAddr, _ := mustStartNSQd(options)
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	err = nsq.Subscribe(topicName, "ch", "TestClientTimeoutV2", "TestClientTimeoutV2").Write(conn)
	assert.Equal(t, err, nil)

	time.Sleep(50 * time.Millisecond)

	// depending on timing there may be 1 or 2 hearbeats sent
	// just read until we get an error
	timer := time.After(100 * time.Millisecond)
	for {
		select {
		case <-timer:
			t.Fatalf("test timed out")
		default:
			_, err := nsq.ReadResponse(conn)
			if err != nil {
				goto done
			}
		}
	}
done:
}

func TestClientHeartbeat(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	topicName := "test_hb_v2" + strconv.Itoa(int(time.Now().Unix()))

	options := NewNsqdOptions()
	options.clientTimeout = 100 * time.Millisecond
	tcpAddr, _ := mustStartNSQd(options)
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	err = nsq.Subscribe(topicName, "ch", "TestClientHeartbeatV2", "TestClientHeartbeatV2").Write(conn)
	assert.Equal(t, err, nil)

	err = nsq.Ready(1).Write(conn)
	assert.Equal(t, err, nil)

	resp, _ := nsq.ReadResponse(conn)
	_, data, _ := nsq.UnpackResponse(resp)
	assert.Equal(t, data, []byte("_heartbeat_"))

	time.Sleep(10 * time.Millisecond)

	err = nsq.Nop().Write(conn)
	assert.Equal(t, err, nil)

	// wait long enough that would have timed out (had we not sent the above cmd)
	time.Sleep(50 * time.Millisecond)

	err = nsq.Nop().Write(conn)
	assert.Equal(t, err, nil)
}

func TestPausing(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	topicName := "test_pause_v2" + strconv.Itoa(int(time.Now().Unix()))

	tcpAddr, _ := mustStartNSQd(NewNsqdOptions())
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	err = nsq.Subscribe(topicName, "ch", "TestPausing", "TestPausing").Write(conn)
	assert.Equal(t, err, nil)

	err = nsq.Ready(1).Write(conn)
	assert.Equal(t, err, nil)

	topic := nsqd.GetTopic(topicName)
	msg := nsq.NewMessage(<-nsqd.idChan, []byte("test body"))
	channel := topic.GetChannel("ch")
	topic.PutMessage(msg)

	// receive the first message via the client, finish it, and send new RDY
	resp, _ := nsq.ReadResponse(conn)
	_, data, _ := nsq.UnpackResponse(resp)
	msg, err = nsq.DecodeMessage(data)
	assert.Equal(t, msg.Body, []byte("test body"))
//.........这里部分代码省略.........
开发者ID:polaris1119,项目名称:nsq,代码行数:101,代码来源:protocol_v2_test.go

示例14: TestMatchChar


//.........这里部分代码省略.........

func nullString(v interface{}) sql.NullString {
	if v == nil {
		return sql.NullString{Valid: false}
	}
	return sql.NullString{String: v.(string), Valid: true}
}

var fullTests = []matchTest{
	{in: "NULL", out: []string{}},
	{in: "\"a\" => \"b\"",
		out:    []string{"\"a\" => \"b\""},
		hstore: Hstore{"a": nullString("b")}},
	{in: "\"a\"   =>   NULL",
		out:    []string{"\"a\"   =>   NULL"},
		hstore: Hstore{"a": sql.NullString{Valid: false}}},
	{in: "\"id\"=>\"44\", \"foo\"=>\"dfs => somf\", \"name\"=>\"Wash\\\"ington\", \"null\"=>NULL, \"quote\"=>\"\\\"fs ' \"",
		out: []string{
			"\"id\"=>\"44\"",
			"\"foo\"=>\"dfs => somf\"",
			"\"name\"=>\"Wash\\\"ington\"",
			"\"null\"=>NULL",
			"\"quote\"=>\"\\\"fs ' \"",
		},
		hstore: Hstore{
			"id":    nullString("44"),
			"foo":   nullString("dfs => somf"),
			"name":  nullString("Wash\\\"ington"),
			"null":  nullString(nil),
			"quote": nullString("\\\"fs ' "),
		},
	},
}

func TestParseHstore(t *testing.T) {
	for _, mt := range fullTests {
		matches := pairExp.FindAllStringIndex(mt.in, -1)
		checkMatch(t, matches, mt)

		hs := make(Hstore)
		err := parseHstore(mt.in, &hs)
		if err != nil {
			t.Errorf("Error parsing %q: %v", mt.in, err)
		}
		checkHstore(t, mt.hstore, hs)

	}
}

func TestValueAndScan(t *testing.T) {
	for _, mt := range fullTests {
		valued, err := mt.hstore.Value()
		if err != nil {
			t.Fatalf("Value failed: %q", err)
		}
		var scanned Hstore
		(&scanned).Scan([]byte(valued.(string)))
		checkHstore(t, mt.hstore, scanned)
	}
}

func TestDBRoundTrip(t *testing.T) {
	db := openTestConn(t)
	defer db.Close()

	_, err := db.Exec("CREATE EXTENSION IF NOT EXISTS hstore")
	fatal(t, err)
	_, err = db.Exec("CREATE TEMP TABLE temp (id serial, data hstore)")
	fatal(t, err)

	for _, mt := range fullTests {
		v, err := mt.hstore.Value()
		check(t, err)
		r, err := db.Exec("INSERT INTO temp (data) VALUES ($1)", v)
		check(t, err)

		if n, _ := r.RowsAffected(); n != 1 {
			t.Fatalf("expected 1 row affected, not %d", n)
		}
	}

	rows, err := db.Query("SELECT data FROM temp ORDER BY id ASC")
	check(t, err)

	for _, mt := range fullTests {
		if !rows.Next() {
			t.Errorf("Ran out of rows!")
		}
		var data Hstore
		err = rows.Scan(&data)
		check(t, err)
		t.Logf("%+v", data)
		checkHstore(t, mt.hstore, data)
	}

	if rows.Next() {
		t.Errorf("Too many rows!")
	}

}
开发者ID:davars,项目名称:pq,代码行数:101,代码来源:hstore_test.go

示例15: TestClientTimeout

func TestClientTimeout(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	topicName := "test_client_timeout_v2" + strconv.Itoa(int(time.Now().Unix()))

	options := NewNsqdOptions()
	options.clientTimeout = 50 * time.Millisecond
	tcpAddr, _ := mustStartNSQd(options)
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	err = nsq.SendCommand(conn, nsq.Subscribe(topicName, "ch", "TestClientTimeoutV2", "TestClientTimeoutV2"))
	assert.Equal(t, err, nil)

	time.Sleep(50 * time.Millisecond)

	// depending on timing there may be 1 or 2 hearbeats sent
	// just read until we get an error
	timer := time.After(100 * time.Millisecond)
	for {
		select {
		case <-timer:
			t.Fatalf("test timed out")
		default:
			_, err := nsq.ReadResponse(conn)
			if err != nil {
				goto done
			}
		}
	}
done:
}

func TestClientHeartbeat(t *testing.T) {
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)

	topicName := "test_hb_v2" + strconv.Itoa(int(time.Now().Unix()))

	options := NewNsqdOptions()
	options.clientTimeout = 100 * time.Millisecond
	tcpAddr, _ := mustStartNSQd(options)
	defer nsqd.Exit()

	conn, err := mustConnectNSQd(tcpAddr)
	assert.Equal(t, err, nil)

	err = nsq.SendCommand(conn, nsq.Subscribe(topicName, "ch", "TestClientHeartbeatV2", "TestClientHeartbeatV2"))
	assert.Equal(t, err, nil)

	err = nsq.SendCommand(conn, nsq.Ready(1))
	assert.Equal(t, err, nil)

	resp, _ := nsq.ReadResponse(conn)
	_, data, _ := nsq.UnpackResponse(resp)
	assert.Equal(t, data, []byte("_heartbeat_"))

	time.Sleep(10 * time.Millisecond)

	err = nsq.SendCommand(conn, nsq.Nop())
	assert.Equal(t, err, nil)

	// wait long enough that would have timed out (had we not sent the above cmd)
	time.Sleep(50 * time.Millisecond)

	err = nsq.SendCommand(conn, nsq.Nop())
	assert.Equal(t, err, nil)
}

func BenchmarkProtocolV2Command(b *testing.B) {
	b.StopTimer()
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)
	p := &ProtocolV2{}
	c := NewClientV2(nil)
	params := [][]byte{[]byte("SUB"), []byte("test"), []byte("ch")}
	b.StartTimer()

	for i := 0; i < b.N; i++ {
		p.Exec(c, params)
	}
}

func BenchmarkProtocolV2Data(b *testing.B) {
	b.StopTimer()
	log.SetOutput(ioutil.Discard)
	defer log.SetOutput(os.Stdout)
	p := &ProtocolV2{}
	var cb bytes.Buffer
	rw := bufio.NewReadWriter(bufio.NewReader(&cb), bufio.NewWriter(ioutil.Discard))
	conn := util.MockConn{rw}
	c := NewClientV2(conn)
	var buf bytes.Buffer
	msg := nsq.NewMessage([]byte("0123456789abcdef"), []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
	b.StartTimer()

	for i := 0; i < b.N; i += 1 {
//.........这里部分代码省略.........
开发者ID:weixu8,项目名称:nsq,代码行数:101,代码来源:protocol_v2_test.go


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