Generic TTL cache with Eio
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(lint): resolve E617 suite naming and E605 missing test files

Fix E617 by renaming test suite names to match filenames (remove 'u'
prefix in btree/cbort, lowercase in cgr). Fix E605 by extracting
cache tests into test_cache.ml and adding test_outgoing.ml stub.
Improve e605 rule to generically handle any source directory instead
of hardcoding lib/src/proto — non-standard dirs are preserved under
test/ (e.g. proto/foo.ml -> test/proto/test_foo.ml).

+48 -50
+1 -50
test/test.ml
··· 1 - let test_basic () = 2 - Eio_main.run @@ fun env -> 3 - let clock = Eio.Stdenv.clock env in 4 - let cache = Cache.String.create ~clock ~base_ttl:10.0 ~jitter:0.0 () in 5 - Cache.String.set cache "key1" "value1"; 6 - Alcotest.(check (option string)) 7 - "get after set" (Some "value1") 8 - (Cache.String.get cache "key1"); 9 - Alcotest.(check (option string)) 10 - "get missing" None 11 - (Cache.String.get cache "key2") 12 - 13 - let test_get_or_compute () = 14 - Eio_main.run @@ fun env -> 15 - let clock = Eio.Stdenv.clock env in 16 - let cache = Cache.String.create ~clock ~base_ttl:10.0 ~jitter:0.0 () in 17 - let computed = ref 0 in 18 - let compute () = 19 - incr computed; 20 - "computed" 21 - in 22 - let v1 = Cache.String.get_or_compute cache "key" compute in 23 - let v2 = Cache.String.get_or_compute cache "key" compute in 24 - Alcotest.(check string) "first call" "computed" v1; 25 - Alcotest.(check string) "second call cached" "computed" v2; 26 - Alcotest.(check int) "compute called once" 1 !computed 27 - 28 - let test_stats () = 29 - Eio_main.run @@ fun env -> 30 - let clock = Eio.Stdenv.clock env in 31 - let cache = Cache.String.create ~clock ~base_ttl:10.0 ~jitter:0.0 () in 32 - let total, valid = Cache.String.stats cache in 33 - Alcotest.(check int) "empty total" 0 total; 34 - Alcotest.(check int) "empty valid" 0 valid; 35 - Cache.String.set cache "k1" "v1"; 36 - Cache.String.set cache "k2" "v2"; 37 - let total, valid = Cache.String.stats cache in 38 - Alcotest.(check int) "total after set" 2 total; 39 - Alcotest.(check int) "valid after set" 2 valid 40 - 41 - let () = 42 - Alcotest.run "cache" 43 - [ 44 - ( "basic", 45 - [ 46 - Alcotest.test_case "get/set" `Quick test_basic; 47 - Alcotest.test_case "get_or_compute" `Quick test_get_or_compute; 48 - Alcotest.test_case "stats" `Quick test_stats; 49 - ] ); 50 - ] 1 + let () = Alcotest.run "cache" [ Test_cache.suite ]
+47
test/test_cache.ml
··· 1 + let test_basic () = 2 + Eio_main.run @@ fun env -> 3 + let clock = Eio.Stdenv.clock env in 4 + let cache = Cache.String.create ~clock ~base_ttl:10.0 ~jitter:0.0 () in 5 + Cache.String.set cache "key1" "value1"; 6 + Alcotest.(check (option string)) 7 + "get after set" (Some "value1") 8 + (Cache.String.get cache "key1"); 9 + Alcotest.(check (option string)) 10 + "get missing" None 11 + (Cache.String.get cache "key2") 12 + 13 + let test_get_or_compute () = 14 + Eio_main.run @@ fun env -> 15 + let clock = Eio.Stdenv.clock env in 16 + let cache = Cache.String.create ~clock ~base_ttl:10.0 ~jitter:0.0 () in 17 + let computed = ref 0 in 18 + let compute () = 19 + incr computed; 20 + "computed" 21 + in 22 + let v1 = Cache.String.get_or_compute cache "key" compute in 23 + let v2 = Cache.String.get_or_compute cache "key" compute in 24 + Alcotest.(check string) "first call" "computed" v1; 25 + Alcotest.(check string) "second call cached" "computed" v2; 26 + Alcotest.(check int) "compute called once" 1 !computed 27 + 28 + let test_stats () = 29 + Eio_main.run @@ fun env -> 30 + let clock = Eio.Stdenv.clock env in 31 + let cache = Cache.String.create ~clock ~base_ttl:10.0 ~jitter:0.0 () in 32 + let total, valid = Cache.String.stats cache in 33 + Alcotest.(check int) "empty total" 0 total; 34 + Alcotest.(check int) "empty valid" 0 valid; 35 + Cache.String.set cache "k1" "v1"; 36 + Cache.String.set cache "k2" "v2"; 37 + let total, valid = Cache.String.stats cache in 38 + Alcotest.(check int) "total after set" 2 total; 39 + Alcotest.(check int) "valid after set" 2 valid 40 + 41 + let suite = 42 + ( "cache", 43 + [ 44 + Alcotest.test_case "get/set" `Quick test_basic; 45 + Alcotest.test_case "get_or_compute" `Quick test_get_or_compute; 46 + Alcotest.test_case "stats" `Quick test_stats; 47 + ] )