ADDITIONAL SYSTEM INFORMATION :
I am using Intellij IDEA 2020.1 and installed openjdk-15 via the Project Structure dialogue. The same error happens with a manually installed version (11.05) as well.
A DESCRIPTION OF THE PROBLEM :
If I use Instant.now() repeatedly, later calls return the same value even if time should have passed already.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Initialize two variables with Instant.now() and print one after each other.
Instant now1 = Instant.now();
System.out.println(now1);
Instant now2 = Instant.now();
System.out.println(now2);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The variables should be different.
ACTUAL -
The variables are the same:
2021-02-25T15:49:57.512378100Z
2021-02-25T15:49:57.512378100Z
---------- BEGIN SOURCE ----------
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import java.time.Instant;
import static org.assertj.core.api.Assertions.assertThat;
class InstantTest {
@Test
public void succeedsIfRunInIsolation() {
assertThat(Instant.now()).isNotEqualTo(Instant.now());
}
@RepeatedTest(10)
public void allButFirstFailIfRunInIsolation() {
assertThat(Instant.now()).isNotEqualTo(Instant.now());
}
@Test
void failsAlways() {
Instant now1 = Instant.now();
System.out.println(now1);
Instant now2 = Instant.now();
System.out.println(now2);
assertThat(now1).isNotEqualTo(now2);
}
}
---------- END SOURCE ----------
FREQUENCY : always