Offline backlog blocks crash collection in other profiles

Aperta
#23,770 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
android, kotlin
Ambito
mobile

Direzione di ricerca

The reproduction is a new test, ProfileCrashReportQueueTest.kt, which fills the approved folder of one profile via ReportLocator and then asserts that another profile can still collect, using the plugins' shouldStartCollecting. Run it first to confirm the failure. Done means the other profile collects while the offending profile stays limited, but the fix is unresolved: a per-profile cap may exceed the shared sender's batch limit, so the design needs maintainer input first.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

code-scan Multi Profile Needs Triage

Assisted-by: GPT-6.1-Terra xhigh & GPT-6.2-Sol high & GPT-6.2-Sol xhigh & GPT-6.2-Astra xhigh

Offline backlog blocks crash collection in other profiles [P2]
Subject: Offline backlog blocks crash collection in other profiles

Five unsent reports from one profile can prevent ACRA from collecting a new crash in another profile.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileCrashReportQueueTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileCrashReportQueueTest.kt
new file mode 100644
index 0000000000..6b2ae1cb86
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileCrashReportQueueTest.kt
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki.multiprofile
+
+import android.app.Application
+import android.content.Context
+import androidx.core.content.pm.PackageInfoCompat
+import androidx.test.core.app.ApplicationProvider
+import com.ichi2.anki.acraCoreConfigBuilder
+import com.ichi2.anki.common.crashreporting.CrashReportService
+import com.ichi2.anki.initializeAcraCrashReporter
+import com.ichi2.testutils.EmptyApplication
+import com.ichi2.testutils.common.OS
+import io.mockk.every
+import io.mockk.mockkStatic
+import io.mockk.unmockkAll
+import org.acra.ACRA
+import org.acra.ACRAConstants
+import org.acra.ReportField
+import org.acra.builder.ReportBuilder
+import org.acra.config.CoreConfiguration
+import org.acra.config.CoreConfigurationBuilder
+import org.acra.config.LimiterConfiguration
+import org.acra.config.ReportingAdministrator
+import org.acra.data.CrashReportData
+import org.acra.file.CrashReportPersister
+import org.acra.file.ReportLocator
+import org.junit.After
+import org.junit.Assume.assumeFalse
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+import org.robolectric.annotation.Config
+import java.io.File
+import java.text.SimpleDateFormat
+import java.util.Date
+import java.util.Locale
+import kotlin.test.assertFalse
+import kotlin.test.assertTrue
+
+@RunWith(RobolectricTestRunner::class)
+@Config(application = EmptyApplication::class)
+class ProfileCrashReportQueueTest {
+    @After
+    fun tearDown() {
+        unmockkAll()
+    }
+
+    @Test
+    fun `an offline backlog only limits the profile that collected it`() {
+        assumeFalse("ACRA's report file names contain ':', which Windows doesn't allow", OS.WINDOWS.isRunning())
+        val application = ApplicationProvider.getApplicationContext<Application>()
+        mockkStatic(ACRA::class)
+        every { ACRA.init(any<Application>(), any<CoreConfigurationBuilder>(), any()) } returns Unit
+        with(application) { initializeAcraCrashReporter() }
+        val config = CrashReportService.acraCoreConfigBuilder.build()
+        val offlineProfile =
+            ProfileContextWrapper.create(application, ProfileId("p_offline"), File(application.dataDir, "p_offline"))
+        val otherProfile =
+            ProfileContextWrapper.create(application, ProfileId("p_other"), File(application.dataDir, "p_other"))
+        val version = PackageInfoCompat.getLongVersionCode(application.packageManager.getPackageInfo(application.packageName, 0))
+        val timestamps = SimpleDateFormat(ACRAConstants.DATE_TIME_FORMAT_STRING, Locale.ENGLISH)
+        val approved = ReportLocator(offlineProfile).approvedFolder
+
+        // Reports that have been approved but could not be uploaded.
+        repeat(LimiterConfiguration().failedReportLimit) { index ->
+            val timestamp = timestamps.format(Date(index.toLong()))
+            val report =
+                CrashReportData().apply {
+                    put(ReportField.APP_VERSION_CODE, version)
+                    put(ReportField.FILE_PATH, offlineProfile.filesDir.absolutePath)
+                    put(ReportField.USER_CRASH_DATE, timestamp)
+                }
+            CrashReportPersister().store(report, File(approved, timestamp + ACRAConstants.REPORTFILE_EXTENSION))
+        }
+
+        assertFalse(shouldCollect(offlineProfile, config), "A full queue must keep limiting its own profile")
+        assertTrue(shouldCollect(otherProfile, config), "Another profile's approved reports must not fill this profile's queue")
+    }
+
+    private fun shouldCollect(
+        profile: Context,
+        config: CoreConfiguration,
+    ): Boolean {
+        val report = ReportBuilder().exception(IllegalStateException("new crash"))
+        return config.pluginLoader.loadEnabled(config, ReportingAdministrator::class.java).all {
+            it.shouldStartCollecting(profile, config, report)
+        }
+    }
+}

Fix unresolved: no compatible temporary fix verified. A per-profile cap can exceed the shared sender’s batch limit and leave reports queued.

Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/23337#pullrequestreview-6047733103, with a per-profile queue proposed in https://github.com/ankidroid/Anki-Android/pull/23337#issuecomment-7170891275

Lingua principale
Kotlin
Stelle
12.3k
Fork
3.1k
Merge medio
2g 1h
PR unite (30g)
311

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ankidroid/Anki-Android

Tutte le issue di ankidroid/Anki-Android

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.