merged from gramsrv upstream
This commit is contained in:
parent
79c64ee916
commit
21a0856587
651 changed files with 54774 additions and 4590 deletions
41
internal/rpc/router_panic_isolation_test.go
Normal file
41
internal/rpc/router_panic_isolation_test.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/iamxvbaba/td/bin"
|
||||
"github.com/iamxvbaba/td/tg"
|
||||
"github.com/iamxvbaba/td/tgerr"
|
||||
"github.com/iamxvbaba/td/tlprofile"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zaptest/observer"
|
||||
)
|
||||
|
||||
func TestDispatchGeneratedSafelyIsolatesHandlerPanic(t *testing.T) {
|
||||
dispatcher := tlprofile.NewDispatcher()
|
||||
registerRPC[*tg.HelpGetNearestDCRequest](dispatcher, tlprofile.SemanticMethodHelpGetNearestDC, func(context.Context, *tg.HelpGetNearestDCRequest) (any, error) {
|
||||
panic("projection boom")
|
||||
})
|
||||
core, observed := observer.New(zap.ErrorLevel)
|
||||
r := &Router{dispatcher: dispatcher, log: zap.New(core)}
|
||||
|
||||
var wire bin.Buffer
|
||||
if err := tlprofile.EncodeObject(tlprofile.Profile229, &tg.HelpGetNearestDCRequest{}, &wire); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
admission, err := dispatcher.Admit(tlprofile.Profile229, &wire, tlprofile.Limits{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result, err := r.dispatchGeneratedSafely(context.Background(), "help.getNearestDc", admission)
|
||||
if result != nil {
|
||||
t.Fatalf("panic returned result %T", result)
|
||||
}
|
||||
if !tgerr.Is(err, "INTERNAL_SERVER_ERROR") {
|
||||
t.Fatalf("panic error = %v, want INTERNAL_SERVER_ERROR", err)
|
||||
}
|
||||
if got := observed.FilterMessage("RPC handler panic isolated").Len(); got != 1 {
|
||||
t.Fatalf("panic log count = %d, want 1", got)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue