4 WorkerController.register_entry_point ~restore
:(fun () ~
(worker_id
: int) ->
5 Hh_logger.set_id
(Printf.sprintf
"worker_test %d" worker_id
))
9 let make_worker ?call_wrapper heap_handle
=
14 ~nbr_procs
:num_workers
15 ~gc_control
:(Gc.get
())
18 let rec wait_until_ready handle
=
19 let { WorkerController.readys
; waiters
= _
; ready_fds
= _
} =
20 WorkerController.select
[handle
] []
23 | [] -> wait_until_ready handle
26 (** If "f x" throws, we exit the program with a custom exit code. *)
27 let catch_exception_and_custom_exit_wrapper : 'x 'b
. ('x
-> 'b
) -> 'x
-> 'b
=
28 (fun f x
-> (try f x
with _
-> exit
17))
30 let call_and_verify_result worker f x expected
=
32 WorkerController.call worker f x
34 |> WorkerController.get_result
38 (** This is just like the test_worker_uncaught_exception_exits_with_2 test
39 * except we add a call_wapper to the worker. It catches all exceptions and
40 * makes the worker exit with code 17. *)
41 let test_wrapped_worker_with_custom_exit heap_handle
() =
45 { WorkerController.wrap
= catch_exception_and_custom_exit_wrapper }
50 Printf.eprintf
"Failed to create workers";
54 call_and_verify_result
56 (fun () -> raise
(Failure
"oops"))
60 | WorkerController.Worker_failed
61 (_
, WorkerController.Worker_quit
(Unix.WEXITED i
))
65 let test_worker_uncaught_exception_exits_with_2 heap_handle
() =
66 let workers = make_worker heap_handle
in
69 Printf.eprintf
"Failed to create workers";
73 call_and_verify_result
75 (fun () -> raise
(Failure
"oops"))
79 | WorkerController.Worker_failed
80 (_
, WorkerController.Worker_quit
(Unix.WEXITED i
))
84 let test_simple_worker_spawn heap_handle
() =
85 let workers = make_worker heap_handle
in
88 Printf.eprintf
"Failed to create workers";
90 | worker
:: _
-> call_and_verify_result worker
(fun () -> "hello") () "hello"
92 let make_tests handle
=
94 ("simple_worker_spawn_test", test_simple_worker_spawn handle
);
95 ( "worker_uncaught_exception_exits_with_2",
96 test_worker_uncaught_exception_exits_with_2 handle
);
97 ( "wrapped_worker_with_custom_exit",
98 test_wrapped_worker_with_custom_exit handle
);
102 Daemon.check_entry_point
();
104 (* this call might not return *)
106 SharedMem.init ~
num_workers GlobalConfig.default_sharedmem_config
108 let tests = make_tests heap_handle in
109 Unit_test.run_all
tests