Skip to content

Commit ac5503d

Browse files
committed
add wait for archive node bootstrap
1 parent bfd450e commit ac5503d

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/test/archive/archive_node_tests/archive_precomputed_blocks_test.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ let test_case (test_data : t) =
124124
in
125125
let log_file = output ^ "/precomputed_blocks_test.log" in
126126
Archive.Process.start_logging test_data.archive ~log_file ;
127+
let%bind () = Archive.wait_for ~log:log_file in
127128
let%bind () =
128129
Daemon.archive_blocks_from_files daemon.executor
129130
~archive_address:test_data.archive.config.server_port ~format:`Precomputed

src/test/mina_automation/archive.ml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Module to run archive process over archive PostgreSQL database.
33
*)
44
open Core
55

6+
open Logger
67
open Async
78

89
module Config = struct
@@ -118,3 +119,44 @@ let start t =
118119

119120
let archive_process : Process.t = { process; config = t.config } in
120121
Deferred.return archive_process
122+
123+
let wait_for ~log =
124+
let open Deferred.Let_syntax in
125+
let timeout = 30.0 in
126+
let start_time = Time.now () in
127+
let rec loop () =
128+
Core.Unix.sleep 1 ;
129+
let%bind log_exists =
130+
Sys.file_exists log
131+
>>| fun exists -> match exists with `Yes -> true | _ -> false
132+
in
133+
if not log_exists then
134+
if
135+
int_of_float (Time.Span.to_sec (Time.diff (Time.now ()) start_time))
136+
> int_of_float timeout
137+
then (
138+
eprintf "Timeout waiting for log file to be created\n" ;
139+
Deferred.return () )
140+
else loop ()
141+
else
142+
let%bind log_contents = Reader.file_contents log in
143+
let lines = String.split_lines log_contents in
144+
let found =
145+
List.exists lines ~f:(fun line ->
146+
match Yojson.Safe.from_string line |> Logger.Message.of_yojson with
147+
| Ok msg ->
148+
String.equal msg.message
149+
"Archive process ready. Clients can now connect"
150+
| Error _ ->
151+
false )
152+
in
153+
if found then Deferred.return ()
154+
else if
155+
int_of_float (Time.Span.to_sec (Time.diff (Time.now ()) start_time))
156+
> int_of_float timeout
157+
then (
158+
eprintf "Timeout waiting for archive process to be ready\n" ;
159+
Deferred.return () )
160+
else loop ()
161+
in
162+
loop ()

0 commit comments

Comments
 (0)