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

Daniel Fuchs dfuchs at openjdk.org
Tue Oct 15 15:32:10 UTC 2024


On Tue, 15 Oct 2024 13:31:37 GMT, Ramkumar Sunderbabu <rsunderbabu at openjdk.org> wrote:

>> 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.

I am fine with it.

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

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


More information about the core-libs-dev mailing list