Skip to content

Commit 17510fd

Browse files
committed
error out if sql commands return an error
1 parent 9fbde20 commit 17510fd

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

src/test/archive/archive_node_tests/archive_node_tests.ml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ open Mina_automation_fixture.Archive
1212
let assert_archived_blocks ~archive_uri ~expected =
1313
let connection = Psql.Conn_str archive_uri in
1414
let%bind actual_blocks_count =
15-
Psql.run_command ~connection "SELECT COUNT(*) FROM blocks WHERE height > 1"
15+
Psql.run_command ~connection
16+
"SELECT COUNT(*) FROM blocks WHERE global_slot_since_genesis > 1"
1617
in
1718
let actual_blocks_count =
1819
match actual_blocks_count with
1920
| Ok count ->
20-
count |> String.strip |> Int.of_string
21+
count |> Int.of_string
2122
| Error err ->
2223
failwith ("Failed to query blocks count: " ^ Error.to_string_hum err)
2324
in
@@ -54,19 +55,27 @@ module ArchivePrecomputedBlocksFromDaemon = struct
5455
in
5556
let connection = Psql.Conn_str archive_uri in
5657
let%bind latest_state_hash =
57-
Psql.run_command_exn ~connection
58+
Psql.run_command ~connection
5859
"SELECT state_hash FROM blocks ORDER BY id DESC LIMIT 1"
5960
in
61+
let latest_state_hash =
62+
match latest_state_hash with
63+
| Ok hash ->
64+
hash
65+
| Error err ->
66+
failwith
67+
("Failed to query latest state hash: " ^ Error.to_string_hum err)
68+
in
6069
let output_ledger = output ^ "/output_ledger.json" in
6170
let replayer = Replayer.default in
62-
let%bind output =
71+
let%bind replayer_output =
6372
Replayer.run replayer ~archive_uri
6473
~input_config:
6574
(Network_data.replayer_input_file_path test_data.network_data)
6675
~target_state_hash:latest_state_hash ~interval_checkpoint:10
6776
~output_ledger ()
6877
in
69-
let () = print_endline output in
78+
let () = print_endline replayer_output in
7079
let output_ledger = Replayer.Output.of_json_file_exn output_ledger in
7180
assert (
7281
String.equal output_ledger.target_epoch_ledgers_state_hash

src/test/mina_automation/daemon.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ let archive_blocks t ~archive_address ~(format : Archive_blocks.format) blocks =
151151
let archive_blocks_from_files t ~archive_address
152152
~(format : Archive_blocks.format) ?(sleep = 5) blocks =
153153
Deferred.List.iter blocks ~f:(fun block ->
154-
Core.Unix.sleep sleep ;
155-
archive_blocks t ~archive_address ~format [ block ] () >>| ignore )
154+
let%bind _ = archive_blocks t ~archive_address ~format [ block ] () in
155+
after (Time.Span.of_sec (Float.of_int sleep)) )
156156

157157
let default = Executor.default
158158

src/test/mina_automation/fixture/archive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ module Make_FixtureWithBootstrap (M : TestCaseWithBootstrap) :
8484
[%log info] "Tearing down archive" ;
8585
let%bind _ = Archive.Process.force_kill t.archive in
8686
let%bind.Deferred () =
87-
Mina_stdlib_unix.File_system.remove_dir @@ t.network_data.folder
87+
Mina_stdlib_unix.File_system.remove_dir @@ t.temp_dir
8888
in
8989
[%log info] "Archive teardown completed" ;
9090
Deferred.Or_error.ok_unit

src/test/mina_automation/psql.ml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ let create_credential_arg ~connection =
6868
@ value_or_empty "-U" credentials.user
6969
@ value_or_empty "-d" credentials.db
7070

71+
let run_command ~connection command =
72+
let creds = create_credential_arg ~connection in
73+
Util.run_cmd_or_error "." psql (creds @ [ "-c"; command; "-t" ])
74+
>>| Result.map ~f:String.strip
75+
7176
(** [run_command_exn ~connection command] runs a SQL command using psql with the given connection.
7277
The command is executed in the current directory, and the output is stripped of leading and trailing whitespace.
7378
It raises an exception if the command fails.
@@ -76,14 +81,6 @@ let create_credential_arg ~connection =
7681
@param command The SQL command to execute.
7782
@return A deferred string containing the output of the command.
7883
*)
79-
let run_command_exn ~connection command =
80-
let creds = create_credential_arg ~connection in
81-
Util.run_cmd_exn "." psql (creds @ [ "-c"; command; "-t" ]) >>| String.strip
82-
83-
let run_command ~connection command =
84-
let creds = create_credential_arg ~connection in
85-
Util.run_cmd_or_error "." psql (creds @ [ "-c"; command ])
86-
>>| Result.map ~f:String.strip
8784

8885
let run_script ~connection ~db script =
8986
let creds = create_credential_arg ~connection in

0 commit comments

Comments
 (0)