|  | 
|  | 1 | +open Async | 
|  | 2 | +open Core | 
|  | 3 | +open Mina_automation | 
|  | 4 | +open Mina_automation_fixture.Archive | 
|  | 5 | +open Common | 
|  | 6 | + | 
|  | 7 | +(* NOTE: | 
|  | 8 | +   To run this test, several preparation is needed | 
|  | 9 | +   - ensure we have this test, replayer & archive node build with devnet profile | 
|  | 10 | +   - ensure we have a data base instance up | 
|  | 11 | +   - Run the following: | 
|  | 12 | +     ``` | 
|  | 13 | +     MINA_TEST_POSTGRES_URI=postgres://postgres:xxxx@localhost:5432 \ | 
|  | 14 | +     MINA_TEST_NETWORK_DATA=./src/test/archive/sample_db \ | 
|  | 15 | +     ./_build/default/src/test/archive/archive_node_tests/archive_node_tests.exe \ | 
|  | 16 | +     test live_upgrade_archive | 
|  | 17 | +     ``` | 
|  | 18 | +*) | 
|  | 19 | + | 
|  | 20 | +type t = Mina_automation_fixture.Archive.after_bootstrap | 
|  | 21 | + | 
|  | 22 | +let test_case (test_data : t) = | 
|  | 23 | +  let open Deferred.Let_syntax in | 
|  | 24 | +  let daemon = Daemon.default () in | 
|  | 25 | +  let archive_uri = test_data.archive.config.postgres_uri in | 
|  | 26 | +  let temp_dir = test_data.temp_dir in | 
|  | 27 | +  let%bind precomputed_blocks = | 
|  | 28 | +    unpack_precomputed_blocks ~temp_dir test_data.network_data | 
|  | 29 | +  in | 
|  | 30 | +  let logger = Logger.create () in | 
|  | 31 | +  let log_file = temp_dir ^ "/live_upgrade.log" in | 
|  | 32 | +  let upgrade_path = | 
|  | 33 | +    Archive.Scripts.filepath `Upgrade | 
|  | 34 | +    |> Option.value_exn ~message:"Failed to find upgrade script" | 
|  | 35 | +  in | 
|  | 36 | +  let upgrade_script_finished = Ivar.create () in | 
|  | 37 | +  (let%bind () = after (Time.Span.of_min (Random.float_range 0. 5.)) in | 
|  | 38 | +   [%log info] "Starting upgrade script" ; | 
|  | 39 | +   let%map result = | 
|  | 40 | +     Psql.run_script ~connection:(Psql.Conn_str archive_uri) upgrade_path | 
|  | 41 | +   in | 
|  | 42 | +   [%log info] "Finished executing upgrade script" | 
|  | 43 | +     ~metadata:[ ("result", `String result) ] ; | 
|  | 44 | +   Ivar.fill upgrade_script_finished () ) | 
|  | 45 | +  |> Deferred.don't_wait_for ; | 
|  | 46 | +  Archive.Process.start_logging test_data.archive ~log_file ; | 
|  | 47 | + | 
|  | 48 | +  let%bind () = | 
|  | 49 | +    Daemon.archive_blocks_from_files daemon.executor | 
|  | 50 | +      ~archive_address:test_data.archive.config.server_port ~format:`Precomputed | 
|  | 51 | +      precomputed_blocks | 
|  | 52 | +  in | 
|  | 53 | +  [%log info] "Loaded all precomputed blocks" ; | 
|  | 54 | +  let%bind () = Ivar.read upgrade_script_finished in | 
|  | 55 | +  let%bind () = | 
|  | 56 | +    assert_replayer_run_against_last_block | 
|  | 57 | +      ~replayer_input_file_path: | 
|  | 58 | +        (Network_data.replayer_input_file_path test_data.network_data) | 
|  | 59 | +      archive_uri temp_dir | 
|  | 60 | +  in | 
|  | 61 | + | 
|  | 62 | +  Deferred.Or_error.return Mina_automation_fixture.Intf.Passed | 
0 commit comments