@@ -18,6 +18,7 @@ import (
18
18
"context"
19
19
"errors"
20
20
"fmt"
21
+ "github.com/cloudwego/kitex/pkg/remote/codec"
21
22
"reflect"
22
23
"strconv"
23
24
"strings"
60
61
serverTimeoutAddr = "127.0.0.1:9006"
61
62
noDefSerdesFrugalAddr = "127.0.0.1:9007"
62
63
noDefSerdesFastCodecAddr = "127.0.0.1:9008"
64
+ serverWithCRCAddr = "127.0.0.1:9009"
63
65
)
64
66
65
67
func TestMain (m * testing.M ) {
@@ -517,6 +519,34 @@ func TestNoDefaultSerdes(t *testing.T) {
517
519
}
518
520
}
519
521
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
+
520
550
func BenchmarkThriftCall (b * testing.B ) {
521
551
cli = getKitexClient (transport .TTHeader )
522
552
ctx , stReq := thriftrpc .CreateSTRequest (context .Background ())
0 commit comments