Skip to content

Commit d943d15

Browse files
committed
Nit(Archive Node Tests): some simplifications
1 parent c7f2013 commit d943d15

File tree

5 files changed

+23
-31
lines changed

5 files changed

+23
-31
lines changed

src/test/archive/archive_node_tests/archive_precomputed_blocks_test.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ let perf_metrics_to_yojson metrics =
6969
@raises Failure if a log line cannot be parsed as valid JSON
7070
@raises exn if required metadata fields ("elapsed" or "label") are missing *)
7171
let extract_perf_metrics log_file =
72-
let open Deferred.Let_syntax in
7372
let%bind lines = Reader.file_lines log_file in
7473
let perf_metrics =
7574
List.filter_map lines ~f:(fun line ->
@@ -122,7 +121,7 @@ let test_case (test_data : t) =
122121
unpack_precomputed_blocks test_data.network_data
123122
~temp_dir:test_data.temp_dir
124123
in
125-
let log_file = output ^ "/precomputed_blocks_test.log" in
124+
let log_file = output ^/ "precomputed_blocks_test.log" in
126125
Archive.Process.start_logging test_data.archive ~log_file ;
127126
let%bind () =
128127
Daemon.archive_blocks_from_files daemon.executor
@@ -142,7 +141,7 @@ let test_case (test_data : t) =
142141
archive_uri test_data.temp_dir
143142
in
144143

145-
let%bind perf_data = extract_perf_metrics log_file in
144+
let%map perf_data = extract_perf_metrics log_file in
146145
perf_metrics_to_yojson perf_data |> Yojson.to_file "archive.perf" ;
147146

148-
Deferred.Or_error.return Mina_automation_fixture.Intf.Passed
147+
Ok Mina_automation_fixture.Intf.Passed

src/test/archive/archive_node_tests/common.ml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ open Mina_automation
1515
@return Unit deferred that completes when assertion passes *)
1616
let assert_replayer_run_against_last_block ~replayer_input_file_path archive_uri
1717
output =
18-
let open Deferred.Let_syntax in
1918
let connection = Psql.Conn_str archive_uri in
2019
let%bind latest_state_hash =
2120
Psql.run_command ~connection
@@ -29,18 +28,17 @@ let assert_replayer_run_against_last_block ~replayer_input_file_path archive_uri
2928
failwith
3029
("Failed to query latest state hash: " ^ Error.to_string_hum err)
3130
in
32-
let output_ledger = output ^ "/output_ledger.json" in
31+
let output_ledger = output ^/ "output_ledger.json" in
3332
let replayer = Replayer.default in
34-
let%bind replayer_output =
33+
let%map replayer_output =
3534
Replayer.run replayer ~archive_uri ~input_config:replayer_input_file_path
3635
~target_state_hash:latest_state_hash ~interval_checkpoint:10
3736
~output_ledger ()
3837
in
39-
let () = print_endline replayer_output in
38+
print_endline replayer_output ;
4039
let output_ledger = Replayer.Output.of_json_file_exn output_ledger in
4140
assert (
42-
String.equal output_ledger.target_epoch_ledgers_state_hash latest_state_hash ) ;
43-
Deferred.unit
41+
String.equal output_ledger.target_epoch_ledgers_state_hash latest_state_hash )
4442

4543
(** Unpack precomputed blocks from a source archive to a temporary directory.
4644
@@ -51,10 +49,8 @@ let assert_replayer_run_against_last_block ~replayer_input_file_path archive_uri
5149
@param source Source path of the tar archive containing precomputed blocks
5250
@return Deferred list of file paths to extracted JSON block files *)
5351
let unpack_precomputed_blocks ~temp_dir source =
54-
let open Deferred.Let_syntax in
55-
let%bind precomputed_blocks =
52+
let%map precomputed_blocks =
5653
Network_data.untar_precomputed_blocks source temp_dir
5754
in
58-
List.map precomputed_blocks ~f:(fun file -> temp_dir ^ "/" ^ file)
55+
List.map precomputed_blocks ~f:(fun file -> temp_dir ^/ file)
5956
|> List.filter ~f:(fun file -> String.is_suffix file ~suffix:".json")
60-
|> Deferred.return

src/test/archive/archive_node_tests/live_upgrade_archive.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ open Common
2020
type t = Mina_automation_fixture.Archive.after_bootstrap
2121

2222
let test_case (test_data : t) =
23-
let open Deferred.Let_syntax in
2423
let daemon = Daemon.default () in
2524
let archive_uri = test_data.archive.config.postgres_uri in
2625
let temp_dir = test_data.temp_dir in
2726
let%bind precomputed_blocks =
2827
unpack_precomputed_blocks ~temp_dir test_data.network_data
2928
in
3029
let logger = Logger.create () in
31-
let log_file = temp_dir ^ "/live_upgrade.log" in
30+
let log_file = temp_dir ^/ "live_upgrade.log" in
3231
let upgrade_path =
3332
Archive.Scripts.filepath `Upgrade
3433
|> Option.value_exn ~message:"Failed to find upgrade script"
@@ -51,12 +50,14 @@ let test_case (test_data : t) =
5150
precomputed_blocks
5251
in
5352
[%log info] "Loaded all precomputed blocks" ;
53+
5454
let%bind () = Ivar.read upgrade_script_finished in
55-
let%bind () =
55+
56+
let%map () =
5657
assert_replayer_run_against_last_block
5758
~replayer_input_file_path:
5859
(Network_data.replayer_input_file_path test_data.network_data)
5960
archive_uri temp_dir
6061
in
6162

62-
Deferred.Or_error.return Mina_automation_fixture.Intf.Passed
63+
Ok Mina_automation_fixture.Intf.Passed

src/test/archive/archive_node_tests/load_genesis_ledger.ml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ 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 *)
2425
let test_case (test_data : t) =
25-
let open Deferred.Let_syntax in
2626
let config =
2727
{ test_data.config with config_file = "genesis_ledgers/mainnet.json" }
2828
in
@@ -43,7 +43,7 @@ let test_case (test_data : t) =
4343
(Float.to_string max_postgres_memory) ;
4444
[%log info] "Sleep Duration: %s" (Time.Span.to_string sleep_duration) ;
4545

46-
let%bind result =
46+
let%map result =
4747
let end_time = Time.add (Time.now ()) duration in
4848
let rec loop () =
4949
if Time.is_later (Time.now ()) ~than:end_time then Deferred.return ()
@@ -68,14 +68,11 @@ let test_case (test_data : t) =
6868
let%bind () = Clock.after sleep_duration in
6969
loop ()
7070
in
71-
Monitor.try_with (fun () -> loop ())
72-
>>= function
71+
match%map Monitor.try_with loop with
7372
| Ok () ->
74-
Deferred.return Mina_automation_fixture.Intf.Passed
73+
Mina_automation_fixture.Intf.Passed
7574
| Error exn ->
7675
[%log error] "Test failed: %s" (Exn.to_string exn) ;
77-
Deferred.return
78-
@@ Mina_automation_fixture.Intf.Failed (Exn.to_string exn)
76+
Failed (Exn.to_string exn)
7977
in
80-
81-
Deferred.Or_error.return result
78+
Ok result

src/test/archive/archive_node_tests/upgrade_archive.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ open Common
2020
type t = Mina_automation_fixture.Archive.after_bootstrap
2121

2222
let test_case (test_data : t) =
23-
let open Deferred.Let_syntax in
2423
let daemon = Daemon.default () in
2524
let archive_uri = test_data.archive.config.postgres_uri in
2625
let temp_dir = test_data.temp_dir in
2726
let%bind precomputed_blocks =
2827
unpack_precomputed_blocks ~temp_dir test_data.network_data
2928
in
30-
let log_file = temp_dir ^ "/upgrade.log" in
29+
let log_file = temp_dir ^/ "upgrade.log" in
3130
let upgrade_path =
3231
Archive.Scripts.filepath `Upgrade
3332
|> Option.value_exn ~message:"Failed to find upgrade script"
@@ -43,11 +42,11 @@ let test_case (test_data : t) =
4342
precomputed_blocks
4443
in
4544

46-
let%bind () =
45+
let%map () =
4746
assert_replayer_run_against_last_block
4847
~replayer_input_file_path:
4948
(Network_data.replayer_input_file_path test_data.network_data)
5049
archive_uri temp_dir
5150
in
5251

53-
Deferred.Or_error.return Mina_automation_fixture.Intf.Passed
52+
Ok Mina_automation_fixture.Intf.Passed

0 commit comments

Comments
 (0)