Debian Codegraph @

upstream/debian-unstable/man3/Test2::Manual::Anatomy::Hubs.3perl

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