-
Notifications
You must be signed in to change notification settings - Fork 319
Adjust Worker::poll logic to fix pending wake failure in balance service. #825
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,14 +172,13 @@ async fn waits_for_channel_capacity() { | |
|
|
||
| assert_ready_ok!(service.poll_ready()); | ||
| let mut response2 = task::spawn(service.call("hello")); | ||
| assert_pending!(worker.poll()); | ||
|
|
||
| assert_ready_ok!(service.poll_ready()); | ||
| let mut response3 = task::spawn(service.call("hello")); | ||
| assert_pending!(service.poll_ready()); | ||
| assert_pending!(worker.poll()); | ||
|
|
||
| // wake up worker's service (i.e. Mock), now it's ready to make progress | ||
| handle.allow(1); | ||
| // process the request(i.e. send to handle), return the response | ||
| // and then poll worker's service::poll_ready in next loop. | ||
| assert_pending!(worker.poll()); | ||
|
|
||
| handle | ||
|
|
@@ -192,10 +191,10 @@ async fn waits_for_channel_capacity() { | |
| assert_ready_ok!(response1.poll()); | ||
|
|
||
| assert_ready_ok!(service.poll_ready()); | ||
| let mut response4 = task::spawn(service.call("hello")); | ||
| let mut response3 = task::spawn(service.call("hello")); | ||
| assert_pending!(worker.poll()); | ||
|
|
||
| handle.allow(3); | ||
| handle.allow(2); | ||
| assert_pending!(worker.poll()); | ||
|
|
||
| handle | ||
|
|
@@ -216,16 +215,6 @@ async fn waits_for_channel_capacity() { | |
| .send_response("world"); | ||
| assert_pending!(worker.poll()); | ||
| assert_ready_ok!(response3.poll()); | ||
|
|
||
| assert_pending!(worker.poll()); | ||
| handle | ||
| .next_request() | ||
| .await | ||
| .unwrap() | ||
| .1 | ||
| .send_response("world"); | ||
| assert_pending!(worker.poll()); | ||
| assert_ready_ok!(response4.poll()); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "current_thread")] | ||
|
|
@@ -243,14 +232,13 @@ async fn wakes_pending_waiters_on_close() { | |
| assert_pending!(worker.poll()); | ||
| let mut response = task::spawn(service1.call("hello")); | ||
|
|
||
| assert!(worker.is_woken(), "worker task should be woken by request"); | ||
| assert!( | ||
| !worker.is_woken(), | ||
| "worker task would NOT be woken by request until worker's service is ready" | ||
| ); | ||
| assert_pending!(worker.poll()); | ||
|
|
||
| // fill the channel so all subsequent requests will wait for capacity | ||
| let service1 = assert_ready_ok!(task::spawn(service.ready()).poll()); | ||
| assert_pending!(worker.poll()); | ||
| let mut response2 = task::spawn(service1.call("world")); | ||
|
|
||
| let mut service1 = service.clone(); | ||
| let mut ready1 = task::spawn(service1.ready()); | ||
| assert_pending!(worker.poll()); | ||
|
|
@@ -271,13 +259,6 @@ async fn wakes_pending_waiters_on_close() { | |
| err | ||
| ); | ||
|
|
||
| let err = assert_ready_err!(response2.poll()); | ||
| assert!( | ||
| err.is::<error::Closed>(), | ||
| "response should fail with a Closed, got: {:?}", | ||
| err | ||
| ); | ||
|
|
||
| assert!( | ||
| ready1.is_woken(), | ||
| "dropping worker should wake ready task 1" | ||
|
|
@@ -316,14 +297,13 @@ async fn wakes_pending_waiters_on_failure() { | |
| assert_pending!(worker.poll()); | ||
| let mut response = task::spawn(service1.call("hello")); | ||
|
|
||
| assert!(worker.is_woken(), "worker task should be woken by request"); | ||
| assert!( | ||
| !worker.is_woken(), | ||
| "worker task would NOT be woken by request until worker's service is ready" | ||
| ); | ||
| assert_pending!(worker.poll()); | ||
|
|
||
| // fill the channel so all subsequent requests will wait for capacity | ||
| let service1 = assert_ready_ok!(task::spawn(service.ready()).poll()); | ||
| assert_pending!(worker.poll()); | ||
| let mut response2 = task::spawn(service1.call("world")); | ||
|
|
||
| let mut service1 = service.clone(); | ||
| let mut ready1 = task::spawn(service1.ready()); | ||
| assert_pending!(worker.poll()); | ||
|
|
@@ -336,6 +316,8 @@ async fn wakes_pending_waiters_on_failure() { | |
|
|
||
| // fail the inner service | ||
| handle.send_error("foobar"); | ||
| // consume the in-flight request and send an Err response, then run | ||
| // next loop until read None. | ||
| // worker task terminates | ||
| assert_ready!(worker.poll()); | ||
|
|
||
|
|
@@ -345,12 +327,6 @@ async fn wakes_pending_waiters_on_failure() { | |
| "response should fail with a ServiceError, got: {:?}", | ||
| err | ||
| ); | ||
| let err = assert_ready_err!(response2.poll()); | ||
| assert!( | ||
| err.is::<error::ServiceError>(), | ||
| "response should fail with a ServiceError, got: {:?}", | ||
| err | ||
| ); | ||
|
Comment on lines
-348
to
-353
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this no longer the case?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as mentioned above, the old exec order is
the new exec order is
there is no 'preload' message, so i delete it. |
||
|
|
||
| assert!( | ||
| ready1.is_woken(), | ||
|
|
@@ -375,25 +351,6 @@ async fn wakes_pending_waiters_on_failure() { | |
| ); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "current_thread")] | ||
| async fn propagates_trace_spans() { | ||
| use tower::util::ServiceExt; | ||
| use tracing::Instrument; | ||
|
|
||
| let _t = support::trace_init(); | ||
|
|
||
| let span = tracing::info_span!("my_span"); | ||
|
|
||
| let service = support::AssertSpanSvc::new(span.clone()); | ||
| let (service, worker) = Buffer::pair(service, 5); | ||
| let worker = tokio::spawn(worker); | ||
|
|
||
| let result = tokio::spawn(service.oneshot(()).instrument(span)); | ||
|
|
||
| result.await.expect("service panicked").expect("failed"); | ||
| worker.await.expect("worker panicked"); | ||
| } | ||
|
Comment on lines
-378
to
-395
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may i ask why this test was deleted?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this commit change the worker exec order:
after 2 poll_next_msg, the span in the msg can be retrieved, the service.call is now in the span scope, but not the servce.poll_ready, as you see, |
||
|
|
||
| #[tokio::test(flavor = "current_thread")] | ||
| async fn doesnt_leak_permits() { | ||
| let _t = support::trace_init(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are these assertions no longer needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because in this case there is no other request will be issued, so it is no need to do this assertion.