MCPcopy
hub / github.com/grpc/grpc-go / testServerBinaryLog

Function testServerBinaryLog

binarylog/binarylog_end2end_test.go:924–963  ·  view source on GitHub ↗
(t *testing.T, c *rpcConfig)

Source from the content-addressed store, hash-verified

922}
923
924func testServerBinaryLog(t *testing.T, c *rpcConfig) error {
925 defer testSink.clear()
926 expect := runRPCs(t, c)
927 want := expect.toServerLogEntries()
928 var got []*binlogpb.GrpcLogEntry
929 // In racy cases, some entries are not logged when the RPC is finished (e.g.
930 // context.Cancel). This is unlikely to happen on server side, but it does
931 // no harm to retry.
932 //
933 // Check 10 times, with a sleep of 1/100 seconds between each check. Makes
934 // it an 1-second wait in total.
935 for i := 0; i < 10; i++ {
936 got = testSink.logEntries(false) // all server entries.
937 if len(want) == len(got) {
938 break
939 }
940 time.Sleep(100 * time.Millisecond)
941 }
942
943 if len(want) != len(got) {
944 for i, e := range want {
945 t.Errorf("in want: %d, %s", i, e.GetType())
946 }
947 for i, e := range got {
948 t.Errorf("in got: %d, %s", i, e.GetType())
949 }
950 return fmt.Errorf("didn't get same amount of log entries, want: %d, got: %d", len(want), len(got))
951 }
952 var errored bool
953 for i := 0; i < len(got); i++ {
954 if !equalLogEntry(want[i], got[i]) {
955 t.Errorf("entry: %d, want %+v, got %+v", i, want[i], got[i])
956 errored = true
957 }
958 }
959 if errored {
960 return fmt.Errorf("test failed")
961 }
962 return nil
963}
964
965func (s) TestServerBinaryLogUnaryRPC(t *testing.T) {
966 if err := testServerBinaryLog(t, &rpcConfig{success: true, callType: unaryRPC}); err != nil {

Calls 7

runRPCsFunction · 0.85
equalLogEntryFunction · 0.85
toServerLogEntriesMethod · 0.80
logEntriesMethod · 0.80
ErrorfMethod · 0.65
clearMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected