@@ -74,6 +74,20 @@ impl Fixture {
7474 ( status, serde_json:: from_slice ( & bytes) . unwrap ( ) )
7575 }
7676
77+ /// Subscribes to the channel's Redis topic; acknowledged before returning,
78+ /// so a later publish is not missed.
79+ async fn subscribe_channel ( & self ) -> redis:: aio:: PubSub {
80+ let topic = buzz_pubsub:: EventTopicKey {
81+ community_id : self . community ,
82+ topic : buzz_pubsub:: EventTopic :: Channel ( self . channel ) ,
83+ }
84+ . redis_channel ( ) ;
85+ let client = redis:: Client :: open ( self . state . config . redis_url . as_str ( ) ) . unwrap ( ) ;
86+ let mut pubsub = client. get_async_pubsub ( ) . await . unwrap ( ) ;
87+ pubsub. subscribe ( & topic) . await . unwrap ( ) ;
88+ pubsub
89+ }
90+
7791 async fn stored_typing_rows ( & self ) -> i64 {
7892 sqlx:: query_scalar (
7993 "SELECT COUNT(*) FROM events WHERE community_id = $1 AND channel_id = $2 AND kind = 20002" ,
@@ -91,15 +105,7 @@ impl Fixture {
91105async fn member_typing_is_broadcast_and_not_stored ( ) {
92106 use futures:: StreamExt ;
93107 let f = Fixture :: new ( ) . await ;
94- let topic = buzz_pubsub:: EventTopicKey {
95- community_id : f. community ,
96- topic : buzz_pubsub:: EventTopic :: Channel ( f. channel ) ,
97- }
98- . redis_channel ( ) ;
99- let client = redis:: Client :: open ( f. state . config . redis_url . as_str ( ) ) . unwrap ( ) ;
100- let mut pubsub = client. get_async_pubsub ( ) . await . unwrap ( ) ;
101- // Acknowledged by Redis before returning, so the publish below is not missed.
102- pubsub. subscribe ( & topic) . await . unwrap ( ) ;
108+ let pubsub = f. subscribe_channel ( ) . await ;
103109
104110 let event = f. typing ( & f. member , Some ( f. channel ) ) ;
105111 let ( status, body) = f. post ( & f. member , & event) . await ;
@@ -227,6 +233,7 @@ async fn oversized_typing_is_rejected() {
227233 . collect ( ) ,
228234 ) ,
229235 ] ;
236+ let pubsub = f. subscribe_channel ( ) . await ;
230237 for ( case, content, tags) in cases {
231238 let event = EventBuilder :: new ( Kind :: Custom ( 20002 ) , content)
232239 . tags ( tags)
@@ -246,12 +253,12 @@ async fn oversized_typing_is_rejected() {
246253 "{case}: {body}"
247254 ) ;
248255 }
256+ assert_nothing_published ( pubsub, "oversized typing indicator" ) . await ;
249257}
250258
251259#[ tokio:: test]
252260#[ ignore = "requires Postgres and Redis" ]
253261async fn fenced_community_typing_is_rejected ( ) {
254- use futures:: StreamExt ;
255262 let f = Fixture :: new ( ) . await ;
256263 // Over HTTP a quiescing community's host no longer binds (404), so the
257264 // fence only matters when quiescing starts after the request has bound its
@@ -274,14 +281,7 @@ async fn fenced_community_typing_is_rejected() {
274281 . unwrap ( ) ;
275282 tx. commit ( ) . await . unwrap ( ) ;
276283
277- let topic = buzz_pubsub:: EventTopicKey {
278- community_id : f. community ,
279- topic : buzz_pubsub:: EventTopic :: Channel ( f. channel ) ,
280- }
281- . redis_channel ( ) ;
282- let client = redis:: Client :: open ( f. state . config . redis_url . as_str ( ) ) . unwrap ( ) ;
283- let mut pubsub = client. get_async_pubsub ( ) . await . unwrap ( ) ;
284- pubsub. subscribe ( & topic) . await . unwrap ( ) ;
284+ let pubsub = f. subscribe_channel ( ) . await ;
285285
286286 let err = crate :: handlers:: event:: publish_http_typing (
287287 & f. state ,
@@ -295,11 +295,16 @@ async fn fenced_community_typing_is_rejected() {
295295 matches!( & err, IngestError :: Rejected ( msg) if msg == "restricted: community writes are fenced" ) ,
296296 "{err:?}"
297297 ) ;
298+ assert_nothing_published ( pubsub, "fenced typing indicator" ) . await ;
299+ }
300+
301+ async fn assert_nothing_published ( pubsub : redis:: aio:: PubSub , what : & str ) {
302+ use futures:: StreamExt ;
298303 let mut messages = pubsub. into_on_message ( ) ;
299304 assert ! (
300305 tokio:: time:: timeout( std:: time:: Duration :: from_millis( 500 ) , messages. next( ) )
301306 . await
302307 . is_err( ) ,
303- "fenced typing indicator must not be published"
308+ "{what} must not be published"
304309 ) ;
305310}
0 commit comments