Skip to content

Commit 4b0793b

Browse files
committed
refactor load genesis ledger test
1 parent 610be95 commit 4b0793b

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

src/test/archive/archive_node_tests/load_genesis_ledger.ml

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,54 +21,57 @@ type t = Mina_automation_fixture.Archive.before_bootstrap
2121

2222
let postgres_user_name = "postgres"
2323

24-
(* val test_case : t -> test_result Deferred.Or_error.t *)
2524
let test_case (test_data : t) =
2625
let config =
2726
{ test_data.config with config_file = "genesis_ledgers/mainnet.json" }
2827
in
2928
let logger = Logger.create () in
30-
let log_file = test_data.temp_dir ^ "/archive.load_genesis_ledger.log" in
29+
let log_file = test_data.temp_dir ^/ "archive.load_genesis_ledger.log" in
3130
let%bind process = Archive.of_config config |> Archive.start in
3231
Archive.Process.start_logging process ~log_file ;
3332

34-
let max_postgres_memory = 4000.0 in
3533
let sleep_duration = Time.Span.of_sec 10.0 in
36-
let max_archive_memory = 1000.0 in
34+
35+
let max_archive_memory = 1024.0 in
36+
let max_postgres_memory = 4096.0 in
3737

3838
(* Set the duration for the archive process *)
39-
let duration = Time.Span.of_min 10.0 in
39+
let expected_duration = Time.Span.of_min 10.0 in
4040

4141
[%log info] "Max Archive Memory: %s MiB" (Float.to_string max_archive_memory) ;
4242
[%log info] "Max Postgres Memory: %s MiB"
4343
(Float.to_string max_postgres_memory) ;
4444
[%log info] "Sleep Duration: %s" (Time.Span.to_string sleep_duration) ;
4545

46-
let end_time = Time.add (Time.now ()) duration in
46+
let start_time = Time.now () in
4747
let rec loop () =
48-
if Time.is_later (Time.now ()) ~than:end_time then Deferred.return ()
48+
let executed_duration = Time.(diff (now ()) start_time) in
49+
if Time.Span.(executed_duration > expected_duration) then
50+
return Mina_automation_fixture.Intf.Passed
4951
else
50-
let memory = Archive.Process.get_memory_usage_mib process in
51-
let%bind () =
52-
match memory with
53-
| Some mem ->
54-
[%log info] "Archive Memory usage: %s MiB" (Float.to_string mem) ;
55-
if Float.( > ) mem max_archive_memory then
56-
failwith "Archive process memory exceeds 1GB"
57-
else Deferred.return ()
58-
| None ->
59-
failwith "Error getting memory usage for archive process"
60-
in
61-
let%bind memory =
62-
Utils.get_memory_usage_mib_of_user_process postgres_user_name
63-
in
64-
[%log info] "Postgres Memory usage: %s MiB" (Float.to_string memory) ;
65-
if Float.( > ) memory max_postgres_memory then
66-
failwith "Postgres memory exceeds 4GB" ;
67-
let%bind () = Clock.after sleep_duration in
68-
loop ()
52+
match Archive.Process.get_memory_usage_mib process with
53+
| Some mem when Float.( > ) mem max_archive_memory ->
54+
Mina_automation_fixture.Intf.Failed
55+
(Error.create "Archive process memory exceeds 1GiB" mem
56+
Float.sexp_of_t )
57+
|> return
58+
| None ->
59+
Mina_automation_fixture.Intf.Failed
60+
(Error.createf "Error getting memory usage for archive process")
61+
|> return
62+
| Some mem ->
63+
[%log info] "Archive Memory usage: %s MiB" (Float.to_string mem) ;
64+
let%bind memory =
65+
Utils.get_memory_usage_mib_of_user_process postgres_user_name
66+
in
67+
if Float.( > ) memory max_postgres_memory then
68+
Mina_automation_fixture.Intf.Failed
69+
(Error.create "Postgres memory exceeds 4GiB" memory
70+
Float.sexp_of_t )
71+
|> return
72+
else (
73+
[%log info] "Postgres Memory usage: %s MiB" (Float.to_string memory) ;
74+
let%bind () = Clock.after sleep_duration in
75+
loop () )
6976
in
70-
match%map Monitor.try_with loop with
71-
| Ok () ->
72-
Mina_automation_fixture.Intf.Passed
73-
| Error exn ->
74-
Failed (Error.of_exn exn)
77+
loop ()

0 commit comments

Comments
 (0)