Debian Codegraph @

upstream/mageia-cauldron/man3pm/Test2::Manual::Anatomy::Hubs.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Test2::Manual::Anatomy::Hubs 3pm"
61 .TH Test2::Manual::Anatomy::Hubs 3pm 2025-06-24 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Test2::Manual::Anatomy::Hubs \- Internals documentation for the hub stack, and
68 hubs.
69 .SH DESCRIPTION
70 .IX Header "DESCRIPTION"
71 This document describes the hub stack, and the hubs it contains. It explains
72 why we have a stack, and when to add/remove hubs from it.
73 .SH "WHAT IS A HUB?"
74 .IX Header "WHAT IS A HUB?"
75 Test2 is an event system, tools generate events, those events are then
76 processed to modify the testing state (number of tests, number of failures,
77 etc). The hub is responsible for receiving and processing events to record the
78 change in state. All events should eventually reach a destination hub.
79 .PP
80 The base hub is Test2::Hub. All hub classes should inherit from the base hub
81 class. The base hub class provides several hooks that allow you to monitor or
82 modify events. Hubs are also responsible for forwarding events to the output
83 formatter.
84 .SH "WHY DO WE HAVE A HUB STACK?"
85 .IX Header "WHY DO WE HAVE A HUB STACK?"
86 There are cases where it makes sense to have more than one hub:
87 .IP subtests 4
88 .IX Item "subtests"
89 In Test2 subtests are implemented using the hub stack. When you start a subtest
90 a new Test2::Hub::Subtest instance is created and pushed to the stack. Once
91 this is done all calls to \f(CW\*(C`Test2::API::context\*(C'\fR will find the new hub and send
92 all events to it. When the subtest tool is complete it will remove the new hub,
93 and send a final subtest event to the parent hub.
94 .IP "testing your test tools" 4
95 .IX Item "testing your test tools"
96 \&\f(CWTest2::API::intercept()\fR is implemented using the hub stack. The
97 \&\f(CWTest2::API::intercept()\fR function will add an Test2::Hub::Interceptor
98 instance to the stack, any calls to \fBTest2::API::context()\fR will find the new
99 hub, and send it all events. The intercept hub is special in that is has no
100 connection to the parent hub, and usually does not have a formatter.
101 .SH "WHEN SHOULD I ADD A HUB TO THE STACK?"
102 .IX Header "WHEN SHOULD I ADD A HUB TO THE STACK?"
103 Any time you want to intercept or block events from affecting the test state.
104 Adding a new hub is essentially a way to create a sandbox where you have
105 absolute control over what events do. Adding a new hub insures that the main
106 test state will not be affected.
107 .SH "WHERE IS THE STACK?"
108 .IX Header "WHERE IS THE STACK?"
109 The stack is an instance of Test2::API::Stack. You can access the global hub
110 stack using \f(CW\*(C`Test2::API::test2_stack\*(C'\fR.
111 .SH "WHAT ABOUT THE ROOT HUB?"
112 .IX Header "WHAT ABOUT THE ROOT HUB?"
113 The root hub is created automatically as needed. A call to
114 \&\f(CW\*(C`Test2::API::test2_stack\->top()\*(C'\fR will create the root hub if it does not
115 already exist.
116 .SH "HOW DO HUBS HANDLE IPC?"
117 .IX Header "HOW DO HUBS HANDLE IPC?"
118 If the IPC system (Test2::IPC) was not loaded, then IPC is not handled at
119 all. Forking or creating new threads without the IPC system can cause
120 unexpected problems.
121 .PP
122 All hubs track the PID and Thread ID that was current when they were created.
123 If an event is sent to a hub in a new process/thread the hub will detect this
124 and try to forward the event along to the correct process/thread. This is
125 accomplished using the IPC system.
126 .SH "SEE ALSO"
127 .IX Header "SEE ALSO"
128 Test2::Manual \- Primary index of the manual.
129 .SH SOURCE
130 .IX Header "SOURCE"
131 The source code repository for Test2\-Manual can be found at
132 \&\fIhttps://github.com/Test\-More/test\-more/\fR.
133 .SH MAINTAINERS
134 .IX Header "MAINTAINERS"
135 .IP "Chad Granum <[email protected]>" 4
136 .IX Item "Chad Granum <[email protected]>"
137 .SH AUTHORS
138 .IX Header "AUTHORS"
139 .IP "Chad Granum <[email protected]>" 4
140 .IX Item "Chad Granum <[email protected]>"
141 .SH COPYRIGHT
142 .IX Header "COPYRIGHT"
143 Copyright Chad Granum <[email protected]>.
144 .PP
145 This program is free software; you can redistribute it and/or
146 modify it under the same terms as Perl itself.
147 .PP
148 See \fIhttp://dev.perl.org/licenses/\fR