Browse Source

Merge pull request #952 from vector-im/feature/bma/fixPushStoreCrash

Fix push store crash
pull/959/head
Benoit Marty 1 year ago committed by GitHub
parent
commit
caaa1923c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .gitignore
  2. 2
      features/analytics/impl/build.gradle.kts
  3. 2
      features/createroom/impl/build.gradle.kts
  4. 2
      features/login/impl/build.gradle.kts
  5. 2
      features/logout/impl/build.gradle.kts
  6. 1
      features/messages/impl/build.gradle.kts
  7. 2
      features/onboarding/impl/build.gradle.kts
  8. 2
      features/preferences/impl/build.gradle.kts
  9. 2
      features/rageshake/impl/build.gradle.kts
  10. 2
      features/roomlist/impl/build.gradle.kts
  11. 2
      libraries/permissions/impl/build.gradle.kts
  12. 14
      libraries/pushstore/impl/build.gradle.kts
  13. 56
      libraries/pushstore/impl/src/androidTest/kotlin/io/element/android/libraries/pushstore/impl/DefaultUserPushStoreFactoryTest.kt
  14. 3
      libraries/pushstore/impl/src/main/kotlin/io/element/android/libraries/pushstore/impl/DefaultUserPushStoreFactory.kt
  15. 26
      libraries/session-storage/test/build.gradle.kts
  16. 25
      libraries/session-storage/test/src/main/kotlin/io/element/android/libraries/sessionstorage/test/observer/NoOpSessionObserver.kt
  17. 1
      tests/uitests/build.gradle.kts

1
.gitignore vendored

@ -38,6 +38,7 @@ captures/ @@ -38,6 +38,7 @@ captures/
# IntelliJ
*.iml
.idea/.name
.idea/androidTestResultsUserPreferences.xml
.idea/assetWizardSettings.xml
.idea/compiler.xml
.idea/deploymentTargetDropDown.xml

2
features/analytics/impl/build.gradle.kts

@ -52,6 +52,4 @@ dependencies { @@ -52,6 +52,4 @@ dependencies {
testImplementation(projects.libraries.matrix.test)
testImplementation(projects.features.analytics.test)
testImplementation(projects.features.analytics.impl)
androidTestImplementation(libs.test.junitext)
}

2
features/createroom/impl/build.gradle.kts

@ -66,7 +66,5 @@ dependencies { @@ -66,7 +66,5 @@ dependencies {
testImplementation(projects.libraries.mediaupload.test)
testImplementation(projects.libraries.usersearch.test)
androidTestImplementation(libs.test.junitext)
ksp(libs.showkase.processor)
}

2
features/login/impl/build.gradle.kts

@ -61,6 +61,4 @@ dependencies { @@ -61,6 +61,4 @@ dependencies {
testImplementation(libs.test.turbine)
testImplementation(projects.libraries.matrix.test)
testImplementation(projects.tests.testutils)
androidTestImplementation(libs.test.junitext)
}

2
features/logout/impl/build.gradle.kts

@ -48,6 +48,4 @@ dependencies { @@ -48,6 +48,4 @@ dependencies {
testImplementation(libs.test.truth)
testImplementation(libs.test.turbine)
testImplementation(projects.libraries.matrix.test)
androidTestImplementation(libs.test.junitext)
}

1
features/messages/impl/build.gradle.kts

@ -78,6 +78,5 @@ dependencies { @@ -78,6 +78,5 @@ dependencies {
testImplementation(projects.libraries.mediapickers.test)
testImplementation(libs.test.mockk)
androidTestImplementation(libs.test.junitext)
ksp(libs.showkase.processor)
}

2
features/onboarding/impl/build.gradle.kts

@ -48,6 +48,4 @@ dependencies { @@ -48,6 +48,4 @@ dependencies {
testImplementation(libs.test.truth)
testImplementation(libs.test.turbine)
testImplementation(projects.libraries.matrix.test)
androidTestImplementation(libs.test.junitext)
}

2
features/preferences/impl/build.gradle.kts

@ -69,6 +69,4 @@ dependencies { @@ -69,6 +69,4 @@ dependencies {
testImplementation(projects.features.analytics.test)
testImplementation(projects.features.analytics.impl)
testImplementation(projects.tests.testutils)
androidTestImplementation(libs.test.junitext)
}

2
features/rageshake/impl/build.gradle.kts

@ -56,6 +56,4 @@ dependencies { @@ -56,6 +56,4 @@ dependencies {
testImplementation(libs.test.mockk)
testImplementation(projects.libraries.matrix.test)
testImplementation(projects.features.rageshake.test)
androidTestImplementation(libs.test.junitext)
}

2
features/roomlist/impl/build.gradle.kts

@ -71,6 +71,4 @@ dependencies { @@ -71,6 +71,4 @@ dependencies {
testImplementation(projects.features.networkmonitor.test)
testImplementation(projects.tests.testutils)
testImplementation(projects.features.leaveroom.fake)
androidTestImplementation(libs.test.junitext)
}

2
libraries/permissions/impl/build.gradle.kts

@ -57,7 +57,5 @@ dependencies { @@ -57,7 +57,5 @@ dependencies {
testImplementation(libs.test.turbine)
testImplementation(projects.libraries.matrix.test)
androidTestImplementation(libs.test.junitext)
ksp(libs.showkase.processor)
}

14
libraries/pushstore/impl/build.gradle.kts

@ -20,6 +20,11 @@ plugins { @@ -20,6 +20,11 @@ plugins {
android {
namespace = "io.element.android.libraries.push.pushstore.impl"
defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["clearPackageData"] = "true"
}
}
anvil {
@ -43,4 +48,13 @@ dependencies { @@ -43,4 +48,13 @@ dependencies {
testImplementation(libs.coroutines.test)
testImplementation(projects.libraries.matrix.test)
testImplementation(projects.services.appnavstate.test)
androidTestImplementation(libs.coroutines.test)
androidTestImplementation(libs.test.core)
androidTestImplementation(libs.test.junit)
androidTestImplementation(libs.test.truth)
androidTestImplementation(libs.test.runner)
androidTestImplementation(projects.libraries.sessionStorage.test)
coreLibraryDesugaring(libs.android.desugar)
}

56
libraries/pushstore/impl/src/androidTest/kotlin/io/element/android/libraries/pushstore/impl/DefaultUserPushStoreFactoryTest.kt

@ -0,0 +1,56 @@ @@ -0,0 +1,56 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.pushstore.impl
import androidx.test.platform.app.InstrumentationRegistry
import io.element.android.libraries.matrix.api.core.SessionId
import io.element.android.libraries.pushstore.api.UserPushStore
import io.element.android.libraries.sessionstorage.test.observer.NoOpSessionObserver
import kotlinx.coroutines.runBlocking
import org.junit.Test
import kotlin.concurrent.thread
/**
* Note: to clear the emulator, invoke:
* adb uninstall io.element.android.libraries.push.pushstore.impl.test
*/
class DefaultUserPushStoreFactoryTest {
/**
* Ensure that creating UserPushStore is thread safe.
*/
@Test
fun testParallelCreation() {
val context = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext
val sessionId = SessionId("@alice:server.org")
val userPushStoreFactory = DefaultUserPushStoreFactory(context, NoOpSessionObserver())
var userPushStore1: UserPushStore? = null
val thread1 = thread {
userPushStore1 = userPushStoreFactory.create(sessionId)
}
var userPushStore2: UserPushStore? = null
val thread2 = thread {
userPushStore2 = userPushStoreFactory.create(sessionId)
}
thread1.join()
thread2.join()
runBlocking {
userPushStore1!!.areNotificationEnabledForDevice()
userPushStore2!!.areNotificationEnabledForDevice()
}
}
}

3
libraries/pushstore/impl/src/main/kotlin/io/element/android/libraries/pushstore/impl/DefaultUserPushStoreFactory.kt

@ -26,6 +26,7 @@ import io.element.android.libraries.pushstore.api.UserPushStore @@ -26,6 +26,7 @@ import io.element.android.libraries.pushstore.api.UserPushStore
import io.element.android.libraries.pushstore.api.UserPushStoreFactory
import io.element.android.libraries.sessionstorage.api.observer.SessionListener
import io.element.android.libraries.sessionstorage.api.observer.SessionObserver
import java.util.concurrent.ConcurrentHashMap
import javax.inject.Inject
@SingleIn(AppScope::class)
@ -39,7 +40,7 @@ class DefaultUserPushStoreFactory @Inject constructor( @@ -39,7 +40,7 @@ class DefaultUserPushStoreFactory @Inject constructor(
}
// We can have only one class accessing a single data store, so keep a cache of them.
private val cache = mutableMapOf<SessionId, UserPushStore>()
private val cache = ConcurrentHashMap<SessionId, UserPushStore>()
override fun create(userId: SessionId): UserPushStore {
return cache.getOrPut(userId) {
UserPushStoreDataStore(

26
libraries/session-storage/test/build.gradle.kts

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id("io.element.android-library")
}
android {
namespace = "io.element.android.libraries.sessionstorage.test"
}
dependencies {
implementation(projects.libraries.sessionStorage.api)
}

25
libraries/session-storage/test/src/main/kotlin/io/element/android/libraries/sessionstorage/test/observer/NoOpSessionObserver.kt

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
/*
* Copyright (c) 2023 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.element.android.libraries.sessionstorage.test.observer
import io.element.android.libraries.sessionstorage.api.observer.SessionListener
import io.element.android.libraries.sessionstorage.api.observer.SessionObserver
class NoOpSessionObserver : SessionObserver {
override fun addListener(listener: SessionListener) = Unit
override fun removeListener(listener: SessionListener) = Unit
}

1
tests/uitests/build.gradle.kts

@ -42,7 +42,6 @@ dependencies { @@ -42,7 +42,6 @@ dependencies {
testImplementation(libs.test.junit)
testImplementation(libs.test.parameter.injector)
testImplementation(projects.libraries.designsystem)
androidTestImplementation(libs.test.junitext)
ksp(libs.showkase.processor)
kspTest(libs.showkase.processor)

Loading…
Cancel
Save