// Run executes the thriftgauntlet behavior. func Run(t crossdock.T) { fatals := crossdock.Fatals(t) dispatcher := disp.Create(t) fatals.NoError(dispatcher.Start(), "could not start Dispatcher") defer dispatcher.Stop() t.Tag("transport", t.Param(params.Transport)) t.Tag("server", t.Param(params.Server)) RunGauntlet(t, Config{ Dispatcher: dispatcher, ServerName: serverName, }) }
// Raw implements the 'raw' behavior. func Raw(t crossdock.T) { t = createEchoT("raw", t) fatals := crossdock.Fatals(t) dispatcher := disp.Create(t) fatals.NoError(dispatcher.Start(), "could not start Dispatcher") defer dispatcher.Stop() client := raw.New(dispatcher.Channel("yarpc-test")) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() token := random.Bytes(5) resBody, _, err := client.Call(ctx, yarpc.NewReqMeta().Procedure("echo/raw"), token) crossdock.Fatals(t).NoError(err, "call to echo/raw failed: %v", err) crossdock.Assert(t).True(bytes.Equal(token, resBody), "server said: %v", resBody) }
// Thrift implements the 'thrift' behavior. func Thrift(t crossdock.T) { t = createEchoT("thrift", t) fatals := crossdock.Fatals(t) dispatcher := disp.Create(t) fatals.NoError(dispatcher.Start(), "could not start Dispatcher") defer dispatcher.Stop() client := echoclient.New(dispatcher.Channel("yarpc-test")) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() token := random.String(5) pong, _, err := client.Echo(ctx, nil, &echo.Ping{Beep: token}) crossdock.Fatals(t).NoError(err, "call to Echo::echo failed: %v", err) crossdock.Assert(t).Equal(token, pong.Boop, "server said: %v", pong.Boop) }
// JSON implements the 'json' behavior. func JSON(t crossdock.T) { t = createEchoT("json", t) fatals := crossdock.Fatals(t) dispatcher := disp.Create(t) fatals.NoError(dispatcher.Start(), "could not start Dispatcher") defer dispatcher.Stop() client := json.New(dispatcher.Channel("yarpc-test")) ctx, cancel := context.WithTimeout(context.Background(), time.Second) defer cancel() var response jsonEcho token := random.String(5) _, err := client.Call( ctx, yarpc.NewReqMeta().Procedure("echo"), &jsonEcho{Token: token}, &response, ) crossdock.Fatals(t).NoError(err, "call to echo failed: %v", err) crossdock.Assert(t).Equal(token, response.Token, "server said: %v", response.Token) }
// Run tests if a yarpc client returns correctly a client timeout error behind // the TimeoutError interface when the context deadline is reached while the // server is taking too long to respond. func Run(t crossdock.T) { assert := crossdock.Assert(t) fatals := crossdock.Fatals(t) ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() dispatcher := disp.Create(t) fatals.NoError(dispatcher.Start(), "could not start Dispatcher") defer dispatcher.Stop() ch := raw.New(dispatcher.Channel("yarpc-test")) _, _, err := ch.Call(ctx, yarpc.NewReqMeta().Procedure("sleep/raw"), nil) fatals.Error(err, "expected a failure for timeout") if transport.IsBadRequestError(err) { t.Skipf("sleep/raw method not implemented: %v", err) return } assert.True(transport.IsTimeoutError(err), "returns a TimeoutError: %T", err) trans := t.Param(params.Transport) switch trans { case "http": form := strings.HasPrefix(err.Error(), `client timeout for procedure "sleep/raw" of service "yarpc-test" after`) assert.True(form, "should be a client timeout: %q", err.Error()) case "tchannel": form := strings.HasPrefix(err.Error(), `timeout`) assert.True(form, "should be a remote timeout (we cant represent client timeout with tchannel): %q", err.Error()) default: fatals.Fail("", "unknown transport %q", trans) } }
// Run runs the headers behavior func Run(t crossdock.T) { t = createHeadersT(t) fatals := crossdock.Fatals(t) assert := crossdock.Assert(t) checks := crossdock.Checks(t) dispatcher := disp.Create(t) fatals.NoError(dispatcher.Start(), "could not start Dispatcher") defer dispatcher.Stop() var caller headerCaller encoding := t.Param(params.Encoding) switch encoding { case "raw": caller = rawCaller{raw.New(dispatcher.Channel("yarpc-test"))} case "json": caller = jsonCaller{json.New(dispatcher.Channel("yarpc-test"))} case "thrift": caller = thriftCaller{echoclient.New(dispatcher.Channel("yarpc-test"))} default: fatals.Fail("", "unknown encoding %q", encoding) } token1 := random.String(10) token2 := random.String(10) tests := []struct { desc string give yarpc.Headers want yarpc.Headers }{ { "valid headers", yarpc.NewHeaders().With("token1", token1).With("token2", token2), yarpc.NewHeaders().With("token1", token1).With("token2", token2), }, { "non-string values", yarpc.NewHeaders().With("token", "42"), yarpc.NewHeaders().With("token", "42"), }, { "empty strings", yarpc.NewHeaders().With("token", ""), yarpc.NewHeaders().With("token", ""), }, { "no headers", yarpc.Headers{}, yarpc.NewHeaders(), }, { "empty map", yarpc.NewHeaders(), yarpc.NewHeaders(), }, { "varying casing", yarpc.NewHeaders().With("ToKeN1", token1).With("tOkEn2", token2), yarpc.NewHeaders().With("token1", token1).With("token2", token2), }, { "http header conflict", yarpc.NewHeaders().With("Rpc-Procedure", "does not exist"), yarpc.NewHeaders().With("rpc-procedure", "does not exist"), }, { "mixed case value", yarpc.NewHeaders().With("token", "MIXED case Value"), yarpc.NewHeaders().With("token", "MIXED case Value"), }, } for _, tt := range tests { got, err := caller.Call(tt.give) if checks.NoError(err, "%v: call failed", tt.desc) { gotHeaders := internal.RemoveVariableHeaderKeys(got) assert.Equal(tt.want, gotHeaders, "%v: returns valid headers", tt.desc) } } }