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

Support for timeout propagation in async requests #617

Merged
merged 2 commits into from Mar 24, 2022
Merged

Conversation

dxxyy
Copy link
Contributor

@dxxyy dxxyy commented Mar 21, 2022

Give the possibility to clients to specify a timeout while performing async requests.
More details in #616

Copy link
Contributor

@scottf scottf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

* @param timeout the time to wait for a response
* @return a Future for the response, which may be cancelled on error or timed out
*/
CompletableFuture<Message> requestWithTimeout(Message message, Duration timeout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For parity, I think we'd also want:

CompletableFuture<Message> requestWithTimeout(String subject, byte[] body, Duration timeout);

wdyt @scottf ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dxxyy please add.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do!

@@ -239,6 +239,39 @@ public void testRequireCleanupOnTimeoutNoNoResponders() throws IOException, Inte
}
}

@Test
public void testRequireCleanupOnTimeoutCleanCompletable() throws IOException, InterruptedException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see some tests that also succeed, and then fail with a timeout. This one does test failure w/ cleanup - but would like to see that the right exception is thrown.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! For a "succeed and then fail" what do you mean exactly? I see that the timeout of the NatsRequestCompletableFuture is considered only upon cleanup.

I can add an additional test that triggers the timeout exception, coming from the CompletableFuture.
Something like:
assertThrows(TimeoutException.class, () -> nc.requestWithTimeout(nm, Duration.ofMillis(cleanupInterval)).get(100, TimeUnit.MILLISECONDS));

Thanks for your reply

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this this is request/reply, the timeout is suggesting how long to wait for a response. Test actually getting a response back and also not getting a response back. Although No responders may come into play. What do other tests for the default timeout do?

Copy link
Contributor Author

@dxxyy dxxyy Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added more tests and api update. thx for the clarification

@ColinSullivan1
Copy link
Member

Thanks for contributing! I offered a few suggestions but will defer to @scottf.

@scottf scottf self-requested a review March 21, 2022 19:13
Copy link
Contributor

@scottf scottf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@ColinSullivan1 ColinSullivan1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the contribution!

@dxxyy
Copy link
Contributor Author

dxxyy commented Mar 24, 2022

I see 5 failures in the build, after the pushed merge commit:

  1. JetStreamPushTests > testPushDurableNullDeliver
  2. JetStreamPushTests > testPushEphemeralWithDeliver
  3. JetStreamGeneralTests > testBindPush
  4. KeyValueTests > testCreateAndUpdate
  5. KeyValueTests > testWatch

-> Theses are not linked to the change (and the new exposed API), let me know if I need to take some actions in order to have this merged.

Thanks!

@scottf
Copy link
Contributor

scottf commented Mar 24, 2022

I see 5 failures in the build, after the pushed merge commit:
Yes they are not related to this PR. They are "flappers", exacerbated by extremely slow GHA runners, but they are functional and build fine in other PR's and the main. It's a crapshoot sometimes.
This PR will get merged I've just been in the middle of other stuff.

@scottf
Copy link
Contributor

scottf commented Mar 24, 2022

Using admin merge because GHA/coveralls isn't reporting after hours of waiting.

@scottf scottf merged commit 2c1d74b into nats-io:main Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants