@@ -100,6 +100,29 @@ describe('invokeOrchestrionInstrumentation', () => {
100100 expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
101101 } ) ;
102102
103+ it ( 'keeps the listener when the binding is not ready, so a later injection recovers' , async ( ) => {
104+ // No async-context strategy, so the first injection finds no binding.
105+ setAsyncContextStrategy ( undefined ) ;
106+ const client = makeClient ( ) ;
107+ const callback = vi . fn ( ) ;
108+
109+ invokeOrchestrionInstrumentation ( client as never , [ 'pg' , 'pg-pool' ] , callback , [ ] ) ;
110+ expect ( client . listenerCount ( ) ) . toBe ( 1 ) ;
111+
112+ // First matching injection fires with no binding: the single retry bails,
113+ // the callback stays unmarked, and the listener must remain for a retry.
114+ client . inject ( 'pg' ) ;
115+ await new Promise ( resolve => setTimeout ( resolve , 10 ) ) ;
116+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
117+ expect ( client . listenerCount ( ) ) . toBe ( 1 ) ;
118+
119+ // Binding now available; a later matching injection subscribes.
120+ installBinding ( ) ;
121+ client . inject ( 'pg-pool' ) ;
122+ expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
123+ expect ( client . listenerCount ( ) ) . toBe ( 0 ) ;
124+ } ) ;
125+
103126 it ( 'matches on any of several module names' , ( ) => {
104127 const client = makeClient ( ) ;
105128 const callback = vi . fn ( ) ;
0 commit comments