Skip to content

Commit ee1ce7e

Browse files
committed
Use multiple system threads in integration tests
1 parent bdd068f commit ee1ce7e

File tree

5 files changed

+78
-21
lines changed

5 files changed

+78
-21
lines changed

tests/bin/emit1_cohttp.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ let () =
109109
let batch_metrics = ref 3 in
110110
let batch_logs = ref 400 in
111111
let url = ref None in
112+
let n_procs = ref 1 in
112113
let opts =
113114
[
114115
"--debug", Arg.Bool (( := ) debug), " enable debug output";
@@ -127,12 +128,18 @@ let () =
127128
"--sleep-outer", Arg.Set_float sleep_outer, " sleep (in s) in outer loop";
128129
"--iterations", Arg.Set_int iterations, " the number of iterations to run";
129130
"-j", Arg.Set_int n_jobs, " number of parallel jobs";
131+
"--procs", Arg.Set_int n_procs, " number of processes";
130132
]
131133
|> Arg.align
132134
in
133135

134136
Arg.parse opts (fun _ -> ()) "emit1 [opt]*";
135137

138+
if !n_procs > 1 then
139+
failwith
140+
"TODO: add support for running multiple processes to the lwt-cohttp \
141+
emitter";
142+
136143
let some_if_nzero r =
137144
if !r > 0 then
138145
Some !r

tests/bin/emit1_eio.ml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let sleep_outer = ref 2.0
1111

1212
let n_jobs = ref 1
1313

14-
let iterations = ref 1
14+
let iterations = Atomic.make 1
1515

1616
let num_sleep = Atomic.make 0
1717

@@ -32,8 +32,8 @@ let run_job clock _job_id : unit =
3232
~attrs:[ "i", `Int !i ]
3333
in
3434

35-
for j = 0 to !iterations do
36-
if j >= !iterations then
35+
for j = 0 to Atomic.get iterations do
36+
if j >= Atomic.get iterations then
3737
(* Terminate program, having reached our max iterations *)
3838
Atomic.set stop true
3939
else
@@ -80,7 +80,7 @@ let run_job clock _job_id : unit =
8080
done
8181
done
8282

83-
let run env : unit =
83+
let run env proc () : unit =
8484
OT.GC_metrics.basic_setup ();
8585

8686
OT.Metrics_callbacks.register (fun () ->
@@ -90,8 +90,11 @@ let run env : unit =
9090
[ int (Atomic.get num_sleep) ];
9191
]);
9292

93+
(* The callbacks registered by [OT.Metrics_callbacks.register] are only triggered when a tick runs *)
94+
OT.Collector.tick ();
95+
9396
let n_jobs = max 1 !n_jobs in
94-
Printf.printf "run %d jobs\n%!" n_jobs;
97+
Printf.printf "run %d jobs in proc %d\n%!" n_jobs proc;
9598

9699
Eio.Switch.run (fun sw ->
97100
for j = 1 to n_jobs do
@@ -109,6 +112,7 @@ let () =
109112
let batch_metrics = ref 3 in
110113
let batch_logs = ref 400 in
111114
let url = ref None in
115+
let n_procs = ref 1 in
112116
let opts =
113117
[
114118
"--debug", Arg.Bool (( := ) debug), " enable debug output";
@@ -125,8 +129,11 @@ let () =
125129
"--batch-logs", Arg.Int (( := ) batch_logs), " size of logs batch";
126130
"--sleep-inner", Arg.Set_float sleep_inner, " sleep (in s) in inner loop";
127131
"--sleep-outer", Arg.Set_float sleep_outer, " sleep (in s) in outer loop";
128-
"--iterations", Arg.Set_int iterations, " the number of iterations to run";
129-
"-j", Arg.Set_int n_jobs, " number of parallel jobs";
132+
( "--iterations",
133+
Arg.Int (Atomic.set iterations),
134+
" the number of iterations to run" );
135+
"-j", Arg.Set_int n_jobs, " number of jobs per domain";
136+
"--procs", Arg.Set_int n_procs, " number of processes";
130137
]
131138
|> Arg.align
132139
in
@@ -155,4 +162,16 @@ let () =
155162
Printf.printf "\ndone. %d spans in %.4fs (%.4f/s)\n%!"
156163
(Atomic.get num_tr) elapsed n_per_sec)
157164
in
158-
Opentelemetry_client_cohttp_eio.with_setup ~stop ~config run |> Eio_main.run
165+
Eio_main.run @@ fun env ->
166+
(if !n_procs < 2 then
167+
Opentelemetry_client_cohttp_eio.with_setup ~stop ~config (run env 0) env
168+
else
169+
Eio.Switch.run @@ fun sw ->
170+
Opentelemetry_client_cohttp_eio.setup ~stop ~config ~sw env;
171+
let dm = Eio.Stdenv.domain_mgr env in
172+
Eio.Switch.run (fun sw ->
173+
for proc = 1 to !n_procs do
174+
Eio.Fiber.fork ~sw @@ fun () ->
175+
Eio.Domain_manager.run dm (run env proc)
176+
done));
177+
Opentelemetry.Collector.remove_backend () ~on_done:ignore

tests/client_e2e/clients_e2e_lib.ml

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ let filter_map_metrics f signals =
5656
|> List.find_map (fun ss ->
5757
ss.Proto.Metrics.metrics |> List.find_map f))
5858

59+
let count_metrics_with_name name signals =
60+
signals
61+
|> filter_map_metrics (fun s ->
62+
if String.equal s.Proto.Metrics.name name then
63+
Some s
64+
else
65+
None)
66+
|> List.length
67+
5968
let number_data_point_to_float : Proto.Metrics.number_data_point_value -> float
6069
= function
6170
| Proto.Metrics.As_double f -> f
@@ -98,6 +107,7 @@ let count_logs_with_body p signals =
98107
type params = {
99108
url: string;
100109
jobs: int;
110+
procs: int;
101111
batch_traces: int;
102112
batch_metrics: int;
103113
batch_logs: int;
@@ -109,6 +119,8 @@ let cmd exec params =
109119
exec;
110120
"-j";
111121
string_of_int params.jobs;
122+
"--procs";
123+
string_of_int params.procs;
112124
"--url";
113125
params.url;
114126
"--iterations";
@@ -134,22 +146,24 @@ let tests params signal_batches =
134146
(* TODO: What properties of batch sizes does it make sense to test? *)
135147
test "loop.outer spans" (fun () ->
136148
Alcotest.(check' int)
137-
~msg:"number of occurrences should equal the configured jobs"
138-
~expected:params.jobs
149+
~msg:
150+
"number of occurrences should equal the configured jobs * the \
151+
configured processes"
152+
~expected:(params.jobs * params.procs)
139153
~actual:(count_spans_with_name "loop.outer" signals));
140154
test "loop.inner spans" (fun () ->
141155
Alcotest.(check' int)
142156
~msg:
143157
"number of occurrences should equal the configured jobs * the \
144-
configured iterations"
145-
~expected:(params.jobs * params.iterations)
158+
configured iterations * configured processes"
159+
~expected:(params.jobs * params.iterations * params.procs)
146160
~actual:(count_spans_with_name "loop.inner" signals));
147161
test "alloc spans" (fun () ->
148162
Alcotest.(check' int)
149163
~msg:
150164
"number of occurrences should equal the configured jobs * the \
151-
configured iterations"
152-
~expected:(params.jobs * params.iterations)
165+
configured iterations * configured processes"
166+
~expected:(params.jobs * params.iterations * params.procs)
153167
~actual:(count_spans_with_name "alloc" signals);
154168
Alcotest.(check' bool)
155169
~msg:"should have 'done with alloc' event" ~expected:true
@@ -167,16 +181,19 @@ let tests params signal_batches =
167181
|> List.for_all (fun (e : Proto.Trace.span_event) ->
168182
String.equal e.name "done with alloc")));
169183
test "num-sleep metrics" (fun () ->
170-
Alcotest.(check' (float 0.))
171-
~msg:"should record jobs * iterations sleeps"
172-
~expected:(params.jobs * params.iterations |> float_of_int)
184+
Alcotest.(check' bool)
185+
~msg:
186+
"should record at lest as many sleep metrics as there are \
187+
iterations configured"
188+
~expected:true
173189
~actual:
174-
(get_metric_values "num-sleep" signals
175-
|> List.sort Float.compare |> List.rev |> List.hd));
190+
(count_metrics_with_name "num-sleep" signals >= params.iterations));
176191
test "logs" (fun () ->
177192
Alcotest.(check' int)
178-
~msg:"should record jobs * iterations occurrences of 'inner at n'"
179-
~expected:(params.jobs * params.iterations)
193+
~msg:
194+
"should record jobs * iterations occurrences * configured \
195+
processes of 'inner at n'"
196+
~expected:(params.jobs * params.iterations * params.procs)
180197
~actual:
181198
(signals
182199
|> count_logs_with_body (function

tests/client_e2e/test_cottp_eio_client_e2e.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ let () =
1515
{
1616
url;
1717
jobs = 1;
18+
procs = 1;
1819
iterations = 1;
1920
batch_traces = 2;
2021
batch_metrics = 2;
@@ -24,6 +25,17 @@ let () =
2425
{
2526
url;
2627
jobs = 3;
28+
procs = 1;
29+
iterations = 1;
30+
batch_traces = 400;
31+
batch_metrics = 3;
32+
batch_logs = 400;
33+
} );
34+
( "emit1_eio",
35+
{
36+
url;
37+
jobs = 3;
38+
procs = 3;
2739
iterations = 1;
2840
batch_traces = 400;
2941
batch_metrics = 3;

tests/client_e2e/test_cottp_lwt_client_e2e.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ let () =
2525
{
2626
url;
2727
jobs = 1;
28+
procs = 1;
2829
iterations = 1;
2930
batch_traces = 2;
3031
batch_metrics = 2;
@@ -34,6 +35,7 @@ let () =
3435
{
3536
url;
3637
jobs = 3;
38+
procs = 1;
3739
iterations = 1;
3840
batch_traces = 400;
3941
batch_metrics = 3;

0 commit comments

Comments
 (0)