Skip to content

Commit 7fbb235

Browse files
committed
Thanks Code Rabbit
Signed-off-by: Graham King <grahamk@nvidia.com>
1 parent f4f8598 commit 7fbb235

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/runtime/src/storage/kv/file.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ impl FileStore {
6565
let ttl = self.shortest_ttl();
6666
let keep_alive_interval = cmp::max(ttl / 3, MIN_KEEP_ALIVE);
6767

68+
// Check before and after the sleep
69+
if self.cancel_token.is_cancelled() {
70+
break;
71+
}
72+
6873
thread::sleep(keep_alive_interval);
74+
6975
if self.cancel_token.is_cancelled() {
7076
break;
7177
}
@@ -485,7 +491,8 @@ mod tests {
485491
async fn test_entries_full_path() {
486492
let t = tempfile::tempdir().unwrap();
487493

488-
let m = FileStore::new(CancellationToken::new(), t.path());
494+
let cancel_token = CancellationToken::new();
495+
let m = FileStore::new(cancel_token.clone(), t.path());
489496
let bucket = m.get_or_create_bucket("v1/tests", None).await.unwrap();
490497
let _ = bucket
491498
.insert(&Key::new("key1/multi/part".to_string()), "value1".into(), 0)
@@ -497,6 +504,7 @@ mod tests {
497504
.unwrap();
498505
let entries = bucket.entries().await.unwrap();
499506
let keys: HashSet<Key> = entries.into_keys().collect();
507+
cancel_token.cancel(); // stop the background thread
500508

501509
assert!(keys.contains(&Key::new("v1/tests/key1/multi/part".to_string())));
502510
assert!(keys.contains(&Key::new("v1/tests/key2".to_string())));

0 commit comments

Comments
 (0)