| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Test2::AsyncSubtest 3perl" |
| 58 |
.TH Test2::AsyncSubtest 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Test2::AsyncSubtest \- Object representing an async subtest. |
| 65 |
.SH DESCRIPTION |
| 66 |
.IX Header "DESCRIPTION" |
| 67 |
Regular subtests have a limited scope, they start, events are generated, then |
| 68 |
they close and send an Test2::Event::Subtest event. This is a problem if you |
| 69 |
want the subtest to keep receiving events while other events are also being |
| 70 |
generated. This class implements subtests that stay open until you decide to |
| 71 |
close them. |
| 72 |
.PP |
| 73 |
This is mainly useful for tools that start a subtest in one process and then |
| 74 |
spawn children. In many cases it is nice to let the parent process continue |
| 75 |
instead of waiting on the children. |
| 76 |
.SH SYNOPSIS |
| 77 |
.IX Header "SYNOPSIS" |
| 78 |
.Vb 1 |
| 79 |
\& use Test2::AsyncSubtest; |
| 80 |
\& |
| 81 |
\& my $ast = Test2::AsyncSubtest\->new(name => foo); |
| 82 |
\& |
| 83 |
\& $ast\->run(sub { |
| 84 |
\& ok(1, "Event in parent" ); |
| 85 |
\& }); |
| 86 |
\& |
| 87 |
\& ok(1, "Event outside of subtest"); |
| 88 |
\& |
| 89 |
\& $ast\->run_fork(sub { |
| 90 |
\& ok(1, "Event in child process"); |
| 91 |
\& }); |
| 92 |
\& |
| 93 |
\& ... |
| 94 |
\& |
| 95 |
\& $ast\->finish; |
| 96 |
\& |
| 97 |
\& done_testing; |
| 98 |
.Ve |
| 99 |
.SH CONSTRUCTION |
| 100 |
.IX Header "CONSTRUCTION" |
| 101 |
.Vb 1 |
| 102 |
\& my $ast = Test2::AsyncSubtest\->new( ... ); |
| 103 |
.Ve |
| 104 |
.ie n .IP "name => $name (required)" 4 |
| 105 |
.el .IP "name => \f(CW$name\fR (required)" 4 |
| 106 |
.IX Item "name => $name (required)" |
| 107 |
Name of the subtest. This construction argument is required. |
| 108 |
.ie n .IP "send_to => $hub (optional)" 4 |
| 109 |
.el .IP "send_to => \f(CW$hub\fR (optional)" 4 |
| 110 |
.IX Item "send_to => $hub (optional)" |
| 111 |
Hub to which the final subtest event should be sent. This must be an instance |
| 112 |
of Test2::Hub or a subclass. If none is specified then the current top hub |
| 113 |
will be used. |
| 114 |
.ie n .IP "trace => $trace (optional)" 4 |
| 115 |
.el .IP "trace => \f(CW$trace\fR (optional)" 4 |
| 116 |
.IX Item "trace => $trace (optional)" |
| 117 |
File/Line to which errors should be attributed. This must be an instance of |
| 118 |
Test2::Util::Trace. If none is specified then the file/line where the |
| 119 |
constructor was called will be used. |
| 120 |
.ie n .IP "hub => $hub (optional)" 4 |
| 121 |
.el .IP "hub => \f(CW$hub\fR (optional)" 4 |
| 122 |
.IX Item "hub => $hub (optional)" |
| 123 |
Use this to specify a hub the subtest should use. By default a new hub is |
| 124 |
generated. This must be an instance of Test2::AsyncSubtest::Hub. |
| 125 |
.SH METHODS |
| 126 |
.IX Header "METHODS" |
| 127 |
.SS "SIMPLE ACCESSORS" |
| 128 |
.IX Subsection "SIMPLE ACCESSORS" |
| 129 |
.ie n .IP "$bool = $ast\->active" 4 |
| 130 |
.el .IP "\f(CW$bool\fR = \f(CW$ast\fR\->active" 4 |
| 131 |
.IX Item "$bool = $ast->active" |
| 132 |
True if the subtest is active. The subtest is active if its hub appears in the |
| 133 |
global hub stack. This is true when \f(CW\*(C`$ast\->run(...)\*(C'\fR us running. |
| 134 |
.ie n .IP "$arrayref = $ast\->children" 4 |
| 135 |
.el .IP "\f(CW$arrayref\fR = \f(CW$ast\fR\->children" 4 |
| 136 |
.IX Item "$arrayref = $ast->children" |
| 137 |
Get an arrayref of child processes/threads. Numerical items are PIDs, blessed |
| 138 |
items are threads instances. |
| 139 |
.ie n .IP "$arrayref = $ast\->events" 4 |
| 140 |
.el .IP "\f(CW$arrayref\fR = \f(CW$ast\fR\->events" 4 |
| 141 |
.IX Item "$arrayref = $ast->events" |
| 142 |
Get an arrayref of events that have been sent to the subtests hub. |
| 143 |
.ie n .IP "$bool = $ast\->finished" 4 |
| 144 |
.el .IP "\f(CW$bool\fR = \f(CW$ast\fR\->finished" 4 |
| 145 |
.IX Item "$bool = $ast->finished" |
| 146 |
True if \f(CWfinished()\fR has already been called. |
| 147 |
.ie n .IP "$hub = $ast\->hub" 4 |
| 148 |
.el .IP "\f(CW$hub\fR = \f(CW$ast\fR\->hub" 4 |
| 149 |
.IX Item "$hub = $ast->hub" |
| 150 |
The hub created for the subtest. |
| 151 |
.ie n .IP "$int = $ast\->id" 4 |
| 152 |
.el .IP "\f(CW$int\fR = \f(CW$ast\fR\->id" 4 |
| 153 |
.IX Item "$int = $ast->id" |
| 154 |
Attach/Detach counter. Used internally, not useful to users. |
| 155 |
.ie n .IP "$str = $ast\->name" 4 |
| 156 |
.el .IP "\f(CW$str\fR = \f(CW$ast\fR\->name" 4 |
| 157 |
.IX Item "$str = $ast->name" |
| 158 |
Name of the subtest. |
| 159 |
.ie n .IP "$pid = $ast\->pid" 4 |
| 160 |
.el .IP "\f(CW$pid\fR = \f(CW$ast\fR\->pid" 4 |
| 161 |
.IX Item "$pid = $ast->pid" |
| 162 |
PID in which the subtest was created. |
| 163 |
.ie n .IP "$tid = $ast\->tid" 4 |
| 164 |
.el .IP "\f(CW$tid\fR = \f(CW$ast\fR\->tid" 4 |
| 165 |
.IX Item "$tid = $ast->tid" |
| 166 |
Thread ID in which the subtest was created. |
| 167 |
.ie n .IP "$hub = $ast\->send_to" 4 |
| 168 |
.el .IP "\f(CW$hub\fR = \f(CW$ast\fR\->send_to" 4 |
| 169 |
.IX Item "$hub = $ast->send_to" |
| 170 |
Hub to which the final subtest event should be sent. |
| 171 |
.ie n .IP "$arrayref = $ast\->stack" 4 |
| 172 |
.el .IP "\f(CW$arrayref\fR = \f(CW$ast\fR\->stack" 4 |
| 173 |
.IX Item "$arrayref = $ast->stack" |
| 174 |
Stack of async subtests at the time this one was created. This is mainly for |
| 175 |
internal use. |
| 176 |
.ie n .IP "$trace = $ast\->trace" 4 |
| 177 |
.el .IP "\f(CW$trace\fR = \f(CW$ast\fR\->trace" 4 |
| 178 |
.IX Item "$trace = $ast->trace" |
| 179 |
Test2::Util::Trace instance used for error reporting. |
| 180 |
.SS INTERFACE |
| 181 |
.IX Subsection "INTERFACE" |
| 182 |
.ie n .IP $ast\->attach($id) 4 |
| 183 |
.el .IP \f(CW$ast\fR\->attach($id) 4 |
| 184 |
.IX Item "$ast->attach($id)" |
| 185 |
Attach a subtest in a child/process to the original. |
| 186 |
.Sp |
| 187 |
\&\fBNote:\fR \f(CW\*(C`my $id = $ast\->cleave\*(C'\fR must have been called in the parent |
| 188 |
process/thread before the child was started, the id it returns must be used in |
| 189 |
the call to \f(CW\*(C`$ast\->attach($id)\*(C'\fR |
| 190 |
.ie n .IP "$id = $ast\->cleave" 4 |
| 191 |
.el .IP "\f(CW$id\fR = \f(CW$ast\fR\->cleave" 4 |
| 192 |
.IX Item "$id = $ast->cleave" |
| 193 |
Prepare a slot for a child process/thread to attach. This must be called BEFORE |
| 194 |
the child process or thread is started. The ID returned is used by \f(CWattach()\fR. |
| 195 |
.Sp |
| 196 |
This must only be called in the original process/thread. |
| 197 |
.ie n .IP "$ctx = $ast\->context" 4 |
| 198 |
.el .IP "\f(CW$ctx\fR = \f(CW$ast\fR\->context" 4 |
| 199 |
.IX Item "$ctx = $ast->context" |
| 200 |
Get an Test2::API::Context instance that can be used to send events to the |
| 201 |
context in which the hub was created. This is not a canonical context, you |
| 202 |
should not call \f(CW\*(C`$ctx\->release\*(C'\fR on it. |
| 203 |
.ie n .IP $ast\->detach 4 |
| 204 |
.el .IP \f(CW$ast\fR\->detach 4 |
| 205 |
.IX Item "$ast->detach" |
| 206 |
Detach from the parent in a child process/thread. This should be called just |
| 207 |
before the child exits. |
| 208 |
.ie n .IP $ast\->finish 4 |
| 209 |
.el .IP \f(CW$ast\fR\->finish 4 |
| 210 |
.IX Item "$ast->finish" |
| 211 |
.PD 0 |
| 212 |
.ie n .IP $ast\->finish(%options) 4 |
| 213 |
.el .IP \f(CW$ast\fR\->finish(%options) 4 |
| 214 |
.IX Item "$ast->finish(%options)" |
| 215 |
.PD |
| 216 |
Finish the subtest, wait on children, and send the final subtest event. |
| 217 |
.Sp |
| 218 |
This must only be called in the original process/thread. |
| 219 |
.Sp |
| 220 |
\&\fBNote:\fR This calls \f(CW\*(C`$ast\->wait\*(C'\fR. |
| 221 |
.Sp |
| 222 |
These are the options: |
| 223 |
.RS 4 |
| 224 |
.IP "collapse => 1" 4 |
| 225 |
.IX Item "collapse => 1" |
| 226 |
This intelligently allows a subtest to be empty. |
| 227 |
.Sp |
| 228 |
If no events bump the test count then the subtest no final plan will be added. |
| 229 |
The subtest will not be considered a failure (normally an empty subtest is a |
| 230 |
failure). |
| 231 |
.Sp |
| 232 |
If there are no events at all the subtest will be collapsed into an |
| 233 |
Test2::Event::Ok event. |
| 234 |
.IP "silent => 1" 4 |
| 235 |
.IX Item "silent => 1" |
| 236 |
This will prevent finish from generating a final Test2::Event::Subtest |
| 237 |
event. This effectively ends the subtest without it effecting the parent |
| 238 |
subtest (or top level test). |
| 239 |
.IP "no_plan => 1" 4 |
| 240 |
.IX Item "no_plan => 1" |
| 241 |
This will prevent a final plan from being added to the subtest for you when |
| 242 |
none is directly specified. |
| 243 |
.IP "skip => ""reason""" 4 |
| 244 |
.IX Item "skip => ""reason""" |
| 245 |
This will issue an Test2::Event::Skip instead of a subtest. This will throw |
| 246 |
an exception if any events have been seen, or if state implies events have |
| 247 |
occurred. |
| 248 |
.RE |
| 249 |
.RS 4 |
| 250 |
.RE |
| 251 |
.ie n .IP "$out = $ast\->fork" 4 |
| 252 |
.el .IP "\f(CW$out\fR = \f(CW$ast\fR\->fork" 4 |
| 253 |
.IX Item "$out = $ast->fork" |
| 254 |
This is a slightly higher level interface to fork. Running it will fork your |
| 255 |
code in-place just like \f(CWfork()\fR. It will return a pid in the parent, and an |
| 256 |
Test2::Util::Guard instance in the child. An exception will be thrown if |
| 257 |
fork fails. |
| 258 |
.Sp |
| 259 |
It is recommended that you use \f(CW\*(C`$ast\->run_fork(sub { ... })\*(C'\fR instead. |
| 260 |
.ie n .IP "$bool = $ast\->pending" 4 |
| 261 |
.el .IP "\f(CW$bool\fR = \f(CW$ast\fR\->pending" 4 |
| 262 |
.IX Item "$bool = $ast->pending" |
| 263 |
True if there are child processes, threads, or subtests that depend on this |
| 264 |
one. |
| 265 |
.ie n .IP "$bool = $ast\->ready" 4 |
| 266 |
.el .IP "\f(CW$bool\fR = \f(CW$ast\fR\->ready" 4 |
| 267 |
.IX Item "$bool = $ast->ready" |
| 268 |
This is essentially \f(CW\*(C`!$ast\->pending\*(C'\fR. |
| 269 |
.ie n .IP "$ast\->run(sub { ... })" 4 |
| 270 |
.el .IP "\f(CW$ast\fR\->run(sub { ... })" 4 |
| 271 |
.IX Item "$ast->run(sub { ... })" |
| 272 |
Run the provided codeblock inside the subtest. This will push the subtest hub |
| 273 |
onto the stack, run the code, then pop the hub off the stack. |
| 274 |
.ie n .IP "$pid = $ast\->run_fork(sub { ... })" 4 |
| 275 |
.el .IP "\f(CW$pid\fR = \f(CW$ast\fR\->run_fork(sub { ... })" 4 |
| 276 |
.IX Item "$pid = $ast->run_fork(sub { ... })" |
| 277 |
Same as \f(CW\*(C`$ast\->run()\*(C'\fR, except that the codeblock is run in a child |
| 278 |
process. |
| 279 |
.Sp |
| 280 |
You do not need to directly call \f(CWwait($pid)\fR, that will be done for you when |
| 281 |
\&\f(CW\*(C`$ast\->wait\*(C'\fR, or \f(CW\*(C`$ast\->finish\*(C'\fR are called. |
| 282 |
.ie n .IP "my $thr = $ast\->run_thread(sub { ... });" 4 |
| 283 |
.el .IP "my \f(CW$thr\fR = \f(CW$ast\fR\->run_thread(sub { ... });" 4 |
| 284 |
.IX Item "my $thr = $ast->run_thread(sub { ... });" |
| 285 |
\&\fB** DISCOURAGED **\fR Threads cause problems. This method remains for anyone who |
| 286 |
REALLY wants it, but it is no longer supported. Tests for this functionality do |
| 287 |
not even run unless the AUTHOR_TESTING or T2_DO_THREAD_TESTS env vars are |
| 288 |
enabled. |
| 289 |
.Sp |
| 290 |
Same as \f(CW\*(C`$ast\->run()\*(C'\fR, except that the codeblock is run in a child |
| 291 |
thread. |
| 292 |
.Sp |
| 293 |
You do not need to directly call \f(CW\*(C`$thr\->join\*(C'\fR, that is done for you when |
| 294 |
\&\f(CW\*(C`$ast\->wait\*(C'\fR, or \f(CW\*(C`$ast\->finish\*(C'\fR are called. |
| 295 |
.ie n .IP "$passing = $ast\->start" 4 |
| 296 |
.el .IP "\f(CW$passing\fR = \f(CW$ast\fR\->start" 4 |
| 297 |
.IX Item "$passing = $ast->start" |
| 298 |
Push the subtest hub onto the stack. Returns the current pass/fail status of |
| 299 |
the subtest. |
| 300 |
.ie n .IP $ast\->stop 4 |
| 301 |
.el .IP \f(CW$ast\fR\->stop 4 |
| 302 |
.IX Item "$ast->stop" |
| 303 |
Pop the subtest hub off the stack. Returns the current pass/fail status of the |
| 304 |
subtest. |
| 305 |
.ie n .IP $ast\->wait 4 |
| 306 |
.el .IP \f(CW$ast\fR\->wait 4 |
| 307 |
.IX Item "$ast->wait" |
| 308 |
Wait on all threads/processes that were started using \f(CW\*(C`$ast\->fork\*(C'\fR, |
| 309 |
\&\f(CW\*(C`$ast\->run_fork\*(C'\fR, or \f(CW\*(C`$ast\->run_thread\*(C'\fR. |
| 310 |
.SH SOURCE |
| 311 |
.IX Header "SOURCE" |
| 312 |
The source code repository for Test2\-AsyncSubtest can be found at |
| 313 |
\&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR. |
| 314 |
.SH MAINTAINERS |
| 315 |
.IX Header "MAINTAINERS" |
| 316 |
.IP "Chad Granum <[email protected]>" 4 |
| 317 |
.IX Item "Chad Granum <[email protected]>" |
| 318 |
.SH AUTHORS |
| 319 |
.IX Header "AUTHORS" |
| 320 |
.PD 0 |
| 321 |
.IP "Chad Granum <[email protected]>" 4 |
| 322 |
.IX Item "Chad Granum <[email protected]>" |
| 323 |
.PD |
| 324 |
.SH COPYRIGHT |
| 325 |
.IX Header "COPYRIGHT" |
| 326 |
Copyright 2018 Chad Granum <[email protected]>. |
| 327 |
.PP |
| 328 |
This program is free software; you can redistribute it and/or |
| 329 |
modify it under the same terms as Perl itself. |
| 330 |
.PP |
| 331 |
See \fIhttp://dev.perl.org/licenses/\fR |