File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed
core/src/test/java/io/grpc Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -152,13 +152,17 @@ public void toStringMatches_withDeadline() {
152152 @ Test
153153 @ SuppressWarnings ("deprecation" )
154154 public void withDeadlineNanoTime () {
155- CallOptions opts = CallOptions .DEFAULT .withDeadlineNanoTime (System .nanoTime ());
155+ // Create Deadline near calling System.nanoTime to reduce clock differences
156+ Deadline reference = Deadline .after (-1 , NANOSECONDS );
157+ long rawDeadline = System .nanoTime () - 1 ;
158+ CallOptions opts = CallOptions .DEFAULT .withDeadlineNanoTime (rawDeadline );
156159 assertThat (opts .getDeadlineNanoTime ()).isNotNull ();
160+ // This is not technically correct, since nanoTime is permitted to overflow, but the chances of
161+ // that impacting this test are very remote.
157162 assertThat (opts .getDeadlineNanoTime ()).isAtMost (System .nanoTime ());
158163 assertThat (opts .getDeadline ().isExpired ()).isTrue ();
159164
160- assertAbout (deadline ()).that (opts .getDeadline ())
161- .isWithin (20 , MILLISECONDS ).of (Deadline .after (0 , SECONDS ));
165+ assertAbout (deadline ()).that (opts .getDeadline ()).isWithin (50 , MILLISECONDS ).of (reference );
162166 }
163167
164168 // TODO(carl-mastrangelo): consider making a CallOptionsSubject for Truth.
You can’t perform that action at this time.
0 commit comments