text stringlengths 0 601k |
|---|
let disjoint_union_classified_fields ? fail_msg ( t : unit Classification . t ) = let ( +> ) acc next_set = if not ( Operation_hash . Set . disjoint acc next_set ) then QCheck2 . Test . fail_reportf " Invariant ' The fields : [ refused ; outdated ; branch_refused ; \ branch_delayed ; applied ] are disjoint ' broken by ... |
let check_invariants ? fail_msg ( t : unit Classification . t ) = let to_set map = Operation_hash . Map . to_seq map |> Seq . map fst |> Operation_hash . Set . of_seq in let expected_in_mempool = disjoint_union_classified_fields ? fail_msg t in let mempool_as_set = to_set t . in_mempool in if not ( Operation_hash . Set... |
let classification_pp pp classification = Format . fprintf pp ( match classification with | ` Applied -> " Applied " | ` Prechecked -> " Prechecked " | ` Branch_delayed _ -> " Branch_delayed " | ` Branch_refused _ -> " Branch_refused " | ` Refused _ -> " Refused " | ` Outdated _ -> " Outdated " ) |
let event_pp pp = function | Add_if_not_present ( classification , op ) -> Format . fprintf pp " Add_if_not_present % a % a " classification_pp classification Operation_hash . pp op . Prevalidation . hash | Remove oph -> Format . fprintf pp " Remove % a " Operation_hash . pp oph | Flush handle_branch_refused -> Format ... |
let test_flush_empties_all_except_refused_and_outdated = let open QCheck2 in Test . make ~ name : " [ flush ~ handle_branch_refused : true ] empties everything except [ refused ] \ and [ outdated ] " ( Generators . t_gen ( ) ) @@ fun t -> let refused_before = t . refused |> Classification . map in let outdated_before =... |
let test_flush_empties_all_except_refused_and_branch_refused = let open QCheck2 in Test . make ~ name : " [ flush ~ handle_branch_refused : false ] empties everything except \ [ refused ] , [ outdated ] and [ branch_refused ] " ( Generators . t_gen ( ) ) @@ fun t -> let refused_before = t . refused |> Classification . ... |
let test_is_in_mempool_remove = let open QCheck2 in Test . make ~ name " [ : is_in_mempool ] and [ remove_ ] * are well - behaved " Generators . ( Gen . pair ( t_with_operation_gen ( ) ) unrefused_classification_gen ) @@ fun ( ( t , op ) , unrefused_classification ) -> Classification . add unrefused_classification op t... |
let test_is_applied = let open QCheck2 in Test . make ~ name " [ : is_applied ] is well - behaved " Generators . ( Gen . pair ( t_gen ( ) ) ( operation_with_hash_gen ( ) ) ) @@ fun ( t , op ) -> Classification . add ` Applied op t ; let oph = op . Prevalidation . hash in qcheck_eq_true ~ actual ( : is_in_mempool oph t ... |
let test_invariants = let open QCheck2 in Test . make ~ name : " invariants are preserved through any sequence of events ( provided we do \ not [ add ] already present operations ) " Extra_generators . t_with_event_sequence_gen @@ fun ( t , events ) -> let _ = List . fold_left ( fun ( fail_msg , cnt ) event -> play_eve... |
module Unparsable = struct let test_add_is_known = let open QCheck2 in Test . make ~ name " [ : is_known_unparsable oph ( add_unparsable oph t ) ] holds " Generators . ( t_with_operation_gen ( ) ) @@ fun ( t , op ) -> let oph = op . Prevalidation . hash in Classification . add_unparsable oph t ; qcheck_eq_true ~ actual... |
module Bounded = struct type binding = unit Prevalidation . operation type custom = unit Classification . t * [ ` Branch_delayed of tztrace | ` Branch_refused of tztrace | ` Refused of tztrace | ` Outdated of tztrace ] * binding list * binding list let custom_print : custom QCheck2 . Print . t = fun ( t , classificatio... |
module To_map = struct let map_pp fmt x = let map_to_list m = Operation_hash . Map . to_seq m |> Seq . map ( fun ( _ , op ) -> op ) |> List . of_seq in let pp_pair fmt op = Format . fprintf fmt " % a :% a " Operation_hash . pp op . Prevalidation . hash Operation . pp op . raw in Format . fprintf fmt " % a " ( Format . ... |
let test_create_is_empty = let open QCheck2 in Test . make ~ name " [ : is_empty ( create params ) ] holds " Generators . parameters_gen @@ fun parameters -> let t = Classification . create parameters in qcheck_eq ' ~ expected : true ~ actual ( : Classification . is_empty t ) ( ) |
let test_create_add_not_empty = let open QCheck2 in Test . make ~ name " [ : not ( is_empty ( add _ _ _ t ) ) ] holds " ( Gen . pair ( Generators . t_with_operation_gen ( ) ) Generators . classification_gen ) @@ fun ( ( t , op ) , classification ) -> Classification . add classification op t ; qcheck_eq ' ~ expected : f... |
let ( ) = let mk_tests label tests = ( label , qcheck_wrap tests ) in Alcotest . run " Prevalidator_classification " [ mk_tests " flush " [ test_flush_empties_all_except_refused_and_outdated ; test_flush_empties_all_except_refused_and_branch_refused ; ] ; mk_tests " is_in_mempool " [ test_is_in_mempool_remove ] ; mk_te... |
let force_opt ~ loc = function | Some x -> x | None -> QCheck2 . Test . fail_reportf " Unexpected None at % s " loc |
let values_from_to ( ~ equal : ' a -> ' a -> bool ) ( tree : ' a Tree . tree ) ( start : ' a ) ( ancestor : ' a ) : ' a list = Tree . predecessors ~ equal tree start |> List_extra . take_until_if_found ~ pred ( ( : = ) ancestor ) |> force_opt ~ loc : __LOC__ |> fun preds -> start :: preds |
let op_set_pp fmt x = let set_to_list m = Operation_hash . Set . to_seq m |> List . of_seq in Format . fprintf fmt " % a " ( Format . pp_print_list Operation_hash . pp ) ( set_to_list x ) |
let op_map_pp fmt x = let pp_pair fmt ( hash , op ) = Format . fprintf fmt " % a :% a " Operation_hash . pp hash Operation . pp op . Prevalidation . raw in Format . fprintf fmt " % a " ( Format . pp_print_list pp_pair ) ( Operation_hash . Map . bindings x ) |
let qcheck_cond ? pp ~ cond e1 e2 ( ) = if cond e1 e2 then true else match pp with | None -> QCheck2 . Test . fail_reportf " [ @< h 0 > The condition check failed , but no pretty printer was \ provided . ] " @ | Some pp -> QCheck2 . Test . fail_reportf " [ @< v 2 > The condition check failed , !@\ first element , :@\ %... |
let blocks_to_oph_set ( blocks : Operation_hash . t list list list ) : Operation_hash . Set . t = List . concat blocks |> List . concat |> Operation_hash . Set . of_list |
let is_subset ( m1 : unit Prevalidation . operation Op_map . t ) ( m2 : unit Prevalidation . operation Op_map . t ) = let rec go ( m1_seq : ( Operation_hash . t * unit Prevalidation . operation ) Seq . t ) = match m1_seq ( ) with | Seq . Nil -> true | Seq . Cons ( ( m1_key , m1_value ) , m1_rest ) -> ( match Op_map . f... |
module Handle_operations = struct let dummy_classes = Classification . ( create { map_size_limit = 1 ; on_discarded_operation = ( fun _oph -> ( ) ) } ) let parse raw hash = Some ( Prevalidation . Internal_for_tests . make_operation hash raw ( ) ) let test_handle_live_operations_is_branch_alive = let gen = let open QChe... |
module Recyle_operations = struct let classification_of_ops_gen ( ops : unit Prevalidation . operation Op_map . t ) : unit Classification . t QCheck2 . Gen . t = let open QCheck2 . Gen in let ops = Operation_hash . Map . bindings ops |> List . map snd in let length = List . length ops in let * empty_space = 0 -- 100 in... |
let ( ) = Alcotest . run " Prevalidator " [ ( " handle_operations " , qcheck_wrap Handle_operations . [ test_handle_live_operations_is_branch_alive ; test_handle_live_operations_path_spec ; test_handle_live_operations_clear ; test_handle_live_operations_inject ; ] ) ; ( " recycle_operations " , qcheck_wrap Recyle_opera... |
module CompareListQ = Compare . List ( Q ) |
let pending_of_list = List . fold_left ( fun pendings ( op , priority ) -> Pending_ops . add op priority pendings ) Pending_ops . empty |
let test_iterators_ordering ~ name ~ iterator return_value = let open QCheck2 in Test . make ~ name : ( Format . sprintf " Ensure that % s returns operations in their priority ordering " name ) ( Gen . small_list ( Generators . operation_with_hash_and_priority_gen ( ) ) ) @@ fun ops -> let previous_priority = ref ` Hig... |
let test_iter_ordering = test_iterators_ordering ~ name " : iter " ~ iterator ( : fun f ops _acc -> Pending_ops . iter ( fun p h o -> f p h o ( ) ) ops ) ( ) |
let test_fold_ordering = test_iterators_ordering ~ name " : fold " ~ iterator : Pending_ops . fold ( ) |
let test_fold_es_ordering = test_iterators_ordering ~ name " : fold_es " ~ iterator : Pending_ops . fold_es return_unit |
let test_partial_fold_es = let open QCheck2 in Test . make ~ name " : Test cardinal after partial iteration with fold_es " ( Gen . pair ( Gen . small_list ( Generators . operation_with_hash_and_priority_gen ( ) ) ) Gen . small_nat ) @@ fun ( ops , to_process ) -> let pending = pending_of_list ops in let card0 = Pending... |
let ( ) = let mk_tests label tests = ( label , qcheck_wrap tests ) in Alcotest . run " Prevalidator_pending_operations " [ mk_tests " iter ordering " [ test_iter_ordering ] ; mk_tests " fold ordering " [ test_fold_ordering ] ; mk_tests " fold_es ordering " [ test_fold_es_ordering ] ; mk_tests " partial fold_es " [ test... |
type int ' = int [ @@ deriving qcheck ] qcheck |
let test_int ( ) = test_compare ~ msg " : Gen . int <=> deriving int " ~ eq : Alcotest . int Gen . int gen_int ' |
type unit ' = unit [ @@ deriving qcheck ] qcheck |
let test_unit ( ) = test_compare ~ msg " : Gen . unit <=> deriving unit " ~ eq : Alcotest . unit Gen . unit gen_unit ' |
type string ' = string [ @@ deriving qcheck ] qcheck |
let test_string ( ) = test_compare ~ msg " : Gen . string <=> deriving string " ~ eq : Alcotest . string Gen . string gen_string ' |
type char ' = char [ @@ deriving qcheck ] qcheck |
let test_char ( ) = test_compare ~ msg " : Gen . char <=> deriving char " ~ eq : Alcotest . char Gen . char gen_char ' |
type bool ' = bool [ @@ deriving qcheck ] qcheck |
let test_bool ( ) = test_compare ~ msg " : Gen . bool <=> deriving bool " ~ eq : Alcotest . bool Gen . bool gen_bool ' |
type float ' = float [ @@ deriving qcheck ] qcheck |
let test_float ( ) = test_compare ~ msg " : Gen . float <=> deriving float " ~ eq ( : Alcotest . float 0 ) . Gen . float gen_float ' |
type int32 ' = int32 [ @@ deriving qcheck ] qcheck |
let test_int32 ( ) = test_compare ~ msg " : Gen . int32 <=> deriving int32 " ~ eq : Alcotest . int32 Gen . ui32 gen_int32 ' |
type int64 ' = int64 [ @@ deriving qcheck ] qcheck |
let test_int64 ( ) = test_compare ~ msg " : Gen . int64 <=> deriving int64 " ~ eq : Alcotest . int64 Gen . ui64 gen_int64 ' |
type ' a option ' = ' a option [ @@ deriving qcheck ] qcheck |
let test_option ( ) = let zero = Gen . pure 0 in test_compare ~ msg " : Gen . option <=> deriving option " ~ eq : Alcotest ( . option int ) int ( Gen . option zero ) zero ( gen_option ' zero ) zero |
type ' a array ' = ' a array [ @@ deriving qcheck ] qcheck |
let test_array ( ) = let zero = Gen . pure 0 in test_compare ~ msg " : Gen . array <=> deriving array " ~ eq : Alcotest ( . array int ) int ( Gen . array zero ) zero ( gen_array ' zero ) zero |
type ' a list ' = ' a list [ @@ deriving qcheck ] qcheck |
let test_list ( ) = let zero = Gen . pure 0 in test_compare ~ msg " : Gen . list <=> deriving list " ~ eq : Alcotest ( . list int ) int ( Gen . list zero ) zero ( gen_list ' zero ) zero |
let ( ) = Alcotest . run " Test_Primitives " [ ( " Primitives " , Alcotest [ . test_case " test_int " ` Quick test_int ; test_case " test_unit " ` Quick test_unit ; test_case " test_string " ` Quick test_string ; test_case " test_char " ` Quick test_char ; test_case " test_bool " ` Quick test_bool ; test_case " test_fl... |
let pp_priority fmt { Priority . weight ; stream_dependency ; exclusive } = Format . fprintf fmt " Weight : % d ; Parent : % ld ; Exclusive : % B " weight stream_dependency exclusive |
let priority = Alcotest . of_pp pp_priority |
let node = ( module struct open Scheduler . PriorityTreeNode type t = parent let pp formatter ( Parent t ) t = Format . pp_print_text formatter ( Scheduler . stream_id t |> Int32 . to_string ) to_string let equal ( Parent h1 ) h1 ( Parent h2 ) h2 = Stream_identifier ( . Scheduler ( . stream_id h1 ) h1 === Scheduler ( .... |
let default_error_handler ? request : _ _err _handle = ( ) |
let new_p w = { Priority . exclusive = false ; stream_dependency = 0l ; weight = w } |
let test_reqd stream_id = Stream . create ~ max_frame_size : Config . default . read_buffer_size stream_id Serialize . Writer ( . create 0x400 ) 0x400 default_error_handler ( fun ~ active : _ _ -> ( ) ) |
let repeat ( Scheduler . PriorityTreeNode . Connection root ) root queue num = let rec loop q n acc = if n = 0 then acc else match Scheduler . PriorityQueue . pop q with | None -> failwith " invalid queue " | Some ( ( k , ( Scheduler . Stream p as p_node ) p_node ) p_node , q ' ) q ' -> root . t_last <- p . t ; Schedul... |
let add_stream root ( ? priority = Priority . default_priority ) default_priority reqd = ignore @@ Scheduler . add root ~ priority ~ initial_recv_window_size : Settings . WindowSize . default_initial_window_size ~ initial_send_window_size : Settings . WindowSize . default_initial_window_size reqd |
let test_priority_queue ( ) = let root = Scheduler . make_root ~ capacity : 1000 ( ) in add_stream root ~ priority ( : new_p 201 ) 201 ( test_reqd 1l ) 1l ; add_stream root ~ priority ( : new_p 101 ) 101 ( test_reqd 3l ) 3l ; add_stream root ~ priority ( : new_p 1 ) 1 ( test_reqd 5l ) 5l ; let q = Scheduler . children ... |
let test_reprioritize ( ) = let open Scheduler in let root = Scheduler . make_root ~ capacity : 5 ( ) in add_stream root ( test_reqd 1l ) 1l ; add_stream root ( test_reqd 3l ) 3l ; add_stream root ( test_reqd 5l ) 5l ; let new_priority = { Priority . default_priority with weight = 100 } in let ( Stream stream1 as strea... |
let test_reprioritize_exclusive ( ) = let open Scheduler in let root = Scheduler . make_root ~ capacity : 5 ( ) in add_stream root ( test_reqd 1l ) 1l ; add_stream root ( test_reqd 3l ) 3l ; add_stream root ( test_reqd 5l ) 5l ; let stream7 = test_reqd 7l in let stream7_priority = { Priority . default_priority with str... |
let depend_on stream_id = { Priority . default_priority with stream_dependency = stream_id } |
let set_up_dep_tree root = add_stream root ( test_reqd 1l ) 1l ; add_stream root ~ priority ( : depend_on 1l ) 1l ( test_reqd 3l ) 3l ; add_stream root ~ priority ( : depend_on 1l ) 1l ( test_reqd 5l ) 5l ; add_stream root ~ priority ( : depend_on 5l ) 5l ( test_reqd 7l ) 7l ; add_stream root ~ priority ( : depend_on 5... |
let test_reprioritize_to_dependency ( ) = let open Scheduler in let root = Scheduler . make_root ~ capacity : 6 ( ) in set_up_dep_tree root ; let ( Stream stream1 as stream1_node ) stream1_node = Scheduler . get_node root 1l |> opt_exn in let stream5_node = Scheduler . get_node root 5l |> opt_exn in let ( Stream stream... |
let test_reprioritize_to_dependency_exclusive ( ) = let open Scheduler in let root = Scheduler . make_root ~ capacity : 6 ( ) in set_up_dep_tree root ; let stream5_node = Scheduler . get_node root 5l |> opt_exn in let ( Stream stream7 as stream7_node ) stream7_node = Scheduler . get_node root 7l |> opt_exn in Alcotest ... |
let priority_queue_tests = [ " Priority queue tests " , ` Quick , test_priority_queue ] |
let reprioritization_tests = [ " Reprioritize simple " , ` Quick , test_reprioritize ; " Reprioritize simple exclusive " , ` Quick , test_reprioritize_exclusive ; " Reprioritize to dependency " , ` Quick , test_reprioritize_to_dependency ; ( " Reprioritize to dependency exclusive " , ` Quick , test_reprioritize_to_depe... |
let ( ) = Alcotest . run " httpaf unit tests " [ " Reprioritization tests " , reprioritization_tests ; " Priority_Queue_Tests " , priority_queue_tests ] |
module Aspect = struct type t = Hashing_Blake2b | Hashing_Sha256 let compare ( x : t ) ( y : t ) = match ( x , y ) with | ( Hashing_Sha256 , Hashing_Sha256 ) -> 0 | ( Hashing_Blake2b , Hashing_Blake2b ) -> 0 | ( Hashing_Blake2b , Hashing_Sha256 ) -> - 1 | ( Hashing_Sha256 , Hashing_Blake2b ) -> 1 end |
type workload = Blake2b of { nbytes : int } | Sha256 of { nbytes : int } |
type config = { max_bytes : int } |
module Probing_bench = struct let name = " Probing_test " let info = " Testing probing benchmarks " let tags = [ " example " ] type nonrec config = config let default_config = { max_bytes = 1 lsl 16 } let config_encoding = let open Data_encoding in conv ( fun { max_bytes } -> max_bytes ) ( fun max_bytes -> { max_bytes ... |
let bench_opts = let open Measure in { flush_cache = ` Dont ; stabilize_gc = false ; seed = Some 1337 ; nsamples = 30 ; determinizer = Percentile 50 ; cpu_affinity = None ; bench_number = 10 ; minor_heap_size = ` words ( 256 * 1024 ) ; config_dir = None ; } |
let do_bench ( ) = let bench : ( config , workload ) Benchmark . poly = ( module Probing_bench ) in let _workload_data = Measure . perform_benchmark bench_opts bench in true |
let tests = [ Test . tztest_assert " probing bench " ` Quick do_bench ] |
let ts = all_emacs_children ( ) in print_s [ % message " " ~ _ ( : ts : t list ) ] ; [ % expect { | ( " #< process Async scheduler " ) > } ] ; | List . iter ts ~ f ( : fun t -> print_s [ % message " " ~ name ( : name t : string ) ] ) ; [ % expect { | ( name " Async scheduler " ) } ] ; | return ( ) ; ; |
let sleep ? buffer ( ) = create " / bin / sleep " [ " 100 " ] ~ name " : sleeper " ? buffer ( ) |
let show t = print_s [ % message " " ~ name ( : name t : string ) ~ buffer ( : buffer t : Buffer . t option ) ~ command ( : command t : string list option ) ~ is_in_all_emacs_children ( : List . mem ( all_emacs_children ( ) ) t ~ equal : bool ) ~ pid_is_positive : ( match pid t with | None -> None | Some pid -> Some ( ... |
let wait_until f = let timeout_at = Time . ( add ( now ( ) ) ( Span . of_sec 1 . ) ) in while_ ( fun ( ) -> ( not ( f ( ) ) ) && Time . ( now ( ) < timeout_at ) ) ~ do_ ( : fun ( ) -> Timer . sleep_for ( 0 . 01 |> sec_ns ) ) ; ; let test prog = let t = create prog [ ] ~ name " : t " ( ) in let sentinels_ran = ref false... |
let print_current_buffer_contents ( ) = print_string ( Current_buffer . contents ( ) |> Text . to_utf8_bytes ) ; ; |
let test_call_result_exn ? input ( ? output = Call . Output . Before_point_in_current_buffer ) ? working_directory ( ) ~ args ~ prog = Current_buffer . set_temporarily_to_temp_buffer Sync ( fun ( ) -> let result = call_result_exn prog args ? input ~ output ? working_directory in print_s [ % message ( result : Call . Re... |
let show_file_contents file = Current_buffer . set_temporarily_to_temp_buffer Sync ( fun ( ) -> Point . insert_file_contents_exn file ; print_current_buffer_contents ( ) ) ; ; require_does_raise [ % here ] ( fun ( ) -> test_call_result_exn ( ) ~ prog " :/ zzz " ~ args [ ] ) ; : [ % expect { | ( file - missing ( " Searc... |
let input_region ~ start ~ end_ ~ delete = Call . Region_input . Region { start = Position . of_int_exn start ; end_ = Position . of_int_exn end_ ; delete } ; ; |
let test result = print_s [ % message ( result : Call . Result . t ) ] ; print_endline " output " ; : print_current_buffer_contents ( ) ; Current_buffer . erase ( ) ; ; Point . insert " echo " ; test ( call_region_exn " cat " [ ] ~ output : Before_point_in_current_buffer ) ; [ % expect { | ( result ( Exit_status 0 ) ) ... |
module Query_response_tracker = Bonsai . Effect . For_testing . Query_response_tracker let var = Bonsai . Var . create 0 in let value = Bonsai . Var . value var in let component = return @@ Value . cutoff value ~ equal ( : fun a b -> a % 2 = b % 2 ) in let handle = Handle . create ( Result_spec . string ( module Int ) ... |
type thing = | Loading of string | Search_results of int let open Bonsai . Let_syntax in let component current_page = match % sub current_page with | Loading x -> Bonsai . read ( let % map x = x in " loading " ^ x ) | Search_results s -> Bonsai . read ( let % map s = s in sprintf " search results % d " s ) in let var =... |
let edge_poll_shared ~ get_expect_output = let effect_tracker = Query_response_tracker . create ( ) in let effect = Bonsai . Effect . For_testing . of_query_response_tracker effect_tracker in let var = Bonsai . Var . create " hello " in let component = Bonsai . Edge . Poll . effect_on_change [ % here ] ( module String ... |
let chain_computation = let % sub a = Bonsai . const " x " in let % sub b , set_b = Bonsai . state [ % here ] ( module String ) ~ default_model " : " in let % sub c , set_c = Bonsai . state [ % here ] ( module String ) ~ default_model " : " in let % sub d , set_d = Bonsai . state [ % here ] ( module String ) ~ default_... |
module M = struct type t = { a : string ; b : int } [ @@ deriving sexp_of , fields ] end let id = Bonsai . Dynamic_scope . create ~ sexp_of : M . sexp_of_t ~ name " : my - id " ~ fallback { : a = " hi " ; b = 5 } ( ) in let a = Bonsai . Dynamic_scope . derived id ~ get : M . a ~ set ( : Field . fset M . Fields . a ) in... |
let ( ) = Backtrace . elide := true |
let _ = Profile . should_profile := true |
module type Monad = sig include Monad . S val sync_or_async : _ t Sync_or_async . t end |
let clock = Private . Clock . create ~ now : Time_ns . epoch |
let advance_clock_by by = Clock . advance clock ~ by |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.