RFR: 8324672: Update jdk/java/time/tck/java/time/TCKInstant.java now() to be more robust [v3]

Ramkumar Sunderbabu rsunderbabu at openjdk.org
Tue Oct 15 13:34:15 UTC 2024


On Tue, 15 Oct 2024 13:08:37 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> Ramkumar Sunderbabu has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   checking if time is monotonic
>
> test/jdk/java/time/tck/java/time/TCKInstant.java line 196:
> 
>> 194:             instantMillis = Instant.now().toEpochMilli();
>> 195:             afterMillis = Instant.now(Clock.systemUTC()).toEpochMilli();
>> 196:             diff = instantMillis - beforeMillis;
> 
> Alternatively, you could set:
> 
> - `diff = afterMillis - beforeMillis;` (range should be < 100ms, instant is anyhwere inside)  or,
> - `diff = Math.abs(afterMillis / 2 - instantMillis + beforeMillis / 2);` (distance from instant to midpoint should be < 100ms)
> 
> Not that it matters much I guess - but it would give more symmetry... Feel free to ignore :-)

AFAIU, the original intention of the test is to check if Instant.now and Instant.now(Clock.systemUTC()) returns almost same time since the underlying clock is same.
Given that premise,
suggestion 1: it does the job but doesn't show the intention in a better way.
suggestion 2: it is not same as what the test wanted to check.
If you are fine, I would like to retain the logic I have in my latest commit.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21413#discussion_r1801176742


More information about the core-libs-dev mailing list