@@ -138,9 +138,6 @@ async fn test_retry_failed() {
138138
139139 mock_sync ( & server, sync_builder. build_json_sync_response ( ) , None ) . await ;
140140 let _response = client. sync_once ( sync_settings. clone ( ) ) . await . unwrap ( ) ;
141- server. reset ( ) . await ;
142-
143- mock_encryption_state ( & server, false ) . await ;
144141
145142 client. send_queue ( ) . set_enabled ( true ) ;
146143
@@ -149,20 +146,43 @@ async fn test_retry_failed() {
149146 let ( _, mut timeline_stream) =
150147 timeline. subscribe_filter_map ( |item| item. as_event ( ) . cloned ( ) ) . await ;
151148
149+ // When trying to send an event, return with a 500 error, which is interpreted
150+ // as a transient error.
151+ server. reset ( ) . await ;
152+ mock_encryption_state ( & server, false ) . await ;
153+ let scoped_faulty_send = Mock :: given ( method ( "PUT" ) )
154+ . and ( path_regex ( r"^/_matrix/client/r0/rooms/.*/send/.*" ) )
155+ . and ( header ( "authorization" , "Bearer 1234" ) )
156+ . respond_with ( ResponseTemplate :: new ( 500 ) )
157+ . expect ( 3 )
158+ . mount_as_scoped ( & server)
159+ . await ;
160+
152161 timeline. send ( RoomMessageEventContent :: text_plain ( "Hello, World!" ) . into ( ) ) . await . unwrap ( ) ;
153162
154163 // Let the send queue handle the event.
155164 yield_now ( ) . await ;
156165
157- // First, local echo is added
166+ // First, local echo is added.
158167 assert_next_matches ! ( timeline_stream, VectorDiff :: PushBack { value } => {
159168 assert_matches!( value. send_state( ) , Some ( EventSendState :: NotSentYet ) ) ;
160169 } ) ;
161170
162- // Sending fails, the mock server has no matching route yet
171+ // Sending fails, because the error is a transient one that's recoverable,
172+ // indicating something's wrong on the client side.
163173 assert_let ! ( Some ( VectorDiff :: Set { index: 0 , value: item } ) = timeline_stream. next( ) . await ) ;
164- assert_matches ! ( item. send_state( ) , Some ( EventSendState :: SendingFailed { .. } ) ) ;
174+ assert_matches ! (
175+ item. send_state( ) ,
176+ Some ( EventSendState :: SendingFailed { is_recoverable: true , .. } )
177+ ) ;
165178
179+ // This doesn't disable the send queue at the global level…
180+ assert ! ( client. send_queue( ) . is_enabled( ) ) ;
181+ // …but does so at the local level.
182+ assert ! ( !room. send_queue( ) . is_enabled( ) ) ;
183+
184+ // Have the endpoint return a success result, and re-enable the queue.
185+ drop ( scoped_faulty_send) ;
166186 Mock :: given ( method ( "PUT" ) )
167187 . and ( path_regex ( r"^/_matrix/client/r0/rooms/.*/send/.*" ) )
168188 . and ( header ( "authorization" , "Bearer 1234" ) )
@@ -173,11 +193,6 @@ async fn test_retry_failed() {
173193 . mount ( & server)
174194 . await ;
175195
176- // This doesn't disable the send queue at the global level…
177- assert ! ( client. send_queue( ) . is_enabled( ) ) ;
178- // …but does so at the local level.
179- assert ! ( !room. send_queue( ) . is_enabled( ) ) ;
180-
181196 room. send_queue ( ) . set_enabled ( true ) ;
182197
183198 // Let the send queue handle the event.
0 commit comments