@@ -6778,3 +6778,46 @@ func TestNetPipeConn(t *testing.T) {
6778
6778
t .Fatalf ("UnaryCall(_) = _, %v; want _, nil" , err )
6779
6779
}
6780
6780
}
6781
+
6782
+ func TestLargeTimeout (t * testing.T ) {
6783
+ defer leakcheck .Check (t )
6784
+ for _ , e := range listTestEnv () {
6785
+ testLargeTimeout (t , e )
6786
+ }
6787
+ }
6788
+
6789
+ func testLargeTimeout (t * testing.T , e env ) {
6790
+ te := newTest (t , e )
6791
+ te .declareLogNoise ("Server.processUnaryRPC failed to write status" )
6792
+
6793
+ ts := & funcServer {}
6794
+ te .startServer (ts )
6795
+ defer te .tearDown ()
6796
+ tc := testpb .NewTestServiceClient (te .clientConn ())
6797
+
6798
+ timeouts := []time.Duration {
6799
+ time .Duration (math .MaxInt64 ), // will be (correctly) converted to
6800
+ // 2562048 hours, which overflows upon converting back to an int64
6801
+ 2562047 * time .Hour , // the largest timeout that does not overflow
6802
+ }
6803
+
6804
+ for i , maxTimeout := range timeouts {
6805
+ ts .unaryCall = func (ctx context.Context , in * testpb.SimpleRequest ) (* testpb.SimpleResponse , error ) {
6806
+ deadline , ok := ctx .Deadline ()
6807
+ timeout := deadline .Sub (time .Now ())
6808
+ minTimeout := maxTimeout - 5 * time .Second
6809
+ if ! ok || timeout < minTimeout || timeout > maxTimeout {
6810
+ t .Errorf ("ctx.Deadline() = (now+%v), %v; want [%v, %v], true" , timeout , ok , minTimeout , maxTimeout )
6811
+ return nil , status .Error (codes .OutOfRange , "deadline error" )
6812
+ }
6813
+ return & testpb.SimpleResponse {}, nil
6814
+ }
6815
+
6816
+ ctx , cancel := context .WithTimeout (context .Background (), maxTimeout )
6817
+ defer cancel ()
6818
+
6819
+ if _ , err := tc .UnaryCall (ctx , & testpb.SimpleRequest {}); err != nil {
6820
+ t .Errorf ("case %v: UnaryCall(_) = _, %v; want _, nil" , i , err )
6821
+ }
6822
+ }
6823
+ }
0 commit comments