File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
archive/archive_node_tests Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 22Module to run archive process over archive PostgreSQL database.
33*)
44open Core
5-
5+ open Logger
66open Async
77
88module Config = struct
@@ -118,3 +118,40 @@ let start t =
118118
119119 let archive_process : Process.t = { process; config = t.config } in
120120 Deferred. return archive_process
121+
122+ let wait_for ~log =
123+ let open Deferred.Let_syntax in
124+ let timeout = 30.0 in
125+ let start_time = Time. now () in
126+ let rec loop () =
127+ Core.Unix. sleep 1 ;
128+ let % bind log_exists =
129+ Sys. file_exists log >> | fun exists ->
130+ match exists with
131+ | `Yes -> true
132+ | _ -> false
133+ in
134+ if not log_exists then (
135+ if int_of_float (Time.Span. to_sec (Time. diff (Time. now () ) start_time)) > int_of_float timeout then (
136+ eprintf " Timeout waiting for log file to be created\n " ;
137+ Deferred. return ()
138+ ) else loop ()
139+ ) else (
140+ let % bind log_contents = Reader. file_contents log in
141+ let lines = String. split_lines log_contents in
142+ let found =
143+ List. exists lines ~f: (fun line ->
144+ match Yojson.Safe. from_string line |> Logger.Message. of_yojson with
145+ | Ok msg ->
146+ String. equal msg.message " Archive process ready. Clients can now connect"
147+ | Error _ -> false )
148+ in
149+ if found then Deferred. return ()
150+ else if int_of_float (Time.Span. to_sec (Time. diff (Time. now () ) start_time)) > int_of_float timeout then (
151+ eprintf " Timeout waiting for archive process to be ready\n " ;
152+ Deferred. return ()
153+ )
154+ else loop ()
155+ )
156+ in
157+ loop ()
You can’t perform that action at this time.
0 commit comments