Skip to content

Commit

Permalink
fix buffer test that isn't quite deterministic
Browse files Browse the repository at this point in the history
Signed-off-by: Eliza Weisman <[email protected]>
  • Loading branch information
hawkw committed Oct 27, 2020
1 parent ff3dc34 commit 0cddf0f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tower/tests/buffer/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,56 +142,74 @@ async fn response_future_when_worker_is_dropped_early() {

#[tokio::test]
async fn waits_for_channel_capacity() {
let (mut service, mut handle) = new_service_with_bound(3);
let (service, mut handle) = mock::pair::<&'static str, &'static str>();

let (service, worker) = Buffer::pair(service, 3);

let mut service = mock::Spawn::new(service);
let mut worker = task::spawn(worker);

// keep requests in the worker
handle.allow(0);
assert_ready_ok!(service.poll_ready());
let mut response1 = task::spawn(service.call("hello"));
assert_pending!(worker.poll());

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());

handle.allow(1);
assert_pending!(worker.poll());

handle
.next_request()
.await
.unwrap()
.1
.send_response("world");
assert_pending!(worker.poll());
assert_ready_ok!(response1.poll());

assert_ready_ok!(service.poll_ready());
let mut response4 = task::spawn(service.call("hello"));
assert_pending!(worker.poll());

handle.allow(3);
assert_pending!(worker.poll());

handle
.next_request()
.await
.unwrap()
.1
.send_response("world");
assert_pending!(worker.poll());
assert_ready_ok!(response2.poll());

assert_pending!(worker.poll());
handle
.next_request()
.await
.unwrap()
.1
.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());
}

Expand Down

0 comments on commit 0cddf0f

Please sign in to comment.