Skip to content

Commit 215207b

Browse files
committed
simplify mina automation fixture test result type
1 parent bbcf261 commit 215207b

File tree

7 files changed

+87
-90
lines changed

7 files changed

+87
-90
lines changed

src/test/archive/archive_node_tests/archive_precomputed_blocks_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,4 @@ let test_case (test_data : t) =
144144
let%map perf_data = extract_perf_metrics log_file in
145145
perf_metrics_to_yojson perf_data |> Yojson.to_file "archive.perf" ;
146146

147-
Ok Mina_automation_fixture.Intf.Passed
147+
Mina_automation_fixture.Intf.Passed

src/test/archive/archive_node_tests/live_upgrade_archive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ let test_case (test_data : t) =
6060
archive_uri temp_dir
6161
in
6262

63-
Ok Mina_automation_fixture.Intf.Passed
63+
Mina_automation_fixture.Intf.Passed

src/test/archive/archive_node_tests/load_genesis_ledger.ml

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,32 @@ 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%map result =
47-
let end_time = Time.add (Time.now ()) duration in
48-
let rec loop () =
49-
if Time.is_later (Time.now ()) ~than:end_time then Deferred.return ()
50-
else
51-
let memory = Archive.Process.get_memory_usage_mib process in
52-
let%bind () =
53-
match memory with
54-
| Some mem ->
55-
[%log info] "Archive Memory usage: %s MiB" (Float.to_string mem) ;
56-
if Float.( > ) mem max_archive_memory then
57-
failwith "Archive process memory exceeds 1GB"
58-
else Deferred.return ()
59-
| None ->
60-
failwith "Error getting memory usage for archive process"
61-
in
62-
let%bind memory =
63-
Utils.get_memory_usage_mib_of_user_process postgres_user_name
64-
in
65-
[%log info] "Postgres Memory usage: %s MiB" (Float.to_string memory) ;
66-
if Float.( > ) memory max_postgres_memory then
67-
failwith "Postgres memory exceeds 4GB" ;
68-
let%bind () = Clock.after sleep_duration in
69-
loop ()
70-
in
71-
match%map Monitor.try_with loop with
72-
| Ok () ->
73-
Mina_automation_fixture.Intf.Passed
74-
| Error exn ->
75-
[%log error] "Test failed: %s" (Exn.to_string exn) ;
76-
Failed (Exn.to_string exn)
46+
let end_time = Time.add (Time.now ()) duration in
47+
let rec loop () =
48+
if Time.is_later (Time.now ()) ~than:end_time then Deferred.return ()
49+
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 ()
7769
in
78-
Ok result
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)

src/test/archive/archive_node_tests/upgrade_archive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ let test_case (test_data : t) =
4949
archive_uri temp_dir
5050
in
5151

52-
Ok Mina_automation_fixture.Intf.Passed
52+
Mina_automation_fixture.Intf.Passed

src/test/command_line_tests/command_line_tests.ml

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,33 @@ module BackgroundMode = struct
2525
let () = printf "Daemon logs:\n%s\n" logs in
2626
Writer.flushed (Lazy.force Writer.stdout)
2727
in
28-
let%bind () = Daemon.Client.stop_daemon process.client in
29-
Deferred.Or_error.return Mina_automation_fixture.Intf.Passed
28+
let%map () = Daemon.Client.stop_daemon process.client in
29+
Mina_automation_fixture.Intf.Passed
3030
end
3131

3232
module DaemonRecover = struct
3333
type t = Mina_automation_fixture.Daemon.before_bootstrap
3434

3535
let test_case (test : t) =
36-
let daemon = Daemon.of_config test.config in
37-
let%bind () = Daemon.Config.generate_keys test.config in
38-
let ledger_file = test.config.dirs.conf ^/ "daemon.json" in
39-
let%bind () =
40-
Mina_automation_fixture.Daemon.generate_random_config daemon ledger_file
41-
in
42-
let%bind process = Daemon.start daemon in
43-
let%bind.Deferred.Result () =
44-
Daemon.Client.wait_for_bootstrap process.client ()
45-
in
46-
let%bind.Deferred.Result _ = Daemon.Process.force_kill process in
47-
let%bind process = Daemon.start daemon in
48-
let%bind.Deferred.Result () =
49-
Daemon.Client.wait_for_bootstrap process.client ()
50-
in
51-
let%bind () = Daemon.Client.stop_daemon process.client in
52-
Deferred.Or_error.return Mina_automation_fixture.Intf.Passed
36+
(let daemon = Daemon.of_config test.config in
37+
let%bind () = Daemon.Config.generate_keys test.config in
38+
let ledger_file = test.config.dirs.conf ^/ "daemon.json" in
39+
let%bind () =
40+
Mina_automation_fixture.Daemon.generate_random_config daemon ledger_file
41+
in
42+
let%bind process = Daemon.start daemon in
43+
let%bind.Deferred.Result () =
44+
Daemon.Client.wait_for_bootstrap process.client ()
45+
in
46+
let%bind.Deferred.Result _ = Daemon.Process.force_kill process in
47+
let%bind process = Daemon.start daemon in
48+
let%bind.Deferred.Result () =
49+
Daemon.Client.wait_for_bootstrap process.client ()
50+
in
51+
let%map () = Daemon.Client.stop_daemon process.client in
52+
Ok () )
53+
>>| function
54+
| Ok () -> Mina_automation_fixture.Intf.Passed | Error err -> Failed err
5355
end
5456

5557
let contain_log_output output =
@@ -65,16 +67,16 @@ module LedgerHash = struct
6567
let%bind _ =
6668
Mina_automation_fixture.Daemon.generate_random_accounts daemon ledger_file
6769
in
68-
let%bind hash = Daemon.Client.ledger_hash client ~ledger_file in
69-
Deferred.Or_error.return
70-
( if contain_log_output hash then
71-
Mina_automation_fixture.Intf.Failed "output contains log"
72-
else if not (String.is_prefix ~prefix:"j" hash) then
73-
Failed "invalid ledger hash prefix"
74-
else if Int.( <> ) (String.length hash) 52 then
75-
Failed
76-
(Printf.sprintf "invalid ledger hash length (%d)" (String.length hash))
77-
else Passed )
70+
let%map hash = Daemon.Client.ledger_hash client ~ledger_file in
71+
if contain_log_output hash then
72+
Mina_automation_fixture.Intf.Failed
73+
(Error.of_string "output contains log")
74+
else if not (String.is_prefix ~prefix:"j" hash) then
75+
Failed (Error.of_string "invalid ledger hash prefix")
76+
else if Int.( <> ) (String.length hash) 52 then
77+
Failed
78+
(Error.createf "invalid ledger hash length (%d)" (String.length hash))
79+
else Passed
7880
end
7981

8082
module LedgerCurrency = struct
@@ -92,17 +94,16 @@ module LedgerCurrency = struct
9294
Currency.Balance.to_nanomina_int account.balance )
9395
|> List.sum (module Int) ~f:Fn.id
9496
in
95-
let%bind output = Daemon.Client.ledger_currency client ~ledger_file in
97+
let%map output = Daemon.Client.ledger_currency client ~ledger_file in
9698
let actual = Scanf.sscanf output "MINA : %f" Fn.id in
9799
let total_currency_float = float_of_int total_currency /. 1000000000.0 in
98100

99-
Deferred.Or_error.return
100-
@@
101101
if contain_log_output output then
102-
Mina_automation_fixture.Intf.Failed "output contains log"
102+
Mina_automation_fixture.Intf.Failed
103+
(Error.of_string "output contains log")
103104
else if not Float.(abs (total_currency_float - actual) < 0.001) then
104105
Failed
105-
(Printf.sprintf "invalid mina total count %f vs %f" total_currency_float
106+
(Error.createf "invalid mina total count %f vs %f" total_currency_float
106107
actual )
107108
else Passed
108109
end
@@ -113,15 +114,14 @@ module AdvancedPrintSignatureKind = struct
113114
let test_case (test : t) =
114115
let daemon = Daemon.of_config test.config in
115116
let client = Daemon.client daemon in
116-
let%bind output = Daemon.Client.advanced_print_signature_kind client in
117+
let%map output = Daemon.Client.advanced_print_signature_kind client in
117118
let expected = "testnet" in
118119

119-
Deferred.Or_error.return
120-
@@
121120
if contain_log_output output then
122-
Mina_automation_fixture.Intf.Failed "output contains log"
121+
Mina_automation_fixture.Intf.Failed
122+
(Error.of_string "output contains log")
123123
else if not (String.equal expected (String.strip output)) then
124-
Failed (Printf.sprintf "invalid signature kind %s vs %s" expected output)
124+
Failed (Error.createf "invalid signature kind %s vs %s" expected output)
125125
else Passed
126126
end
127127

@@ -137,15 +137,14 @@ module AdvancedCompileTimeConstants = struct
137137
in
138138
let temp_file = Filename.temp_file "commandline" "ledger.json" in
139139
Yojson.Safe.from_string config_content |> Yojson.Safe.to_file temp_file ;
140-
let%bind output =
140+
let%map output =
141141
Daemon.Client.advanced_compile_time_constants client
142142
~config_file:temp_file
143143
in
144144

145-
Deferred.Or_error.return
146-
@@
147145
if contain_log_output output then
148-
Mina_automation_fixture.Intf.Failed "output contains log"
146+
Mina_automation_fixture.Intf.Failed
147+
(Error.of_string "output contains log")
149148
else Passed
150149
end
151150

@@ -155,12 +154,11 @@ module AdvancedConstraintSystemDigests = struct
155154
let test_case (test : t) =
156155
let daemon = Daemon.of_config test.config in
157156
let client = Daemon.client daemon in
158-
let%bind output = Daemon.Client.advanced_constraint_system_digests client in
157+
let%map output = Daemon.Client.advanced_constraint_system_digests client in
159158

160-
Deferred.Or_error.return
161-
@@
162159
if contain_log_output output then
163-
Mina_automation_fixture.Intf.Failed "output contains log"
160+
Mina_automation_fixture.Intf.Failed
161+
(Error.of_string "output contains log")
164162
else Passed
165163
end
166164

src/test/mina_automation/fixture/intf.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
open Core
12
open Async
23

3-
type test_result = Passed | Failed of string | Warning of string
4+
type test_result = Passed | Failed of Error.t | Warning of string
45

56
module type TestCase = sig
67
type t
78

8-
val test_case : t -> test_result Deferred.Or_error.t
9+
val test_case : t -> test_result Deferred.t
910
end
1011

1112
module type Fixture = sig
@@ -24,7 +25,7 @@ module type Fixture = sig
2425
**)
2526
val setup : unit -> t Deferred.Or_error.t
2627

27-
val test_case : t -> test_result Deferred.Or_error.t
28+
val test_case : t -> test_result Deferred.t
2829

2930
val teardown : t -> unit Deferred.Or_error.t
3031

src/test/mina_automation/runner/runner.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ let run (module F : Intf.Fixture) =
2020
)
2121
(fun () ->
2222
match%bind F.test_case test_case_after_setup with
23-
| Ok result ->
24-
return result
25-
| Error err ->
23+
| Failed err ->
2624
let%map () = F.on_test_fail test_case_after_setup in
27-
Intf.Failed (Error.to_string_hum err) )
25+
Intf.Failed err
26+
| result ->
27+
return result )
2828

2929
let run_blocking test_case () =
3030
match Async.Thread_safe.block_on_async_exn (fun () -> run test_case) with
3131
| Intf.Passed ->
3232
()
33-
| Warning msg | Failed msg ->
33+
| Warning msg ->
3434
Alcotest.fail msg
35+
| Failed err ->
36+
Alcotest.fail (Error.to_string_hum err)

0 commit comments

Comments
 (0)