[ 
https://issues.apache.org/jira/browse/LUCENE-10423?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17579678#comment-17579678
 ] 

Robert Muir commented on LUCENE-10423:
--------------------------------------

The comment is slightly incorrect. nanoTime should still not be used, as it 
prevents test failures from reproducing across machines. But for now, it is 
better than currentTimeMillis in the places doing this.

So there are two problems:
1. System.currentTimeMillis() should not be used. For now, we can drop in 
nanoTime. It is slightly better.
2. Tests should not depend on any clock whatsoever. Machines run at different 
speeds and so on.

For example when the test logic does:
{noformat}
while (/* run iterations for 2 seconds */) {
  // logic
}
{noformat}

This is bad, as a test failure at iteration 97,000 may not reproduce on my 
slower computer, if my computer can only do 70,000 iterations in 2 seconds, it 
will never reach it. And it can mess up random seeds for any remaining logic in 
the test.
Instead, such tests should just do a simple for loop for 97,000 iterations, 
which will behave the same everywhere.


> Remove uses of wall-clock time in codebase
> ------------------------------------------
>
>                 Key: LUCENE-10423
>                 URL: https://issues.apache.org/jira/browse/LUCENE-10423
>             Project: Lucene - Core
>          Issue Type: Bug
>            Reporter: Robert Muir
>            Priority: Major
>
> Followup to LUCENE-10421
> Code in the library shouldn't rely on wall-clock time. If you look at all the 
> places doing this, they are basically all bad news.
> Most tests doing this are "iterating for some amount of wall-clock time" 
> which causes them to instead just be non-reproducible. These should be 
> changed to use a fixed number of loop iterations instead.
> It would really be great to ban this stuff in forbidden apis. It is even in 
> the configuration file, just currently commented out.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to