Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ttstream): pingpong method refers to server interface defined in Kitex generation code when streamx is enabled and there are other streaming methods #1642

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/streamx/streamx_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ func TestStreamingException(t *testing.T) {
atomic.StoreInt32(&circuitBreaker, 0)

// assert context deadline error
ctx, cancel := context.WithTimeout(octx, time.Millisecond)
ctx, cancel := context.WithTimeout(octx, 10*time.Millisecond)
ctx, bs, err := cli.BidiStream(ctx)
test.Assert(t, err == nil, err)
res, err := bs.Recv(ctx)
Expand Down
9 changes: 7 additions & 2 deletions tool/internal_pkg/tpl/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func newServiceInfo(hasStreaming bool, keepStreamingMethods bool, keepNonStreami
return svcInfo
}

{{- $referToKitexServerInterface := and .StreamX .HasStreaming}}
{{range .AllMethods}}
{{- $isStreaming := or .ClientStreaming .ServerStreaming}}
{{- $streamingUnary := (eq .Streaming.Mode "unary")}}
Expand All @@ -153,6 +154,10 @@ func newServiceInfo(hasStreaming bool, keepStreamingMethods bool, keepNonStreami
{{- $bidiSide := and .ClientStreaming .ServerStreaming}}
{{- $arg := ""}}
{{- $handlerFunc := ""}}
{{- $serverInterfaceName := printf "%s.%s" .PkgRefName .ServiceName }}
{{- if $referToKitexServerInterface}}
{{- $serverInterfaceName = .ServiceName}}{{/* when streamx is enabled and there are streaming methods, refer to Server Interface defined in service/server.go */}}
{{- end}}
{{- $mode := ""}}
{{- if $streamingUnary -}} {{- $mode = "serviceinfo.StreamingUnary" }} {{- $handlerFunc = "InvokeUnaryHandler" }}
{{- else if $serverSide -}} {{- $mode = "serviceinfo.StreamingServer" }} {{- $handlerFunc = "InvokeServerStreamHandler" }}
Expand Down Expand Up @@ -228,8 +233,8 @@ func {{LowerFirst .Name}}Handler(ctx context.Context, handler interface{}, arg,
{{- end}}
{{if gt .ArgsLength 0}}realArg := {{else}}_ = {{end}}arg.(*{{if not .GenArgResultStruct}}{{.PkgRefName}}.{{end}}{{.ArgStructName}})
{{if or (not .Void) .Exceptions}}realResult := result.(*{{if not .GenArgResultStruct}}{{.PkgRefName}}.{{end}}{{.ResStructName}}){{end}}
{{if .Void}}err := handler.({{.PkgRefName}}.{{.ServiceName}}).{{.Name}}(ctx{{range .Args}}, realArg.{{.Name}}{{end}})
{{else}}success, err := handler.({{.PkgRefName}}.{{.ServiceName}}).{{.Name}}(ctx{{range .Args}}, realArg.{{.Name}}{{end}})
{{if .Void}}err := handler.({{$serverInterfaceName}}).{{.Name}}(ctx{{range .Args}}, realArg.{{.Name}}{{end}})
{{else}}success, err := handler.({{$serverInterfaceName}}).{{.Name}}(ctx{{range .Args}}, realArg.{{.Name}}{{end}})
{{end -}}
if err != nil {
{{- if $HandlerReturnKeepResp }}
Expand Down
Loading