Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/test/archive/archive_node_tests/archive_node_tests.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
open Core
open Mina_automation_runner

let logger = Logger.create ()

let () =
Backtrace.elide := false ;
Async.Scheduler.set_record_backtraces true
Async.Scheduler.set_record_backtraces true ;
let random_seed =
Time.(now () |> to_span_since_epoch |> Span.to_ms) |> Int.of_float
in
[%log info] "Initializing random with seed"
~metadata:[ ("seed", `Int random_seed) ] ;
Random.init random_seed

let () =
let open Alcotest in
Expand Down Expand Up @@ -32,4 +40,13 @@ let () =
( module Mina_automation_fixture.Archive.Make_FixtureWithBootstrap
(Upgrade_archive) ) )
] )
; ( "live_upgrade_archive"
, [ test_case
"Recreate database from precomputed blocks. Meanwhile run upgrade \
script randomly at some time"
`Quick
(Runner.run_blocking
( module Mina_automation_fixture.Archive.Make_FixtureWithBootstrap
(Live_upgrade_archive) ) )
] )
]
62 changes: 62 additions & 0 deletions src/test/archive/archive_node_tests/live_upgrade_archive.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
open Async
open Core
open Mina_automation
open Mina_automation_fixture.Archive
open Common

(* NOTE:
To run this test, several preparation is needed
- ensure we have this test, replayer & archive node build with devnet profile
- ensure we have a data base instance up
- Run the following:
```
MINA_TEST_POSTGRES_URI=postgres://postgres:xxxx@localhost:5432 \
MINA_TEST_NETWORK_DATA=./src/test/archive/sample_db \
./_build/default/src/test/archive/archive_node_tests/archive_node_tests.exe \
test live_upgrade_archive
```
*)

type t = Mina_automation_fixture.Archive.after_bootstrap

let test_case (test_data : t) =
let open Deferred.Let_syntax in
let daemon = Daemon.default () in
let archive_uri = test_data.archive.config.postgres_uri in
let temp_dir = test_data.temp_dir in
let%bind precomputed_blocks =
unpack_precomputed_blocks ~temp_dir test_data.network_data
in
let logger = Logger.create () in
let log_file = temp_dir ^ "/live_upgrade.log" in
let upgrade_path =
Archive.Scripts.filepath `Upgrade
|> Option.value_exn ~message:"Failed to find upgrade script"
in
let upgrade_script_finished = Ivar.create () in
(let%bind () = after (Time.Span.of_min (Random.float_range 0. 5.)) in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is 0-5 minutes, but the sleep in archive_blocks_from_files is 0-5 seconds. Should this one be seconds too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, 5min is the time it takes to run the whole test on my machine. I'm expecting the upgrade script to be ran any time during the process of loading precomputed blocks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see - this delay wasn't supposed to match up with the delay from archive_blocks_from_files. This is a random delay to put the start of the upgrade script somewhere in the middle of that other function's execution.

[%log info] "Starting upgrade script" ;
let%map result =
Psql.run_script ~connection:(Psql.Conn_str archive_uri) upgrade_path
in
[%log info] "Finished executing upgrade script"
~metadata:[ ("result", `String result) ] ;
Ivar.fill upgrade_script_finished () )
|> Deferred.don't_wait_for ;
Archive.Process.start_logging test_data.archive ~log_file ;

let%bind () =
Daemon.archive_blocks_from_files daemon.executor
~archive_address:test_data.archive.config.server_port ~format:`Precomputed
~sleep:5 precomputed_blocks
in
[%log info] "Loaded all precomputed blocks" ;
let%bind () = Ivar.read upgrade_script_finished in
let%bind () =
assert_replayer_run_against_last_block
~replayer_input_file_path:
(Network_data.replayer_input_file_path test_data.network_data)
archive_uri temp_dir
in

Deferred.Or_error.return Mina_automation_fixture.Intf.Passed
3 changes: 1 addition & 2 deletions src/test/archive/archive_node_tests/upgrade_archive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ open Common
```
MINA_TEST_POSTGRES_URI=postgres://postgres:xxxx@localhost:5432 \
MINA_TEST_NETWORK_DATA=./src/test/archive/sample_db \
DUNE_PROFILE=devnet \
dune exec src/test/archive/archive_node_tests/archive_node_tests.exe -- \
./_build/default/src/test/archive/archive_node_tests/archive_node_tests.exe \
test upgrade_archive
```
*)
Expand Down