當前位置: 首頁>>代碼示例>>Golang>>正文


Golang iotest.TimeoutReader函數代碼示例

本文整理匯總了Golang中testing/iotest.TimeoutReader函數的典型用法代碼示例。如果您正苦於以下問題:Golang TimeoutReader函數的具體用法?Golang TimeoutReader怎麽用?Golang TimeoutReader使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了TimeoutReader函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestCollisionOrCorrupt

func (s *CollisionSuite) TestCollisionOrCorrupt(c *check.C) {
	fooMD5 := "acbd18db4cc2f85cedef654fccc4a4d8"

	c.Check(collisionOrCorrupt(fooMD5, []byte{'f'}, []byte{'o'}, bytes.NewBufferString("o")),
		check.Equals, CollisionError)
	c.Check(collisionOrCorrupt(fooMD5, []byte{'f'}, nil, bytes.NewBufferString("oo")),
		check.Equals, CollisionError)
	c.Check(collisionOrCorrupt(fooMD5, []byte{'f'}, []byte{'o', 'o'}, nil),
		check.Equals, CollisionError)
	c.Check(collisionOrCorrupt(fooMD5, nil, []byte{}, bytes.NewBufferString("foo")),
		check.Equals, CollisionError)
	c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o', 'o'}, nil, bytes.NewBufferString("")),
		check.Equals, CollisionError)
	c.Check(collisionOrCorrupt(fooMD5, nil, nil, iotest.NewReadLogger("foo: ", iotest.DataErrReader(iotest.OneByteReader(bytes.NewBufferString("foo"))))),
		check.Equals, CollisionError)

	c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o', 'o'}, nil, bytes.NewBufferString("bar")),
		check.Equals, DiskHashError)
	c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o'}, nil, nil),
		check.Equals, DiskHashError)
	c.Check(collisionOrCorrupt(fooMD5, []byte{}, nil, bytes.NewBufferString("")),
		check.Equals, DiskHashError)
	c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'O'}, nil, bytes.NewBufferString("o")),
		check.Equals, DiskHashError)
	c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'O', 'o'}, nil, nil),
		check.Equals, DiskHashError)
	c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o'}, []byte{'O'}, nil),
		check.Equals, DiskHashError)
	c.Check(collisionOrCorrupt(fooMD5, []byte{'f', 'o'}, nil, bytes.NewBufferString("O")),
		check.Equals, DiskHashError)

	c.Check(collisionOrCorrupt(fooMD5, []byte{}, nil, iotest.TimeoutReader(iotest.OneByteReader(bytes.NewBufferString("foo")))),
		check.Equals, iotest.ErrTimeout)
}
開發者ID:Kunde21,項目名稱:arvados,代碼行數:34,代碼來源:collision_test.go

示例2: TestLoadTimeoutReader

func TestLoadTimeoutReader(t *testing.T) {
	p := make(Properties)
	err := p.Load(iotest.TimeoutReader(bytes.NewReader([]byte(source))))
	if err == nil {
		t.Fail()
	}
}
開發者ID:dmotylev,項目名稱:goproperties,代碼行數:7,代碼來源:properties_test.go

示例3: TestMediaErrHandling

func TestMediaErrHandling(t *testing.T) {
	handler := &myHandler{}
	server := httptest.NewServer(handler)
	defer server.Close()

	client := &http.Client{}
	s, err := storage.New(client)
	if err != nil {
		t.Fatalf("unable to create service: %v", err)
	}
	s.BasePath = server.URL

	const body = "fake media data"
	f := strings.NewReader(body)
	// The combination of TimeoutReader and OneByteReader causes the first byte to
	// be successfully delivered, but then a timeout error is reported.  This
	// allows us to test the goroutine within the getMediaType function.
	r := iotest.TimeoutReader(iotest.OneByteReader(f))
	o := &storage.Object{
		Bucket:          "mybucket",
		Name:            "filename",
		ContentType:     "plain/text",
		ContentEncoding: "utf-8",
		ContentLanguage: "en",
	}
	_, err = s.Objects.Insert("mybucket", o).Media(r).Do()
	if err == nil || !strings.Contains(err.Error(), "timeout") {
		t.Errorf("expected timeout error, got %v", err)
	}
	if handler.err != nil {
		t.Errorf("handler err = %v, want nil", handler.err)
	}
}
開發者ID:sivarajankumar,項目名稱:google-api-go-client,代碼行數:33,代碼來源:storage_test.go

示例4: ContentsReturnReadError

func (t *ReadProxyTest) ContentsReturnReadError() {
	// NewFile
	rwl := mock_lease.NewMockReadWriteLease(t.mockController, "rwl")
	ExpectCall(t.leaser, "NewFile")().
		WillOnce(Return(rwl, nil))

	// Write
	ExpectCall(rwl, "Write")(Any()).
		WillRepeatedly(Invoke(successfulWrite))

	// Downgrade and Revoke
	rl := mock_lease.NewMockReadLease(t.mockController, "rl")
	ExpectCall(rwl, "Downgrade")().WillOnce(Return(rl))
	ExpectCall(rl, "Revoke")()

	// Function
	t.f = func() (rc io.ReadCloser, err error) {
		rc = ioutil.NopCloser(
			iotest.TimeoutReader(
				iotest.OneByteReader(
					strings.NewReader(contents))))

		return
	}

	// Attempt to read.
	_, err := t.proxy.ReadAt(context.Background(), []byte{}, 0)
	ExpectThat(err, Error(HasSubstr("Copy")))
	ExpectThat(err, Error(HasSubstr("timeout")))
}
開發者ID:mbookman,項目名稱:gcsfuse,代碼行數:30,代碼來源:read_proxy_test.go

示例5: TestReadFailsOverAndThenDies

func TestReadFailsOverAndThenDies(t *testing.T) {
	br, _ := getBlockReader(t, "/_test/mobydick.txt")
	datanodes := br.datanodes.numRemaining()

	for br.datanodes.numRemaining() > 0 {
		br.stream.reader = iotest.TimeoutReader(br.stream.reader)
		_, err := io.CopyN(ioutil.Discard, br, 1000)
		require.NoError(t, err)
		require.Equal(t, datanodes-1, br.datanodes.numRemaining())
		datanodes--
	}

	br.stream.reader = iotest.TimeoutReader(br.stream.reader)
	_, err := io.Copy(ioutil.Discard, br)
	assert.EqualValues(t, iotest.ErrTimeout, err)
}
開發者ID:erimatnor,項目名稱:hdfs,代碼行數:16,代碼來源:block_reader_test.go

示例6: TestMultiReaderSourceError

func TestMultiReaderSourceError(t *testing.T) {
	t.Parallel()

	// This test fails if it doesn't complete quickly.
	timer := time.AfterFunc(2*time.Second, func() {
		t.Fatalf("Test seems to have hung.")
	})
	defer timer.Stop()

	randomSrc := randomDataMaker{rand.NewSource(1028890720402726901)}
	tordr := iotest.TimeoutReader(&randomSrc)

	lr := io.LimitReader(tordr, expSize)

	r1, _ := newMultiReaderTimeout(lr, 10*time.Millisecond)

	b1 := &bytes.Buffer{}

	rs := make(chan copyRes, 2)

	go bgCopy(b1, r1, rs)

	res1 := <-rs

	if res1.e != Timeout {
		t.Errorf("Expected a timeout, got %v", res1.e)
		t.Fail()
	}
}
開發者ID:kkumar86,項目名稱:cbfs,代碼行數:29,代碼來源:ioutil_test.go

示例7: TestStdCopyTimeoutReader

func TestStdCopyTimeoutReader(t *testing.T) {
	var input, stdout, stderr bytes.Buffer
	input.Write([]byte{2, 0, 0, 0, 0, 0, 0, 19})
	input.Write([]byte("something happened!"))
	_, err := stdCopy(&stdout, &stderr, iotest.TimeoutReader(&input))
	if err != iotest.ErrTimeout {
		t.Errorf("stdCopy: wrong error. Want ErrTimeout. Got %#v.", err)
	}
}
開發者ID:pombredanne,項目名稱:rudder,代碼行數:9,代碼來源:stdcopy_test.go

示例8: TestReadError

func TestReadError(t *testing.T) {
	s := int(1e6)
	n, err := ReadZeros(iotest.TimeoutReader(bytes.NewReader(make([]byte, s))))
	// first read should be 512 bytes
	expected := 512
	if err != iotest.ErrTimeout || n != expected {
		t.Errorf("expected %d (timeout), got %d (%v)", expected, n, err)
	}
}
開發者ID:tg,項目名稱:nocontent,代碼行數:9,代碼來源:reader_test.go

示例9: TestReadLinesFromFile

func TestReadLinesFromFile(t *testing.T) {
	fh := bytes.NewBufferString("1\n2 3\n")
	expected := []string{"1", "2 3"}
	actual := readLinesFromFile(fh)
	assert.Equal(t, "readLinesFromFile bad result", expected, actual)

	fh2 := iotest.TimeoutReader(bytes.NewBufferString("1\n2 3\n"))
	defer assert.Panics(t, "readLinesFromFile() should panic on failure", "Reading lines failed")
	_ = readLinesFromFile(fh2)
}
開發者ID:tobinjt,項目名稱:project-euler,代碼行數:10,代碼來源:project-euler_test.go

示例10: TestWriteKeyReaderError

func (s *SessionSuite) TestWriteKeyReaderError(c *C) {
	var testErrorReader = iotest.TimeoutReader(strings.NewReader("ABCD"))

	key, _ := NewKey("test-key")
	defer key.Free()

	for res := range s.session.WriteKey(key, testErrorReader, 0, 0) {
		c.Assert(res.Error(), Equals, iotest.ErrTimeout)
	}
}
開發者ID:noxiouz,項目名稱:elliptics-go,代碼行數:10,代碼來源:elliptics_test.go

示例11: ErrorReading

func (t *RetryBucket_CreateObjectTest) ErrorReading() {
	var err error

	// Pass in a reader that will return an error.
	t.req.Contents = ioutil.NopCloser(
		iotest.OneByteReader(
			iotest.TimeoutReader(
				strings.NewReader("foobar"))))

	// Call
	err = t.call()

	ExpectThat(err, Error(HasSubstr("ReadAll")))
	ExpectThat(err, Error(HasSubstr("timeout")))
}
開發者ID:okdave,項目名稱:gcloud,代碼行數:15,代碼來源:retry_test.go

示例12: ReaderFails

func (t *RandomReaderTest) ReaderFails() {
	// Bucket
	r := iotest.OneByteReader(iotest.TimeoutReader(strings.NewReader("xxx")))
	rc := ioutil.NopCloser(r)

	ExpectCall(t.bucket, "NewReader")(Any(), Any()).
		WillOnce(Return(rc, nil))

	// Call
	buf := make([]byte, 3)
	_, err := t.rr.ReadAt(buf, 0)

	ExpectThat(err, Error(HasSubstr("readFull")))
	ExpectThat(err, Error(HasSubstr(iotest.ErrTimeout.Error())))
}
開發者ID:horzadome,項目名稱:gcsfuse,代碼行數:15,代碼來源:random_reader_test.go

示例13: TestReadFailsOver

func TestReadFailsOver(t *testing.T) {
	br, dn := getBlockReader(t, "/_test/mobydick.txt")
	datanodes := br.datanodes.numRemaining()
	br.stream.reader = iotest.TimeoutReader(br.stream.reader)

	hash := crc32.NewIEEE()
	n, err := io.Copy(hash, br)
	require.NoError(t, err)
	assert.EqualValues(t, 1048576, n)
	assert.EqualValues(t, 0xb35a6a0e, hash.Sum32())
	assert.EqualValues(t, datanodes-1, br.datanodes.numRemaining())

	_, exist := datanodeFailures[dn]
	assert.True(t, exist)
}
開發者ID:erimatnor,項目名稱:hdfs,代碼行數:15,代碼來源:block_reader_test.go

示例14: TestFailsOverMidRead

func TestFailsOverMidRead(t *testing.T) {
	br, dn := setupFailover(t)
	datanodes := br.datanodes.numRemaining()

	hash := crc32.NewIEEE()
	_, err := io.CopyN(hash, br, 10000)
	require.NoError(t, err)

	br.stream.reader = iotest.TimeoutReader(br.stream.reader)

	n, err := io.Copy(hash, br)
	require.NoError(t, err)
	assert.EqualValues(t, 1048576-10000, n)
	assert.EqualValues(t, 0xb35a6a0e, hash.Sum32())
	assert.EqualValues(t, datanodes-1, br.datanodes.numRemaining())

	_, exist := datanodeFailures[dn]
	assert.True(t, exist)
}
開發者ID:xiekeyang,項目名稱:hdfs,代碼行數:19,代碼來源:block_reader_test.go

示例15: TestStripCRError

func (s *SSHStreamSuite) TestStripCRError(c *gc.C) {
	reader := ssh.StripCRReader(strings.NewReader("One\r\r\rTwo"))
	_, err := ioutil.ReadAll(iotest.TimeoutReader(reader))
	c.Assert(err.Error(), gc.Equals, "timeout")
}
開發者ID:juju,項目名稱:utils,代碼行數:5,代碼來源:stream_test.go


注:本文中的testing/iotest.TimeoutReader函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。