test poolable against s3

This commit is contained in:
Martin Algesten
2018-06-30 23:05:40 +02:00
parent e2686e3bd5
commit 548b5d80c2
4 changed files with 67 additions and 1 deletions

View File

@@ -20,6 +20,20 @@ impl ConnectionPool {
pub fn try_get_connection(&mut self, url: &Url) -> Option<Stream> {
self.recycle.remove(&PoolKey::new(url))
}
#[cfg(test)]
pub fn len(&self) -> usize {
self.recycle.len()
}
#[cfg(test)]
pub fn get(&self, hostname: &str, port: u16) -> Option<&Stream> {
let key = PoolKey {
hostname: hostname.into(),
port,
};
self.recycle.get(&key)
}
}
#[derive(Debug, PartialEq, Clone, Eq, Hash)]
@@ -66,12 +80,16 @@ impl<R: Read + Sized> PoolReturnRead<R> {
if let Some(agent) = state.as_mut() {
unsafe {
let stream = *Box::from_raw(self.stream);
self.stream = ::std::ptr::null_mut();
if !stream.is_poolable() {
// just let it deallocate
return;
}
// insert back into pool
let key = PoolKey::new(&unit.url);
agent.pool().recycle.insert(key, stream);
}
};
self.stream = ::std::ptr::null_mut();
}
}