11import assert from "node:assert" ;
2+ import crypto from "node:crypto" ;
23
34it ( "maintains connections for the event even if other handlers closed it" , async ( ) => {
5+ const tag = `tag_${ crypto . randomBytes ( 4 ) . toString ( "hex" ) } ` ;
46 await using alice = await sessions . acquire ( { waitForWs : true } ) ;
57
6- using subscription1 = alice . ws . hashtag . subscribe ( { tag : "test" } ) ;
7- using subscription2 = alice . ws . hashtag . subscribe ( { tag : "test" } ) ;
8+ using subscription1 = alice . ws . hashtag . subscribe ( { tag } ) ;
9+ using subscription2 = alice . ws . hashtag . subscribe ( { tag } ) ;
810
911 const promise1 = subscription1 . values ( ) . take ( 1 ) . toArray ( ) ;
1012 const promise2 = subscription2 . values ( ) . take ( 2 ) . toArray ( ) ;
1113
1214 // Dispatch event for subscription1 to establish connection
1315 const status1 = await alice . rest . v1 . statuses . create ( {
14- status : "#test" ,
16+ status : `# ${ tag } ` ,
1517 visibility : "public" ,
1618 } ) ;
1719 await promise1 ;
1820 subscription1 . unsubscribe ( ) ;
1921
2022 // subscription1 is now closed, so status2 will only be dispatched to subscription2
2123 const status2 = await alice . rest . v1 . statuses . create ( {
22- status : "#test" ,
24+ status : `# ${ tag } ` ,
2325 visibility : "public" ,
2426 } ) ;
2527
@@ -37,16 +39,17 @@ it("maintains connections for the event even if other handlers closed it", async
3739} ) ;
3840
3941it ( "maintains connections for the event if unsubscribe called twice" , async ( ) => {
42+ const tag = `tag_${ crypto . randomBytes ( 4 ) . toString ( "hex" ) } ` ;
4043 await using alice = await sessions . acquire ( { waitForWs : true } ) ;
4144
42- using subscription1 = alice . ws . hashtag . subscribe ( { tag : "test" } ) ;
43- using subscription2 = alice . ws . hashtag . subscribe ( { tag : "test" } ) ;
45+ using subscription1 = alice . ws . hashtag . subscribe ( { tag } ) ;
46+ using subscription2 = alice . ws . hashtag . subscribe ( { tag } ) ;
4447
4548 const promise1 = subscription1 . values ( ) . take ( 1 ) . toArray ( ) ;
4649 const promise2 = subscription2 . values ( ) . take ( 2 ) . toArray ( ) ;
4750
4851 const status1 = await alice . rest . v1 . statuses . create ( {
49- status : "#test" ,
52+ status : `# ${ tag } ` ,
5053 visibility : "public" ,
5154 } ) ;
5255 await promise1 ;
@@ -56,7 +59,7 @@ it("maintains connections for the event if unsubscribe called twice", async () =
5659 subscription1 . unsubscribe ( ) ;
5760
5861 const status2 = await alice . rest . v1 . statuses . create ( {
59- status : "#test" ,
62+ status : `# ${ tag } ` ,
6063 visibility : "public" ,
6164 } ) ;
6265
@@ -74,17 +77,18 @@ it("maintains connections for the event if unsubscribe called twice", async () =
7477} ) ;
7578
7679it ( "maintains connections for the event if another handler called unsubscribe before connection established" , async ( ) => {
80+ const tag = `tag_${ crypto . randomBytes ( 4 ) . toString ( "hex" ) } ` ;
7781 await using alice = await sessions . acquire ( { waitForWs : true } ) ;
7882
79- using subscription1 = alice . ws . hashtag . subscribe ( { tag : "test" } ) ;
80- using subscription2 = alice . ws . hashtag . subscribe ( { tag : "test" } ) ;
83+ using subscription1 = alice . ws . hashtag . subscribe ( { tag } ) ;
84+ using subscription2 = alice . ws . hashtag . subscribe ( { tag } ) ;
8185
8286 subscription1 . unsubscribe ( ) ;
8387
8488 const promise2 = subscription2 . values ( ) . take ( 1 ) . toArray ( ) ;
8589
8690 const status1 = await alice . rest . v1 . statuses . create ( {
87- status : "#test" ,
91+ status : `# ${ tag } ` ,
8892 visibility : "public" ,
8993 } ) ;
9094
0 commit comments