Skip to content

Commit 6fd99dc

Browse files
committed
resist ConnectivityManager$TooManyRequestsException
1 parent 90a4e71 commit 6fd99dc

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/session/space/SpaceCreationTest.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,17 @@ class SpaceCreationTest : InstrumentedTest {
5656
val roomName = "My Space"
5757
val topic = "A public space for test"
5858
var spaceId: String = ""
59-
commonTestHelper.waitWithLatch {
59+
commonTestHelper.runBlockingTest {
6060
spaceId = session.spaceService().createSpace(roomName, topic, null, true)
61-
// wait a bit to let the summary update it self :/
62-
it.countDown()
6361
}
64-
Thread.sleep(4_000)
6562

66-
val syncedSpace = session.spaceService().getSpace(spaceId)
6763
commonTestHelper.waitWithLatch {
6864
commonTestHelper.retryPeriodicallyWithLatch(it) {
69-
syncedSpace?.asRoom()?.roomSummary()?.name != null
65+
session.spaceService().getSpace(spaceId)?.asRoom()?.roomSummary()?.name != null
7066
}
7167
}
68+
69+
val syncedSpace = session.spaceService().getSpace(spaceId)
7270
assertEquals("Room name should be set", roomName, syncedSpace?.asRoom()?.roomSummary()?.name)
7371
assertEquals("Room topic should be set", topic, syncedSpace?.asRoom()?.roomSummary()?.topic)
7472
// assertEquals(topic, syncedSpace.asRoom().roomSummary()?., "Room topic should be set")

matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/NetworkCallbackStrategy.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ internal class PreferredNetworkCallbackStrategy @Inject constructor(context: Con
7070

7171
override fun register(hasChanged: () -> Unit) {
7272
hasChangedCallback = hasChanged
73-
conn.registerDefaultNetworkCallback(networkCallback)
73+
// Add a try catch for safety
74+
// TODO: It happens when running all tests in CI, at some points we reach a limit here causing TooManyRequestsException
75+
// and crashing the sync thread. We might have problem here, would need some investigation
76+
// for now adding a catch to allow CI to continue running
77+
try {
78+
conn.registerDefaultNetworkCallback(networkCallback)
79+
} catch (t: Throwable) {
80+
Timber.e(t, "Unable to register default network callback")
81+
}
7482
}
7583

7684
override fun unregister() {

0 commit comments

Comments
 (0)