Skip to content

Commit

Permalink
test: payload validator (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppzqh authored Aug 28, 2024
1 parent 3896d9b commit 085452f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions thriftrpc/normalcall/normalcall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"errors"
"fmt"
"github.com/cloudwego/kitex/pkg/remote/codec"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -60,6 +61,7 @@ var (
serverTimeoutAddr = "127.0.0.1:9006"
noDefSerdesFrugalAddr = "127.0.0.1:9007"
noDefSerdesFastCodecAddr = "127.0.0.1:9008"
serverWithCRCAddr = "127.0.0.1:9009"
)

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -517,6 +519,34 @@ func TestNoDefaultSerdes(t *testing.T) {
}
}

func TestCRC32PayloadValidator(t *testing.T) {
codecOpt := client.WithCodec(codec.NewDefaultCodecWithConfig(codec.CodecConfig{CRC32Check: true}))
crcClient := getKitexClient(transport.TTHeaderFramed, codecOpt)

t.Run("serverWithoutCRC", func(t *testing.T) {
// request server without crc32 check config
ctx, stReq := thriftrpc.CreateSTRequest(context.Background())
for i := 0; i < 10; i++ {
_, err := crcClient.TestSTReq(ctx, stReq, callopt.WithHostPort(addr))
test.Assert(t, err == nil, err)
}
})

t.Run("serverWithCRC", func(t *testing.T) {
// request server with crc config
svrCodecOpt := server.WithCodec(codec.NewDefaultCodecWithConfig(codec.CodecConfig{CRC32Check: true}))
svrWithCRC := thriftrpc.RunServer(&thriftrpc.ServerInitParam{Network: "tcp", Address: serverWithCRCAddr}, nil, svrCodecOpt)
common.WaitServer(serverWithCRCAddr)
defer svrWithCRC.Stop()

ctx, stReq := thriftrpc.CreateSTRequest(context.Background())
for i := 0; i < 10; i++ {
_, err := crcClient.TestSTReq(ctx, stReq, callopt.WithHostPort(serverWithCRCAddr))
test.Assert(t, err == nil, err)
}
})
}

func BenchmarkThriftCall(b *testing.B) {
cli = getKitexClient(transport.TTHeader)
ctx, stReq := thriftrpc.CreateSTRequest(context.Background())
Expand Down

0 comments on commit 085452f

Please sign in to comment.