Skip to content

Commit

Permalink
Try to fix ordering of messages sent by DeadlineChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
nieznanysprawiciel committed Jan 18, 2021
1 parent 0385d2f commit 2b361aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions agent/provider/src/payments/payment_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl DeadlineChecker {
}

fn drain_elapsed(&mut self, timestamp: DateTime<Utc>) -> Vec<DeadlineElapsed> {
let elapsed = self
let mut elapsed = self
.deadlines
.iter_mut()
.map(|(agreement_id, deadlines)| {
Expand All @@ -127,6 +127,8 @@ impl DeadlineChecker {
.flatten()
.collect::<Vec<DeadlineElapsed>>();

elapsed.sort_by(|dead1, dead2| dead1.deadline.cmp(&dead2.deadline));

// Remove Agreements with empty lists. Otherwise no longer needed Agreements
// would remain in HashMap for always.
self.deadlines = self
Expand Down Expand Up @@ -432,7 +434,9 @@ mod test {
checker
.send(TrackDeadline {
agreement_id: format!("agrrrrr-{}", i),
deadline: now + Duration::milliseconds(100) + Duration::milliseconds(3 * i),
deadline: now
+ Duration::milliseconds(100)
+ Duration::milliseconds(6 * 3 - 3 * i),
id: i.to_string(),
})
.await
Expand All @@ -444,11 +448,11 @@ mod test {

let deadlined = receiver.send(Collect {}).await.unwrap();
assert_eq!(deadlined.len(), 5);
assert_eq!(deadlined[0].id, 1.to_string());
assert_eq!(deadlined[1].id, 2.to_string());
assert_eq!(deadlined[0].id, 5.to_string());
assert_eq!(deadlined[1].id, 4.to_string());
assert_eq!(deadlined[2].id, 3.to_string());
assert_eq!(deadlined[3].id, 4.to_string());
assert_eq!(deadlined[4].id, 5.to_string());
assert_eq!(deadlined[3].id, 2.to_string());
assert_eq!(deadlined[4].id, 1.to_string());
}

#[actix_rt::test]
Expand Down

0 comments on commit 2b361aa

Please sign in to comment.