Skip to content

Commit 5a8d007

Browse files
committed
simplify mina automation fixture test result type
1 parent bbcf261 commit 5a8d007

File tree

6 files changed

+42
-43
lines changed

6 files changed

+42
-43
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/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)