 
 private extension MXRoom {
     
+    /// Send multiple text messages. If any of sending operations is failed, returns immediately with the error. Otherwise waits for all messages to be sent before calling the completion handler.
+    /// - Parameters:
+    ///   - messages: Messages to be sent
+    ///   - completion: Completion block
     func sendTextMessages(messages: [String], completion: @escaping (MXResponse<[String]>) -> Void) {
         let dispatchGroup = DispatchGroup()
         var eventIDs: [String] = []

                    expectation?.fulfill()
                }
            }
            
            let messages = (1...Constants.numberOfMessagesForLimitedTest).map({ "\(Constants.messageText) - \($0)" })
            room.sendTextMessages(messages: messages) { (response) in
                switch response {
                case .success(let eventIDs):
                    
                    guard let firstEventId = eventIDs.first, let lastEventId = eventIDs.last else {
                        XCTFail("Cannot set up initial test conditions - error: room cannot be retrieved")
                        expectation?.fulfill()
                        return
                    }
                    
                    self.bgSyncService = MXBackgroundSyncService(withCredentials: bobCredentials)

                    self.bgSyncService?.event(withEventId: lastEventId, inRoom: roomId) { (response) in
                        switch response {
                        case .success(let event):
                            let text = event.content["body"] as? String
                            XCTAssertEqual(text, "\(Constants.messageText) - \(Constants.numberOfMessagesForLimitedTest)", "Event content should match")

                            let syncResponseStore = MXSyncResponseFileStore()
                            syncResponseStore.open(withCredentials: bobCredentials)
                            XCTAssertNil(syncResponseStore.event(withEventId: firstEventId, inRoom: roomId), "First event should not be present in sync response store")
                            XCTAssertNotNil(syncResponseStore.event(withEventId: lastEventId, inRoom: roomId), "Last event should be present in sync response store")
                            
                            let syncResponse = syncResponseStore.syncResponse
                            XCTAssertNotNil(syncResponse, "Sync response should be present")
                            XCTAssertTrue(syncResponse!.rooms.join[roomId]!.timeline.limited, "Room timeline should be limited")
                            
                            var localEcho: MXEvent?
                            room.sendTextMessage(Constants.messageText, localEcho: &localEcho) { (response2) in
                                switch response2 {
                                case .success(let eventId):
                                    guard let eventId = eventId else {
                                        XCTFail("Cannot set up initial test conditions - error: room cannot be retrieved")
                                        expectation?.fulfill()
                                        return
                                    }
                                    
                                    self.bgSyncService = MXBackgroundSyncService(withCredentials: bobCredentials)

                                    self.bgSyncService?.event(withEventId: eventId, inRoom: roomId) { (response) in
                                        switch response {
                                        case .success:
                                            XCTAssertTrue(syncResponse!.rooms.join[roomId]!.timeline.limited, "Room timeline should still be limited")
                                        case .failure(let error):
                                            XCTFail("Cannot fetch the event from background sync service - error: \(error)")
                                            expectation?.fulfill()
                                        }
                                    }
                                    
                                case .failure(let error):
                                    XCTFail("Cannot set up initial test conditions - error: \(error)")
                                    expectation?.fulfill()
                                }
                            }

                        case .failure(let error):
                            XCTFail("Cannot fetch the event from background sync service - error: \(error)")
                            expectation?.fulfill()
                        }
                    }
                case .failure(let error):
                    XCTFail("Cannot set up initial test conditions - error: \(error)")
                    expectation?.fulfill()
                }
            }

        }
    }

        }
    }
    
    // Nonimal test: A limited timeline in a sync response causes old messages in the MXSyncResponseStore to be deleted
    // - Alice and Bob are in a room
    // - Bob stops their app
    // - Alice send a single message (call it A)
    // - Bob uses the MXBackgroundSyncService to fetch the event
    // -> The sync response in the MXSyncResponseStore doesn't have a limited timeline
    // -> The message (event A) is present in MXSyncResponseStore
    // - Alice sends a lot of messages (enough for a sync response timeline to be limited)
    // - Bob uses the MXBackgroundSyncService to fetch the last event
    // -> The message (last) can be read from MXBackgroundSyncService
    // -> The old message (event A) is not present in MXSyncResponseStore anymore
    // -> The first message is not present in MXSyncResponseStore
    // -> The sync response in the MXSyncResponseStore has a limited timeline
    func testWithPlainEventBeforeLimitedTimeline() {
        let aliceStore = MXMemoryStore()
        let bobStore = MXFileStore()
