tests(client): fix flaking conn_reset test
This commit is contained in:
		| @@ -1,8 +1,10 @@ | |||||||
| extern crate pretty_env_logger; | extern crate pretty_env_logger; | ||||||
|  |  | ||||||
|  | use std::time::Duration; | ||||||
|  |  | ||||||
| use futures::Async; | use futures::Async; | ||||||
| use futures::future::poll_fn; | use futures::future::poll_fn; | ||||||
| use tokio::reactor::Core; | use tokio::reactor::{Core, Timeout}; | ||||||
|  |  | ||||||
| use mock::MockConnector; | use mock::MockConnector; | ||||||
| use super::*; | use super::*; | ||||||
| @@ -68,6 +70,11 @@ fn conn_reset_after_write() { | |||||||
|             Ok(Async::Ready(())) |             Ok(Async::Ready(())) | ||||||
|         }); |         }); | ||||||
|         core.run(res1.join(srv1)).expect("res1"); |         core.run(res1.join(srv1)).expect("res1"); | ||||||
|  |  | ||||||
|  |         // run a tiny timeout just to spin the core, so that the pool | ||||||
|  |         // can tell the socket is ready again | ||||||
|  |         let timeout = Timeout::new(Duration::from_millis(50), &core.handle()).unwrap(); | ||||||
|  |         core.run(timeout).unwrap(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     let res2 = client.get("http://mock.local/a".parse().unwrap()); |     let res2 = client.get("http://mock.local/a".parse().unwrap()); | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								src/mock.rs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/mock.rs
									
									
									
									
									
								
							| @@ -421,10 +421,10 @@ impl Service for MockConnector { | |||||||
|     fn call(&self, uri: Uri) -> Self::Future { |     fn call(&self, uri: Uri) -> Self::Future { | ||||||
|         use futures::future; |         use futures::future; | ||||||
|         trace!("mock connect: {:?}", uri.as_ref()); |         trace!("mock connect: {:?}", uri.as_ref()); | ||||||
|         let mock = self.mocks.borrow_mut() |         let mut mocks = self.mocks.borrow_mut(); | ||||||
|             .get_mut(uri.as_ref()) |         let mocks = mocks.get_mut(uri.as_ref()) | ||||||
|             .expect(&format!("unknown mocks uri: {:?}", uri.as_ref())) |             .expect(&format!("unknown mocks uri: {:?}", uri.as_ref())); | ||||||
|             .remove(0); |         assert!(!mocks.is_empty(), "no additional mocks for {:?}", uri.as_ref()); | ||||||
|         future::ok(mock) |         future::ok(mocks.remove(0)) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user