No issue: make StrictMode suppression count thread safe.

upstream-sync
Michael Comella 4 years ago committed by Michael Comella
parent d7688c8427
commit bff8a0d6a7

@ -73,7 +73,7 @@ class StartupExcessiveResourceUseTest {
// This might cause intermittents: at an arbitrary point after start up (such as the visual
// completeness queue), we might run code on the main thread that suppresses StrictMode,
// causing this number to fluctuate depending on device speed. We'll deal with it if it occurs.
val actualSuppresionCount = activityTestRule.activity.components.strictMode.suppressionCount.toInt()
val actualSuppresionCount = activityTestRule.activity.components.strictMode.suppressionCount.get().toInt()
val actualRunBlocking = RunBlockingCounter.count.get()
assertEquals(STRICTMODE_FAILURE_MSG, EXPECTED_SUPPRESSION_COUNT, actualSuppresionCount)

@ -20,6 +20,7 @@ import mozilla.components.support.ktx.android.os.resetAfter
import org.mozilla.fenix.components.Components
import org.mozilla.fenix.perf.Performance
import org.mozilla.fenix.utils.Mockable
import java.util.concurrent.atomic.AtomicLong
private const val MANUFACTURE_HUAWEI: String = "HUAWEI"
private const val MANUFACTURE_ONE_PLUS: String = "OnePlus"
@ -49,9 +50,11 @@ class StrictModeManager(
* - a lint check: to ensure this value gets used instead of functions that work around it
* - code owners: to prevent modifications to these above items without perf knowing
* to make suppressions a more deliberate act.
*
* This is an Atomic* so it can be incremented from any thread.
*/
@VisibleForTesting(otherwise = PRIVATE)
var suppressionCount: Long = 0
val suppressionCount = AtomicLong(0)
/***
* Enables strict mode for debug purposes. meant to be run only in the main process.
@ -120,7 +123,7 @@ class StrictModeManager(
// This can overflow and crash. However, it's unlikely we'll suppress StrictMode 9
// quintillion times in a build config where StrictMode is enabled so we don't handle it
// because it'd increase complexity.
suppressionCount += 1
val suppressionCount = suppressionCount.incrementAndGet()
// We log so that devs are more likely to notice that we're suppressing StrictMode violations.
// We add profiler markers so that the perf team can easily identify IO locations in profiles.

@ -119,8 +119,8 @@ class StrictModeManagerTest {
@Test
fun `GIVEN we're in debug mode WHEN we suppress StrictMode THEN the suppressed count increases`() {
assertEquals(0, debugManager.suppressionCount)
assertEquals(0, debugManager.suppressionCount.get())
debugManager.resetAfter(StrictMode.allowThreadDiskReads()) { "" }
assertEquals(1, debugManager.suppressionCount)
assertEquals(1, debugManager.suppressionCount.get())
}
}

Loading…
Cancel
Save