@@ -181,32 +181,66 @@ test('bus subject gc', async () => {
181181} ) ;
182182
183183test ( 'bus subject 1' , async ( ) => {
184-
185184 const bus = new BrokerBus ( await adapterFactory ( ) ) ;
186185 const handles : BrokerBus [ 'subjectHandles' ] = ( bus as any ) . subjectHandles ;
187186
188187 type Events = { type : 'user-created' , id : number } | { type : 'user-deleted' , id : number } ;
189188
190189 const caughtEvents : Events [ ] = [ ] ;
190+ const caughtEvents2 : Events [ ] = [ ] ;
191191
192192 const subject1 = bus . subject < Events > ( '/events' ) ;
193193 const subject2 = bus . subject < Events > ( '/events' ) ;
194194 expect ( handles . get ( '/events' ) ! . isSubscribed ) . toBe ( false ) ;
195195 const sub = subject2 . subscribe ( ( event ) => {
196196 caughtEvents . push ( event ) ;
197197 } ) ;
198+ const sub2 = subject1 . subscribe ( ( event ) => {
199+ caughtEvents2 . push ( event ) ;
200+ } ) ;
198201 expect ( handles . get ( '/events' ) ! . isSubscribed ) . toBe ( true ) ;
199202
200203 subject1 . next ( { type : 'user-created' , id : 2 } ) ;
201204 await sleep ( 0.1 ) ;
202205 expect ( handles . size ) . toBe ( 1 ) ;
203206 expect ( caughtEvents . length ) . toBe ( 1 ) ;
207+ expect ( caughtEvents2 . length ) . toBe ( 1 ) ;
204208 sub . unsubscribe ( ) ;
209+ sub2 . unsubscribe ( ) ;
205210 await sleep ( 0.1 ) ;
206211 expect ( handles . size ) . toBe ( 0 ) ;
207212} ) ;
208213
209214test ( 'bus subject 2' , async ( ) => {
215+ const adapter = await adapterFactory ( ) ;
216+ const bus1 = new BrokerBus ( adapter ) ;
217+ const bus2 = new BrokerBus ( adapter ) ;
218+
219+ type Events = { type : 'user-created' , id : number } | { type : 'user-deleted' , id : number } ;
220+
221+ const caughtEvents : Events [ ] = [ ] ;
222+ const caughtEvents2 : Events [ ] = [ ] ;
223+
224+ const subject1 = bus1 . subject < Events > ( '/events' ) ;
225+ const subject2 = bus2 . subject < Events > ( '/events' ) ;
226+ const sub = subject2 . subscribe ( ( event ) => {
227+ caughtEvents . push ( event ) ;
228+ } ) ;
229+ const sub2 = subject1 . subscribe ( ( event ) => {
230+ caughtEvents2 . push ( event ) ;
231+ } ) ;
232+
233+ await sleep ( 0.1 ) ;
234+ subject1 . next ( { type : 'user-created' , id : 2 } ) ;
235+ await sleep ( 0.1 ) ;
236+ expect ( caughtEvents . length ) . toBe ( 1 ) ;
237+ expect ( caughtEvents2 . length ) . toBe ( 1 ) ;
238+ sub . unsubscribe ( ) ;
239+ sub2 . unsubscribe ( ) ;
240+ await sleep ( 0.1 ) ;
241+ } ) ;
242+
243+ test ( 'bus subject 3' , async ( ) => {
210244
211245 const bus = new BrokerBus ( await adapterFactory ( ) ) ;
212246 const handles : BrokerBus [ 'subjectHandles' ] = ( bus as any ) . subjectHandles ;
0 commit comments