Skip to content

Commit 085452f

Browse files
authored
test: payload validator (#86)
1 parent 3896d9b commit 085452f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

thriftrpc/normalcall/normalcall_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"errors"
2020
"fmt"
21+
"github.com/cloudwego/kitex/pkg/remote/codec"
2122
"reflect"
2223
"strconv"
2324
"strings"
@@ -60,6 +61,7 @@ var (
6061
serverTimeoutAddr = "127.0.0.1:9006"
6162
noDefSerdesFrugalAddr = "127.0.0.1:9007"
6263
noDefSerdesFastCodecAddr = "127.0.0.1:9008"
64+
serverWithCRCAddr = "127.0.0.1:9009"
6365
)
6466

6567
func TestMain(m *testing.M) {
@@ -517,6 +519,34 @@ func TestNoDefaultSerdes(t *testing.T) {
517519
}
518520
}
519521

522+
func TestCRC32PayloadValidator(t *testing.T) {
523+
codecOpt := client.WithCodec(codec.NewDefaultCodecWithConfig(codec.CodecConfig{CRC32Check: true}))
524+
crcClient := getKitexClient(transport.TTHeaderFramed, codecOpt)
525+
526+
t.Run("serverWithoutCRC", func(t *testing.T) {
527+
// request server without crc32 check config
528+
ctx, stReq := thriftrpc.CreateSTRequest(context.Background())
529+
for i := 0; i < 10; i++ {
530+
_, err := crcClient.TestSTReq(ctx, stReq, callopt.WithHostPort(addr))
531+
test.Assert(t, err == nil, err)
532+
}
533+
})
534+
535+
t.Run("serverWithCRC", func(t *testing.T) {
536+
// request server with crc config
537+
svrCodecOpt := server.WithCodec(codec.NewDefaultCodecWithConfig(codec.CodecConfig{CRC32Check: true}))
538+
svrWithCRC := thriftrpc.RunServer(&thriftrpc.ServerInitParam{Network: "tcp", Address: serverWithCRCAddr}, nil, svrCodecOpt)
539+
common.WaitServer(serverWithCRCAddr)
540+
defer svrWithCRC.Stop()
541+
542+
ctx, stReq := thriftrpc.CreateSTRequest(context.Background())
543+
for i := 0; i < 10; i++ {
544+
_, err := crcClient.TestSTReq(ctx, stReq, callopt.WithHostPort(serverWithCRCAddr))
545+
test.Assert(t, err == nil, err)
546+
}
547+
})
548+
}
549+
520550
func BenchmarkThriftCall(b *testing.B) {
521551
cli = getKitexClient(transport.TTHeader)
522552
ctx, stReq := thriftrpc.CreateSTRequest(context.Background())

0 commit comments

Comments
 (0)