Skip to content

Commit 597e7af

Browse files
committed
Add accurate timeout for inactive pool connection
Signed-off-by: Sergey Minaev <[email protected]>
1 parent cd84d27 commit 597e7af

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

libindy/src/services/pool/networker.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ impl PoolConnection {
220220
.min_by(|&(_, ref val1), &(_, ref val2)| val1.cmp(&val2)) {
221221
((req_id.to_string(), node_alias.to_string()), timeout)
222222
} else {
223-
(("".to_string(), "".to_string()), POOL_ACK_TIMEOUT * 1000)
223+
let time_from_start: Duration = time::now() - self.time_created;
224+
(("".to_string(), "".to_string()), POOL_CON_ACTIVE_TO * 1000 - time_from_start.num_milliseconds())
224225
}
225226
}
226227

@@ -683,14 +684,18 @@ pub mod networker_tests {
683684

684685
let mut conn = PoolConnection::new(vec![rn]);
685686

686-
let timeout = conn.get_timeout();
687-
assert_eq!((("".to_string(), "".to_string()), POOL_ACK_TIMEOUT * 1000), timeout);
687+
let ((req_id, node_alias), timeout) = conn.get_timeout();
688+
assert_eq!(req_id, "".to_string());
689+
assert_eq!(node_alias, "".to_string());
690+
assert!(POOL_CON_ACTIVE_TO * 1000 - 10 <= timeout);
691+
assert!(POOL_CON_ACTIVE_TO * 1000 >= timeout);
688692

689693
conn.send_request(Some(NetworkerEvent::SendOneRequest(MESSAGE.to_string(), REQ_ID.to_string()))).unwrap();
690694

691695
let (id, timeout) = conn.get_timeout();
692696
assert_eq!((REQ_ID.to_string(), NODE_NAME.to_string()), id);
693-
assert_ne!(POOL_ACK_TIMEOUT * 1000, timeout)
697+
assert!(POOL_ACK_TIMEOUT * 1000 - 10 <= timeout);
698+
assert!(POOL_ACK_TIMEOUT * 1000 >= timeout);
694699
}
695700

696701
#[test]

0 commit comments

Comments
 (0)