Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: be able to query time remaining on a test #1492

Open
carl-mastrangelo opened this issue Dec 4, 2017 · 2 comments
Open

Feature request: be able to query time remaining on a test #1492

carl-mastrangelo opened this issue Dec 4, 2017 · 2 comments
Labels

Comments

@carl-mastrangelo
Copy link

When using the Timeout rule, it would sometimes be convenient to be able to get how much time is remaining in the test. That would allow code that calls Future.get(long, Timeout), CountDownLatch.await(long, Timeunit), Thread.sleep(long), Object.wait(long), and any other code that waits to cooperate with the testing framework.

The use case for this is when bumping the timeout for a test, it becomes necessary to update all of the other uses of time. For example:

@Rule public final Timeout timeout = Timeout.seconds(5);

@Test public void foo() {
  future.get(5, Timeunit.SECONDS);
 // ...
}

Suppose this test is slow or possibly flaky. Just incrementing the timeout to be higher won't work because the get is still going to fail early. Modifying the call to be future.get(Integer.MAX_VALUE, TimeUnit.SECONDS) is cumbersome and doesn't convey the intent of the test. As a strawman API, I would suggest something like the following:

@Rule public final Timeout timeout = Timeout.seconds(5);

@Test public void foo() {
  future.get(timeout.getRemaining(Timeunit.SECONDS), Timeunit.SECONDS);
 // ...
}

It would be okay for this to not be exactly accurate (as compared with "deadlines"). It's more about letting the reader know that the waiting will happen to the end of the test, rather than some seemingly arbitrary duration.

@stefanbirkner
Copy link
Contributor

Timeout has a method getTimeout. Does this method already fix your problem?

@Rule public final Timeout timeout = Timeout.seconds(5);

@Test public void foo() {
  future.get(
    timeout.getTimeout(Timeunit.SECONDS),
    Timeunit.SECONDS
  );
  // ...
}

Of course the timeout is more than getRemaining but you can change the timeout and everything else changes accordingly.

@carl-mastrangelo
Copy link
Author

getTimeout is a partial solution. I can't think of any problems with using it, but my gut feeling is that the remaining time would be preferred.

As a side note, how would that work when used in conjunction with DisableOnDebug ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants