Skip to content

Commit

Permalink
change done on checkHeaderandtrailer
Browse files Browse the repository at this point in the history
  • Loading branch information
misvivek committed Dec 9, 2024
1 parent 86a4997 commit 5aada36
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions internal/transport/handler_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ func (s) TestHandlerTransport_HandleStreams_Timeout(t *testing.T) {
if err != nil {
t.Fatal(err)
}
// rst flag setting to verify the noop function: signalDeadlineExceeded
ch := make(chan struct{}, 1)
origSignalDeadlineExceeded := signalDeadlineExceeded
signalDeadlineExceeded = func() {
ch <- struct{}{}
}
defer func() {
signalDeadlineExceeded = origSignalDeadlineExceeded
}()
runStream := func(s *ServerStream) {
defer bodyw.Close()
select {
Expand All @@ -393,23 +402,9 @@ func (s) TestHandlerTransport_HandleStreams_Timeout(t *testing.T) {
t.Errorf("ctx.Err = %v; want %v", err, context.DeadlineExceeded)
return
}
// rst flag setting to verify the noop function: signalDeadlineExceeded
ch := make(chan struct{}, 1)
origSignalDeadlineExceeded := signalDeadlineExceeded
signalDeadlineExceeded = func() {
ch <- struct{}{}
}
defer func() {
signalDeadlineExceeded = origSignalDeadlineExceeded
}()

s.WriteStatus(status.New(codes.DeadlineExceeded, "too slow"))
select {
case <-ch: // Signal received, continue with the test
case <-s.ctx.Done():
case <-time.After(5 * time.Second):
t.Errorf("timeout waiting for ctx.Done")
return
}

}
ht.HandleStreams(
context.Background(), func(s *ServerStream) { go runStream(s) },
Expand All @@ -424,6 +419,13 @@ func (s) TestHandlerTransport_HandleStreams_Timeout(t *testing.T) {
"Grpc-Message": {encodeGrpcMessage("too slow")},
}
checkHeaderAndTrailer(t, rw, wantHeader, wantTrailer)
select {
case <-ch: // Signal received, continue with the test
case <-time.After(5 * time.Second):
t.Errorf("timeout waiting for ctx.Done")
return
}

}

// TestHandlerTransport_HandleStreams_MultiWriteStatus ensures that
Expand Down

0 comments on commit 5aada36

Please sign in to comment.