Skip to content

Commit 2adc928

Browse files
glyhdannywillems
authored andcommitted
FIX test: LMDB diskcache wouldn't clear the cache eagerly on GC now
1 parent 783f2d5 commit 2adc928

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/lib/disk_cache/lmdb/disk_cache.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ let%test_module "disk_cache lmdb" =
7878
( module struct
7979
include Disk_cache_test_lib.Make_extended (Make)
8080

81-
let%test_unit "remove data on gc" = remove_data_on_gc ()
81+
let%test_unit "remove data on gc" = remove_data_on_gc ~gc_strict:false ()
8282

8383
let%test_unit "simple read/write (with iteration)" =
8484
simple_write_with_iteration ()

src/lib/disk_cache/test_lib/disk_cache_test_lib.ml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ module type S = sig
2323

2424
val initialization_special_cases : unit -> unit
2525

26-
val remove_data_on_gc : unit -> unit
26+
(** [remove_data_on_gc_impl ?gc_strict ())] test behavior of cache on GC.
27+
If [gc_strict] is set to [false], then we won't check if the cache is
28+
empty after GC.
29+
*)
30+
val remove_data_on_gc : ?gc_strict:bool -> unit -> unit
2731
end
2832

2933
module type S_extended = sig
@@ -77,7 +81,7 @@ module Make_impl (Cache : Disk_cache_intf.S_with_count with module Data := Mock)
7781
File_system.with_temp_dir "disk_cache"
7882
~f:(simple_write_impl ?additional_checks)
7983

80-
let remove_data_on_gc_impl tmp_dir =
84+
let remove_data_on_gc_impl ~gc_strict tmp_dir =
8185
let%map cache = initialize_cache_or_fail tmp_dir ~logger in
8286

8387
let proof = Mock.{ proof = "dummy" } in
@@ -91,16 +95,19 @@ module Make_impl (Cache : Disk_cache_intf.S_with_count with module Data := Mock)
9195
[%test_eq: string] proof.proof proof_from_cache.proof
9296
~message:"invalid proof from cache" ) ;
9397

94-
Gc.compact () ;
98+
match gc_strict with
99+
| Some false ->
100+
()
101+
| _ ->
102+
Gc.compact () ;
103+
[%test_eq: int] (Cache.count cache) 0
104+
~message:"cache should be empty after garbage collector run"
95105

96-
[%test_eq: int] (Cache.count cache) 0
97-
~message:"cache should be empty after garbage collector run"
98-
99-
let remove_data_on_gc () =
106+
let remove_data_on_gc ?gc_strict () =
100107
Async.Thread_safe.block_on_async_exn
101108
@@ fun () ->
102109
File_system.with_temp_dir "disk_cache-remove_data_on_gc"
103-
~f:remove_data_on_gc_impl
110+
~f:(remove_data_on_gc_impl ~gc_strict)
104111

105112
let initialize_and_expect_failure path ~logger =
106113
let%bind cache_res = Cache.initialize path ~logger in

0 commit comments

Comments
 (0)