22
33const common = require ( '../common' ) ;
44const assert = require ( 'assert' ) ;
5- const { channel, suppressed } = require ( 'node:diagnostics_channel' ) ;
5+ const { channel, bypass } = require ( 'node:diagnostics_channel' ) ;
66const { AsyncLocalStorage } = require ( 'async_hooks' ) ;
77
8- // Test 1: Basic suppression - subscriber with subscriberId is skipped inside suppressed ()
8+ // Test 1: Basic bypass - subscriber with bypassId is skipped inside bypass ()
99{
1010 const key = Symbol ( 'tracer' ) ;
11- const ch = channel ( 'test-suppression -basic' ) ;
11+ const ch = channel ( 'test-bypass -basic' ) ;
1212 const handler = common . mustNotCall ( ) ;
13- ch . subscribe ( handler , { subscriberId : key } ) ;
13+ ch . subscribe ( handler , { bypassId : key } ) ;
1414
15- suppressed ( key , common . mustCall ( ( ) => {
15+ bypass ( key , common . mustCall ( ( ) => {
1616 ch . publish ( { } ) ;
1717 } ) ) ;
1818
1919 ch . unsubscribe ( handler ) ;
2020}
2121
22- // Test 2: Non-opted subscriber fires even inside suppressed () scope
22+ // Test 2: Non-opted subscriber fires even inside bypass () scope
2323{
2424 const key = Symbol ( 'tracer2' ) ;
25- const ch = channel ( 'test-suppression -nonopted' ) ;
25+ const ch = channel ( 'test-bypass -nonopted' ) ;
2626 const optedHandler = common . mustNotCall ( ) ;
2727 const regularHandler = common . mustCall ( ) ;
28- ch . subscribe ( optedHandler , { subscriberId : key } ) ;
29- ch . subscribe ( regularHandler ) ; // no suppression
28+ ch . subscribe ( optedHandler , { bypassId : key } ) ;
29+ ch . subscribe ( regularHandler ) ; // no bypass
3030
31- suppressed ( key , common . mustCall ( ( ) => {
31+ bypass ( key , common . mustCall ( ( ) => {
3232 ch . publish ( { } ) ;
3333 } ) ) ;
3434
3535 ch . unsubscribe ( optedHandler ) ;
3636 ch . unsubscribe ( regularHandler ) ;
3737}
3838
39- // Test 3: Two APMs with different keys don't suppress each other
39+ // Test 3: Two APMs with different keys don't bypass each other
4040{
4141 const k1 = Symbol ( 'k1' ) ;
4242 const k2 = Symbol ( 'k2' ) ;
43- const ch = channel ( 'test-suppression -two-keys' ) ;
43+ const ch = channel ( 'test-bypass -two-keys' ) ;
4444 let h1Calls = 0 ;
4545 let h2Calls = 0 ;
4646 const h1 = common . mustCall ( ( ) => { h1Calls ++ ; } , 1 ) ;
4747 const h2 = common . mustCall ( ( ) => { h2Calls ++ ; } , 1 ) ;
48- ch . subscribe ( h1 , { subscriberId : k1 } ) ;
49- ch . subscribe ( h2 , { subscriberId : k2 } ) ;
48+ ch . subscribe ( h1 , { bypassId : k1 } ) ;
49+ ch . subscribe ( h2 , { bypassId : k2 } ) ;
5050
51- suppressed ( k1 , common . mustCall ( ( ) => {
51+ bypass ( k1 , common . mustCall ( ( ) => {
5252 ch . publish ( { } ) ;
5353 } ) ) ;
5454
5555 assert . strictEqual ( h1Calls , 0 ) ;
5656 assert . strictEqual ( h2Calls , 1 ) ;
5757
58- suppressed ( k2 , common . mustCall ( ( ) => {
58+ bypass ( k2 , common . mustCall ( ( ) => {
5959 ch . publish ( { } ) ;
6060 } ) ) ;
6161
@@ -66,23 +66,23 @@ const { AsyncLocalStorage } = require('async_hooks');
6666 ch . unsubscribe ( h2 ) ;
6767}
6868
69- // Test 4: Nested suppressed () calls (same key, different keys)
69+ // Test 4: Nested bypass () calls (same key, different keys)
7070{
7171 const k1 = Symbol ( 'nested1' ) ;
7272 const k2 = Symbol ( 'nested2' ) ;
73- const ch = channel ( 'test-suppression -nested' ) ;
73+ const ch = channel ( 'test-bypass -nested' ) ;
7474 const h1 = common . mustNotCall ( ) ;
7575 let h2Calls = 0 ;
7676 const h2 = common . mustCall ( ( ) => { h2Calls ++ ; } , 2 ) ;
77- ch . subscribe ( h1 , { subscriberId : k1 } ) ;
78- ch . subscribe ( h2 , { subscriberId : k2 } ) ;
77+ ch . subscribe ( h1 , { bypassId : k1 } ) ;
78+ ch . subscribe ( h2 , { bypassId : k2 } ) ;
7979
80- suppressed ( k1 , common . mustCall ( ( ) => {
80+ bypass ( k1 , common . mustCall ( ( ) => {
8181 // Inside k1, h1 skipped, h2 runs
8282 ch . publish ( { } ) ;
8383 assert . strictEqual ( h2Calls , 1 ) ;
8484
85- suppressed ( k2 , common . mustCall ( ( ) => {
85+ bypass ( k2 , common . mustCall ( ( ) => {
8686 // Inside both, both skipped
8787 ch . publish ( { } ) ;
8888 assert . strictEqual ( h2Calls , 1 ) ;
@@ -97,15 +97,15 @@ const { AsyncLocalStorage } = require('async_hooks');
9797 ch . unsubscribe ( h2 ) ;
9898}
9999
100- // Test 5: suppressed () across a Promise boundary
100+ // Test 5: bypass () across a Promise boundary
101101{
102102 const key = Symbol ( 'promise' ) ;
103- const ch = channel ( 'test-suppression -promise' ) ;
103+ const ch = channel ( 'test-bypass -promise' ) ;
104104 const handler = common . mustNotCall ( ) ;
105- ch . subscribe ( handler , { subscriberId : key } ) ;
105+ ch . subscribe ( handler , { bypassId : key } ) ;
106106 const done = common . mustCall ( ) ;
107107
108- suppressed ( key , common . mustCall ( async ( ) => {
108+ bypass ( key , common . mustCall ( async ( ) => {
109109 await Promise . resolve ( ) ;
110110 ch . publish ( { } ) ;
111111 } ) ) . then ( common . mustCall ( ( ) => {
@@ -114,15 +114,15 @@ const { AsyncLocalStorage } = require('async_hooks');
114114 } ) ) ;
115115}
116116
117- // Test 6: suppressed () across setImmediate and queueMicrotask
117+ // Test 6: bypass () across setImmediate and queueMicrotask
118118{
119119 const key = Symbol ( 'timers' ) ;
120- const ch = channel ( 'test-suppression -timers' ) ;
120+ const ch = channel ( 'test-bypass -timers' ) ;
121121 const handler = common . mustNotCall ( ) ;
122- ch . subscribe ( handler , { subscriberId : key } ) ;
122+ ch . subscribe ( handler , { bypassId : key } ) ;
123123 const done = common . mustCall ( ) ;
124124
125- suppressed ( key , common . mustCall ( async ( ) => {
125+ bypass ( key , common . mustCall ( async ( ) => {
126126 await new Promise ( ( resolve ) => {
127127 setImmediate ( common . mustCall ( ( ) => {
128128 ch . publish ( { } ) ;
@@ -139,33 +139,32 @@ const { AsyncLocalStorage } = require('async_hooks');
139139 } ) ) ;
140140}
141141
142- // Test 7: unsubscribe() works correctly after using subscriberId
142+ // Test 7: unsubscribe() works correctly after using bypassId
143143{
144144 const key = Symbol ( 'unsub' ) ;
145- const ch = channel ( 'test-suppression -unsubscribe' ) ;
145+ const ch = channel ( 'test-bypass -unsubscribe' ) ;
146146 const handler = common . mustNotCall ( ) ;
147- ch . subscribe ( handler , { subscriberId : key } ) ;
147+ ch . subscribe ( handler , { bypassId : key } ) ;
148148 ch . unsubscribe ( handler ) ;
149149
150150 // Should not throw and should not be called
151- suppressed ( key , common . mustCall ( ( ) => {
151+ bypass ( key , common . mustCall ( ( ) => {
152152 ch . publish ( { } ) ;
153153 } ) ) ;
154-
155154}
156155
157- // Test 8: bindStore with subscriberId is skipped inside suppressed ()
156+ // Test 8: bindStore with bypassId is skipped inside bypass ()
158157{
159158 const key = Symbol ( 'store' ) ;
160- const ch = channel ( 'test-suppression -store' ) ;
159+ const ch = channel ( 'test-bypass -store' ) ;
161160 const als = new AsyncLocalStorage ( ) ;
162161 const normalAls = new AsyncLocalStorage ( ) ;
163162
164- // Normal store - no subscriberId , must always be entered
163+ // Normal store, no bypassId , must always be entered.
165164 ch . bindStore ( normalAls , common . mustCall ( ( data ) => ( { value : data . value } ) ) ) ;
166165
167- // Bypass store - must NOT be entered inside suppressed()
168- ch . bindStore ( als , common . mustNotCall ( ) , { subscriberId : key } ) ;
166+ // Bypass store, must NOT be entered inside bypass().
167+ ch . bindStore ( als , common . mustNotCall ( ) , { bypassId : key } ) ;
169168
170169 // Handler verifies:
171170 // - normal store WAS entered (normalAls has value)
@@ -176,7 +175,7 @@ const { AsyncLocalStorage } = require('async_hooks');
176175 } ) ;
177176 ch . subscribe ( handler ) ;
178177
179- suppressed ( key , common . mustCall ( ( ) => {
178+ bypass ( key , common . mustCall ( ( ) => {
180179 ch . runStores ( { value : 42 } , common . mustCall ( ) ) ;
181180 } ) ) ;
182181
@@ -185,24 +184,24 @@ const { AsyncLocalStorage } = require('async_hooks');
185184 ch . unbindStore ( normalAls ) ;
186185}
187186
188- // Test 9: Wrong type for subscriberId throws ERR_INVALID_ARG_TYPE
187+ // Test 9: Wrong type for bypassId throws ERR_INVALID_ARG_TYPE
189188{
190- const ch = channel ( 'test-suppression -wrong-type' ) ;
189+ const ch = channel ( 'test-bypass -wrong-type' ) ;
191190 const bad = 'not-allowed' ;
192- assert . throws ( ( ) => ch . subscribe ( ( ) => { } , { subscriberId : bad } ) , {
191+ assert . throws ( ( ) => ch . subscribe ( ( ) => { } , { bypassId : bad } ) , {
193192 name : 'TypeError'
194193 } ) ;
195194 const als = new AsyncLocalStorage ( ) ;
196- assert . throws ( ( ) => ch . bindStore ( als , ( d ) => d , { subscriberId : bad } ) , {
195+ assert . throws ( ( ) => ch . bindStore ( als , ( d ) => d , { bypassId : bad } ) , {
197196 name : 'TypeError'
198197 } ) ;
199198}
200199
201- // Test 10: suppressed () return value passes through fn's return value
200+ // Test 10: bypass () return value passes through fn's return value
202201{
203202 const key = Symbol ( 'return' ) ;
204203 const receiver = { value : 41 } ;
205- const result = suppressed ( key , common . mustCall ( function ( a , b ) {
204+ const result = bypass ( key , common . mustCall ( function ( a , b ) {
206205 assert . strictEqual ( this , receiver ) ;
207206 assert . strictEqual ( a , 'a' ) ;
208207 assert . strictEqual ( b , 'b' ) ;
0 commit comments