Skip to content

Commit b2ca590

Browse files
committed
Fix flaky test
1 parent 183fcc5 commit b2ca590

2 files changed

Lines changed: 4 additions & 12 deletions

File tree

quickwit/quickwit-ingest/src/ingest_v2/idle.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ mod tests {
8989
async fn test_close_idle_shards_run() {
9090
let (_temp_dir, state) = IngesterState::for_test().await;
9191
let weak_state = state.weak();
92-
let idle_shard_timeout = Duration::from_millis(200);
92+
let idle_shard_timeout = RUN_INTERVAL_PERIOD * 4;
9393
let join_handle = CloseIdleShardsTask::spawn(weak_state, idle_shard_timeout);
9494

9595
let mut state_guard = state.lock_partially().await.unwrap();
@@ -111,7 +111,6 @@ mod tests {
111111
"test-source".to_string(),
112112
ShardId::from(2),
113113
)
114-
.with_last_write(now - idle_shard_timeout / 2)
115114
.build();
116115
let queue_id_02 = shard_02.queue_id();
117116
state_guard.shards.insert(queue_id_02.clone(), shard_02);

quickwit/quickwit-ingest/src/ingest_v2/state.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,9 @@ impl InnerIngesterState {
8383
.filter(|shard| {
8484
shard.is_open() && shard.index_uid == *index_uid && shard.source_id == *source_id
8585
})
86-
// We use reduce here because we need a mutable borrow of the shard, since
87-
// available_permits() calls refill, which is a mutator.
88-
.reduce(|best, current| {
89-
if current.rate_limiter.available_permits() > best.rate_limiter.available_permits()
90-
{
91-
current
92-
} else {
93-
best
94-
}
95-
})
86+
.map(|shard| (shard.rate_limiter.available_permits(), shard))
87+
.max_by_key(|(available_permits, _)| *available_permits)
88+
.map(|(_, shard)| shard)
9689
}
9790
}
9891

0 commit comments

Comments
 (0)