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


Golang testing.Short函数代码示例

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


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

示例1: TestRenewInstancesConcurrently

func TestRenewInstancesConcurrently(t *testing.T) {
	if testing.Short() {
		t.Skip()
	}

	if testing.Short() {
		t.SkipNow()
	}

	const numOfInstances = 10000
	const numOfIterations = 10
	const ttl = testMediumTTL

	conf := createNewConfig(ttl)
	catalog := newInMemoryCatalog(conf)

	var ids [numOfInstances]string
	for i := 0; i < numOfInstances; i++ {
		hostSuffix := strconv.Itoa(i)
		host := "192.168.0." + hostSuffix
		instance := newServiceInstance("Calc", host, 9080)
		id, _ := doRegister(catalog, instance)
		ids[i] = id
	}

	var wg sync.WaitGroup
	wg.Add(numOfInstances)

	done := make(chan struct{})
	for i := 0; i < numOfInstances; i++ {
		id := ids[i]
		go func() {
			defer wg.Done()
			for {
				select {
				case <-done:
					return
				default:
					{
						duration := randPercentOfDuration(0.25, 0.5, ttl)
						time.Sleep(duration)
						err := catalog.Renew(id)
						assert.NoError(t, err, "Renewal of instance %v failed: %v", id, err)

					}
				}
			}
		}()
	}

	time.Sleep(ttl * numOfIterations)

	close(done)
	wg.Wait()

	instances, err := catalog.List("Calc", protocolPredicate)
	assert.NoError(t, err)
	assert.Len(t, instances, numOfInstances, "Expected %v surviving instances, found %v", numOfInstances, len(instances))

}
开发者ID:charshy,项目名称:registry,代码行数:60,代码来源:in_memory_catalog_test.go

示例2: TestAfterTick

func TestAfterTick(t *testing.T) {
	const Count = 10
	Delta := 100 * time.Millisecond
	if testing.Short() {
		Delta = 10 * time.Millisecond
	}
	for _, ttype := range []bool{false, true} {
		setSandboxMode(ttype)
		t0 := Now()
		for i := 0; i < Count; i++ {
			c := After(Delta)
			if ttype {
				go Advance(t, Delta)
			}
			<-c
		}
		t1 := Now()
		d := t1.Sub(t0)
		target := Delta * Count
		if d < target*9/10 {
			t.Fatalf("%d ticks of %s too fast: want %s, got %s", Count, Delta, target, d)
		}
		if !testing.Short() && d > target*30/10 {
			t.Fatalf("%d ticks of %s too slow: want %s, got %s", Count, Delta, target, d)
		}
	}
}
开发者ID:CERN-Stage-3,项目名称:vitess,代码行数:27,代码来源:hourglass_test.go

示例3: TestS3Replica

func TestS3Replica(t *testing.T) {
	t.Parallel()
	t.Skip("This test is periodically failing to reach s3.")
	// Create a source repo:
	srcRepo := "repo_TestS3Replica_src"
	require.NoError(t, Init(srcRepo))

	// Create a file in the source repo:
	writeFile(t, fmt.Sprintf("%s/master/myfile1", srcRepo), "foo")
	if testing.Short() {
		writeLots(t, fmt.Sprintf("%s/master/big_file", srcRepo), 1)
	} else {
		writeLots(t, fmt.Sprintf("%s/master/big_file", srcRepo), 10)
	}

	// Create a commit in the source repo:
	require.NoError(t, Commit(srcRepo, "mycommit1", "master"))

	// Create another file in the source repo:
	writeFile(t, fmt.Sprintf("%s/master/myfile2", srcRepo), "bar")
	if testing.Short() {
		writeLots(t, fmt.Sprintf("%s/master/big_file", srcRepo), 1)
	} else {
		writeLots(t, fmt.Sprintf("%s/master/big_file", srcRepo), 10)
	}

	// Create a another commit in the source repo:
	require.NoError(t, Commit(srcRepo, "mycommit2", "master"))

	// Create a destination repo:
	dstRepo := "repo_TestS3Replica_dst"
	require.NoError(t, Init(dstRepo))

	// Verify that the commits "mycommit1" and "mycommit2" do exist in source:
	checkFile(t, fmt.Sprintf("%s/mycommit1/myfile1", srcRepo), "foo")
	checkFile(t, fmt.Sprintf("%s/mycommit2/myfile2", srcRepo), "bar")

	// Verify that the commits "mycommit1" and "mycommit2" do not exist in destination:
	checkNoExists(t, fmt.Sprintf("%s/mycommit1", dstRepo))
	checkNoExists(t, fmt.Sprintf("%s/mycommit2", dstRepo))

	// Run a Pull to push all commits to s3
	s3Replica := NewS3Replica(path.Join("pachyderm-test", uuid.NewV4().String()))
	err := Pull(srcRepo, "", s3Replica)
	require.NoError(t, err)

	// Pull commits from s3 to a new local replica
	err = s3Replica.Pull("", NewLocalReplica(dstRepo))
	require.NoError(t, err)

	// Verify that files from both commits are present:
	checkFile(t, fmt.Sprintf("%s/mycommit1/myfile1", dstRepo), "foo")
	checkFile(t, fmt.Sprintf("%s/mycommit2/myfile2", dstRepo), "bar")
	checkFile(t, fmt.Sprintf("%s/master/myfile1", dstRepo), "foo")
	checkFile(t, fmt.Sprintf("%s/master/myfile2", dstRepo), "bar")
}
开发者ID:plar,项目名称:pachyderm,代码行数:56,代码来源:btrfs_test.go

示例4: TestWriteError

// Test if errors from the underlying writer is passed upwards.
func TestWriteError(t *testing.T) {
	t.Parallel()
	buf := new(bytes.Buffer)
	n := 65536
	if !testing.Short() {
		n *= 4
	}
	for i := 0; i < n; i++ {
		fmt.Fprintf(buf, "asdasfasf%d%dfghfgujyut%dyutyu\n", i, i, i)
	}
	in := buf.Bytes()
	// We create our own buffer to control number of writes.
	copyBuffer := make([]byte, 128)
	for l := 0; l < 10; l++ {
		for fail := 1; fail <= 256; fail *= 2 {
			// Fail after 'fail' writes
			ew := &errorWriter{N: fail}
			w, err := NewWriter(ew, l)
			if err != nil {
				t.Fatalf("NewWriter: level %d: %v", l, err)
			}
			n, err := io.CopyBuffer(w, struct{ io.Reader }{bytes.NewBuffer(in)}, copyBuffer)
			if err == nil {
				t.Fatalf("Level %d: Expected an error, writer was %#v", l, ew)
			}
			n2, err := w.Write([]byte{1, 2, 2, 3, 4, 5})
			if n2 != 0 {
				t.Fatal("Level", l, "Expected 0 length write, got", n)
			}
			if err == nil {
				t.Fatal("Level", l, "Expected an error")
			}
			err = w.Flush()
			if err == nil {
				t.Fatal("Level", l, "Expected an error on flush")
			}
			err = w.Close()
			if err == nil {
				t.Fatal("Level", l, "Expected an error on close")
			}

			w.Reset(ioutil.Discard)
			n2, err = w.Write([]byte{1, 2, 3, 4, 5, 6})
			if err != nil {
				t.Fatal("Level", l, "Got unexpected error after reset:", err)
			}
			if n2 == 0 {
				t.Fatal("Level", l, "Got 0 length write, expected > 0")
			}
			if testing.Short() {
				return
			}
		}
	}
}
开发者ID:Harvey-OS,项目名称:go,代码行数:56,代码来源:writer_test.go

示例5: TestWriterReset

func TestWriterReset(t *testing.T) {
	t.Parallel()
	for level := 0; level <= 9; level++ {
		if testing.Short() && level > 1 {
			break
		}
		w, err := NewWriter(ioutil.Discard, level)
		if err != nil {
			t.Fatalf("NewWriter: %v", err)
		}
		buf := []byte("hello world")
		n := 1024
		if testing.Short() {
			n = 10
		}
		for i := 0; i < n; i++ {
			w.Write(buf)
		}
		w.Reset(ioutil.Discard)

		wref, err := NewWriter(ioutil.Discard, level)
		if err != nil {
			t.Fatalf("NewWriter: %v", err)
		}

		// DeepEqual doesn't compare functions.
		w.d.fill, wref.d.fill = nil, nil
		w.d.step, wref.d.step = nil, nil
		w.d.bulkHasher, wref.d.bulkHasher = nil, nil
		w.d.bestSpeed, wref.d.bestSpeed = nil, nil
		// hashMatch is always overwritten when used.
		copy(w.d.hashMatch[:], wref.d.hashMatch[:])
		if len(w.d.tokens) != 0 {
			t.Errorf("level %d Writer not reset after Reset. %d tokens were present", level, len(w.d.tokens))
		}
		// As long as the length is 0, we don't care about the content.
		w.d.tokens = wref.d.tokens

		// We don't care if there are values in the window, as long as it is at d.index is 0
		w.d.window = wref.d.window
		if !reflect.DeepEqual(w, wref) {
			t.Errorf("level %d Writer not reset after Reset", level)
		}
	}
	testResetOutput(t, func(w io.Writer) (*Writer, error) { return NewWriter(w, NoCompression) })
	testResetOutput(t, func(w io.Writer) (*Writer, error) { return NewWriter(w, DefaultCompression) })
	testResetOutput(t, func(w io.Writer) (*Writer, error) { return NewWriter(w, BestCompression) })
	dict := []byte("we are the world")
	testResetOutput(t, func(w io.Writer) (*Writer, error) { return NewWriterDict(w, NoCompression, dict) })
	testResetOutput(t, func(w io.Writer) (*Writer, error) { return NewWriterDict(w, DefaultCompression, dict) })
	testResetOutput(t, func(w io.Writer) (*Writer, error) { return NewWriterDict(w, BestCompression, dict) })
}
开发者ID:Harvey-OS,项目名称:go,代码行数:52,代码来源:deflate_test.go

示例6: TestModSqrt

func TestModSqrt(t *testing.T) {
	var elt, mod, modx4, sq, sqrt Int
	r := rand.New(rand.NewSource(9))
	for i, s := range primes[1:] { // skip 2, use only odd primes
		mod.SetString(s, 10)
		modx4.Lsh(&mod, 2)

		// test a few random elements per prime
		for x := 1; x < 5; x++ {
			elt.Rand(r, &modx4)
			elt.Sub(&elt, &mod) // test range [-mod, 3*mod)
			if !testModSqrt(t, &elt, &mod, &sq, &sqrt) {
				t.Errorf("#%d: failed (sqrt(e) = %s)", i, &sqrt)
			}
		}

		if testing.Short() && i > 2 {
			break
		}
	}

	if testing.Short() {
		return
	}

	// exhaustive test for small values
	for n := 3; n < 100; n++ {
		mod.SetInt64(int64(n))
		if !mod.ProbablyPrime(10) {
			continue
		}
		isSquare := make([]bool, n)

		// test all the squares
		for x := 1; x < n; x++ {
			elt.SetInt64(int64(x))
			if !testModSqrt(t, &elt, &mod, &sq, &sqrt) {
				t.Errorf("#%d: failed (sqrt(%d,%d) = %s)", x, &elt, &mod, &sqrt)
			}
			isSquare[sq.Uint64()] = true
		}

		// test all non-squares
		for x := 1; x < n; x++ {
			sq.SetInt64(int64(x))
			z := sqrt.ModSqrt(&sq, &mod)
			if !isSquare[x] && z != nil {
				t.Errorf("#%d: failed (sqrt(%d,%d) = nil)", x, &sqrt, &mod)
			}
		}
	}
}
开发者ID:danny8002,项目名称:go,代码行数:52,代码来源:int_test.go

示例7: TestSendRecv

// TestSendRecv checks the Send and Recv replication primitives.
func TestSendRecv(t *testing.T) {
	t.Parallel()
	// Create a source repo:
	srcRepo := "repo_TestSendRecv_src"
	require.NoError(t, Init(srcRepo))

	// Create a file in the source repo:
	writeFile(t, fmt.Sprintf("%s/master/myfile1", srcRepo), "foo")
	if testing.Short() {
		writeLots(t, fmt.Sprintf("%s/master/big_file", srcRepo), 1)
	} else {
		writeLots(t, fmt.Sprintf("%s/master/big_file", srcRepo), 10)
	}

	// Create a commit in the source repo:
	require.NoError(t, Commit(srcRepo, "mycommit1", "master"))

	// Create another file in the source repo:
	writeFile(t, fmt.Sprintf("%s/master/myfile2", srcRepo), "bar")
	if testing.Short() {
		writeLots(t, fmt.Sprintf("%s/master/big_file", srcRepo), 1)
	} else {
		writeLots(t, fmt.Sprintf("%s/master/big_file", srcRepo), 10)
	}

	// Create a another commit in the source repo:
	require.NoError(t, Commit(srcRepo, "mycommit2", "master"))

	// Create a destination repo:
	dstRepo := "repo_TestSendRecv_dst"
	require.NoError(t, Init(dstRepo))
	repo2Recv := func(r io.Reader) error { return recv(dstRepo, r) }

	// Verify that the commits "mycommit1" and "mycommit2" do not exist in destination:
	checkNoExists(t, fmt.Sprintf("%s/master/mycommit1", dstRepo))
	checkNoExists(t, fmt.Sprintf("%s/master/mycommit2", dstRepo))

	// Run a Send/Recv operation to fetch data from the older "mycommit1".
	// This verifies that tree copying works:
	require.NoError(t, send(srcRepo, "mycommit1", repo2Recv))

	// Check that the file from mycommit1 exists, but not from mycommit2:
	checkFile(t, fmt.Sprintf("%s/mycommit1/myfile1", dstRepo), "foo")
	checkNoExists(t, fmt.Sprintf("%s/mycommit2/myfile2", dstRepo))

	// Send again, this time starting from mycommit1 and going to mycommit2:
	require.NoError(t, send(srcRepo, "mycommit2", repo2Recv))

	// Verify that files from both commits are present:
	checkFile(t, fmt.Sprintf("%s/mycommit1/myfile1", dstRepo), "foo")
	checkFile(t, fmt.Sprintf("%s/mycommit2/myfile2", dstRepo), "bar")
}
开发者ID:plar,项目名称:pachyderm,代码行数:53,代码来源:btrfs_test.go

示例8: TestStackBarrierProfiling

func TestStackBarrierProfiling(t *testing.T) {
	if (runtime.GOOS == "linux" && runtime.GOARCH == "arm") || runtime.GOOS == "openbsd" || runtime.GOOS == "solaris" || runtime.GOOS == "dragonfly" {
		// This test currently triggers a large number of
		// usleep(100)s. These kernels/arches have poor
		// resolution timers, so this gives up a whole
		// scheduling quantum. On Linux and OpenBSD (and
		// probably Solaris), profiling signals are only
		// generated when a process completes a whole
		// scheduling quantum, so this test often gets zero
		// profiling signals and fails.
		t.Skipf("low resolution timers inhibit profiling signals (golang.org/issue/13405)")
		return
	}

	if !strings.Contains(os.Getenv("GODEBUG"), "gcstackbarrierall=1") {
		// Re-execute this test with constant GC and stack
		// barriers at every frame.
		testenv.MustHaveExec(t)
		if runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" {
			t.Skip("gcstackbarrierall doesn't work on ppc64")
		}
		args := []string{"-test.run=TestStackBarrierProfiling"}
		if testing.Short() {
			args = append(args, "-test.short")
		}
		cmd := exec.Command(os.Args[0], args...)
		cmd.Env = append([]string{"GODEBUG=gcstackbarrierall=1", "GOGC=1"}, os.Environ()...)
		if out, err := cmd.CombinedOutput(); err != nil {
			t.Fatalf("subprocess failed with %v:\n%s", err, out)
		}
		return
	}

	testCPUProfile(t, nil, func() {
		// This is long enough that we're likely to get one or
		// two samples in stackBarrier.
		duration := 5 * time.Second
		if testing.Short() {
			duration = 200 * time.Millisecond
		}
		t := time.After(duration)
		for {
			deepStack(1000)
			select {
			case <-t:
				return
			default:
			}
		}
	})
}
开发者ID:danny8002,项目名称:go,代码行数:51,代码来源:pprof_test.go

示例9: TestWriterBig

func TestWriterBig(t *testing.T) {
	for i, fn := range filenames {
		testFileLevelDict(t, fn, DefaultCompression, "")
		testFileLevelDict(t, fn, NoCompression, "")
		for level := BestSpeed; level <= BestCompression; level++ {
			testFileLevelDict(t, fn, level, "")
			if level >= 1 && testing.Short() && testenv.Builder() == "" {
				break
			}
		}
		if i == 0 && testing.Short() && testenv.Builder() == "" {
			break
		}
	}
}
开发者ID:Greentor,项目名称:go,代码行数:15,代码来源:writer_test.go

示例10: TestDeflateInflateString

func TestDeflateInflateString(t *testing.T) {
	if testing.Short() && testenv.Builder() == "" {
		t.Skip("skipping in short mode")
	}
	for _, test := range deflateInflateStringTests {
		gold, err := ioutil.ReadFile(test.filename)
		if err != nil {
			t.Error(err)
		}
		testToFromWithLimit(t, gold, test.label, test.limit)
		if testing.Short() {
			break
		}
	}
}
开发者ID:RajibTheKing,项目名称:gcc,代码行数:15,代码来源:deflate_test.go

示例11: TestIPCHost

func TestIPCHost(t *testing.T) {
	if testing.Short() {
		return
	}

	rootfs, err := newRootfs()
	ok(t, err)
	defer remove(rootfs)

	l, err := os.Readlink("/proc/1/ns/ipc")
	ok(t, err)

	config := newTemplateConfig(rootfs)
	config.Namespaces.Remove(configs.NEWIPC)
	buffers, exitCode, err := runContainer(config, "", "readlink", "/proc/self/ns/ipc")
	ok(t, err)

	if exitCode != 0 {
		t.Fatalf("exit code not 0. code %d stderr %q", exitCode, buffers.Stderr)
	}

	if actual := strings.Trim(buffers.Stdout.String(), "\n"); actual != l {
		t.Fatalf("ipc link not equal to host link %q %q", actual, l)
	}
}
开发者ID:hallyn,项目名称:runc,代码行数:25,代码来源:exec_test.go

示例12: TestPassExtraFiles

func TestPassExtraFiles(t *testing.T) {
	if testing.Short() {
		return
	}

	rootfs, err := newRootfs()
	if err != nil {
		t.Fatal(err)
	}
	defer remove(rootfs)

	config := newTemplateConfig(rootfs)

	container, err := factory.Create("test", config)
	if err != nil {
		t.Fatal(err)
	}
	defer container.Destroy()

	var stdout bytes.Buffer
	pipeout1, pipein1, err := os.Pipe()
	pipeout2, pipein2, err := os.Pipe()
	process := libcontainer.Process{
		Args:       []string{"sh", "-c", "cd /proc/$$/fd; echo -n *; echo -n 1 >3; echo -n 2 >4"},
		Env:        []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"},
		ExtraFiles: []*os.File{pipein1, pipein2},
		Stdin:      nil,
		Stdout:     &stdout,
	}
	err = container.Start(&process)
	if err != nil {
		t.Fatal(err)
	}

	waitProcess(&process, t)

	out := string(stdout.Bytes())
	// fd 5 is the directory handle for /proc/$$/fd
	if out != "0 1 2 3 4 5" {
		t.Fatalf("expected to have the file descriptors '0 1 2 3 4 5' passed to init, got '%s'", out)
	}
	var buf = []byte{0}
	_, err = pipeout1.Read(buf)
	if err != nil {
		t.Fatal(err)
	}
	out1 := string(buf)
	if out1 != "1" {
		t.Fatalf("expected first pipe to receive '1', got '%s'", out1)
	}

	_, err = pipeout2.Read(buf)
	if err != nil {
		t.Fatal(err)
	}
	out2 := string(buf)
	if out2 != "2" {
		t.Fatalf("expected second pipe to receive '2', got '%s'", out2)
	}
}
开发者ID:hallyn,项目名称:runc,代码行数:60,代码来源:exec_test.go

示例13: TestQuit

func TestQuit(t *testing.T) {
	if testing.Short() {
		t.Skip("skipping test in short mode")
	}

	cmd := exec.Command("sleep", "10000")
	err := cmd.Start()
	if err != nil {
		t.Skip("couldn't run test helper command")
	}
	h := Handler{
		process: cmd.Process,
	}
	err = h.Quit()
	if err != nil {
		t.Errorf("got %v, wanted %v", err, nil)
	}

	pid, err := ignoreInterrupt()
	if err != nil {
		t.Skip("couldn't run test helper command: %v", err)
	}
	h = Handler{
		process: pid,
	}
	err = h.Quit()
	if err != errProcessTookTooLong {
		t.Errorf("got %v, wanted %v", err, errProcessTookTooLong)
	}
}
开发者ID:rfistman,项目名称:camlistore,代码行数:30,代码来源:app_test.go

示例14: TestTimeout

func TestTimeout(t *testing.T) {
	if testing.Short() {
		t.Skip("Integration test - skipping for short mode.")
	}

	sleepForeverHandler := func(w http.ResponseWriter, req *http.Request) {
		req.Close = true
		notify := w.(http.CloseNotifier).CloseNotify()
		<-notify
	}
	server := httptest.NewServer(http.HandlerFunc(sleepForeverHandler))
	defer server.Close()

	rg := NewRecordGenerator(500 * time.Millisecond)
	host, port, err := net.SplitHostPort(server.Listener.Addr().String())
	_, err = rg.loadFromMaster(host, port)
	if err == nil {
		t.Fatal("Expect error because of timeout handler")
	}
	urlErr, ok := (err).(*url.Error)
	if !ok {
		t.Fatalf("Expected url.Error, instead: %#v", urlErr)
	}
	netErr, ok := urlErr.Err.(net.Error)
	if !ok {
		t.Fatalf("Expected net.Error, instead: %#v", netErr)
	}
	if !netErr.Timeout() {
		t.Errorf("Did not receive a timeout, instead: %#v", err)
	}
}
开发者ID:puppetizeme,项目名称:mesos-dns,代码行数:31,代码来源:generator_test.go

示例15: TestCost

func TestCost(t *testing.T) {
	if testing.Short() {
		return
	}

	pass := []byte("mypassword")

	for c := 0; c < MinCost; c++ {
		p, _ := newFromPassword(pass, c)
		if p.cost != uint32(DefaultCost) {
			t.Errorf("newFromPassword should default costs below %d to %d, but was %d", MinCost, DefaultCost, p.cost)
		}
	}

	p, _ := newFromPassword(pass, 14)
	if p.cost != 14 {
		t.Errorf("newFromPassword should default cost to 14, but was %d", p.cost)
	}

	hp, _ := newFromHash(p.Hash())
	if p.cost != hp.cost {
		t.Errorf("newFromHash should maintain the cost at %d, but was %d", p.cost, hp.cost)
	}

	_, err := newFromPassword(pass, 32)
	if err == nil {
		t.Fatalf("newFromPassword: should return a cost error")
	}
	if err != InvalidCostError(32) {
		t.Errorf("newFromPassword: should return cost error, got %#v", err)
	}
}
开发者ID:aubonbeurre,项目名称:gcc,代码行数:32,代码来源:bcrypt_test.go


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