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


Golang TabletManagerClient.IsTimeoutError方法代码示例

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


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

示例1: agentRPCTestIsTimeoutErrorDialExpiredContext

// agentRPCTestIsTimeoutErrorDialExpiredContext verifies that
// client.IsTimeoutError() returns true for RPCs failed due to an expired
// context before .Dial().
func agentRPCTestIsTimeoutErrorDialExpiredContext(ctx context.Context, t *testing.T, client tmclient.TabletManagerClient, ti *topo.TabletInfo) {
	// Using a timeout of 0 here such that .Dial() will fail immediately.
	expiredCtx, cancel := context.WithTimeout(ctx, 0)
	defer cancel()
	err := client.Ping(expiredCtx, ti)
	if err == nil {
		t.Fatal("agentRPCTestIsTimeoutErrorDialExpiredContext: RPC with expired context did not fail")
	}
	if !client.IsTimeoutError(err) {
		t.Errorf("agentRPCTestIsTimeoutErrorDialExpiredContext: want: IsTimeoutError() = true. error: %v", err)
	}
}
开发者ID:BobbWu,项目名称:vitess,代码行数:15,代码来源:test_agent_rpc.go

示例2: agentRPCTestIsTimeoutErrorDialTimeout

// agentRPCTestIsTimeoutErrorDialTimeout verifies that client.IsTimeoutError()
// returns true for RPCs failed due to a connect timeout during .Dial().
func agentRPCTestIsTimeoutErrorDialTimeout(ctx context.Context, t *testing.T, client tmclient.TabletManagerClient, ti *topo.TabletInfo) {
	// Connect to a non-existing tablet.
	// For example, this provokes gRPC to return error grpc.ErrClientConnTimeout.
	invalidTi := topo.NewTabletInfo(ti.Tablet, ti.Version())
	invalidTi.Tablet = proto.Clone(invalidTi.Tablet).(*topodatapb.Tablet)
	invalidTi.Tablet.Hostname = "Non-Existent.Server"

	shortCtx, cancel := context.WithTimeout(ctx, time.Millisecond)
	defer cancel()
	err := client.Ping(shortCtx, invalidTi)
	if err == nil {
		t.Fatal("agentRPCTestIsTimeoutErrorDialTimeout: connect to non-existant tablet did not fail")
	}
	if !client.IsTimeoutError(err) {
		t.Errorf("agentRPCTestIsTimeoutErrorDialTimeout: want: IsTimeoutError() = true. error: %v", err)
	}
}
开发者ID:BobbWu,项目名称:vitess,代码行数:19,代码来源:test_agent_rpc.go

示例3: agentRPCTestIsTimeoutErrorRPC

// agentRPCTestIsTimeoutErrorRPC verifies that client.IsTimeoutError() returns
// true for RPCs failed due to an expired context during RPC execution.
func agentRPCTestIsTimeoutErrorRPC(ctx context.Context, t *testing.T, client tmclient.TabletManagerClient, ti *topo.TabletInfo, fakeAgent *fakeRPCAgent) {
	// We must use a timeout > 0 such that the context deadline hasn't expired
	// yet in grpctmclient.Client.dial().
	// NOTE: This might still race e.g. when test execution takes too long the
	//       context will be expired in dial() already. In such cases coverage
	//       will be reduced but the test will not flake.
	shortCtx, cancel := context.WithTimeout(ctx, time.Millisecond)
	defer cancel()
	fakeAgent.slow = true
	defer func() { fakeAgent.slow = false }()
	err := client.Ping(shortCtx, ti)
	if err == nil {
		t.Fatal("agentRPCTestIsTimeoutErrorRPC: RPC with expired context did not fail")
	}
	if !client.IsTimeoutError(err) {
		t.Errorf("agentRPCTestIsTimeoutErrorRPC: want: IsTimeoutError() = true. error: %v", err)
	}
}
开发者ID:BobbWu,项目名称:vitess,代码行数:20,代码来源:test_agent_rpc.go


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