You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iceraven-browser/app/src/test/java/org/mozilla/fenix/ext/AtomicIntegerTest.kt

41 lines
1.3 KiB
Kotlin

[fenix] 15278 detekt rule runblocking (https://github.com/mozilla-mobile/fenix/pull/15942) * For https://github.com/mozilla-mobile/fenix/issues/15278: added CoroutineManager to count runBlocking calls * For https://github.com/mozilla-mobile/fenix/issues/15278: Added actual detekt rule for runblocking and its config to the yaml * For https://github.com/mozilla-mobile/fenix/issues/15278: Added unit test for RunblockingCounter * For https://github.com/mozilla-mobile/fenix/issues/15278: renamed StrictModeStartupSuppressionCountTest.kt to PerformanceStartupTest.kt and added runBlockingCount test * Lint fix * For https://github.com/mozilla-mobile/fenix/issues/15278: made runblocking a Long to prevent overflow * For https://github.com/mozilla-mobile/fenix/issues/15278: fixed MozRunblocking name, description and moved RunBlockingCounter to perf package * For https://github.com/mozilla-mobile/fenix/issues/15278:Renamed MozillaRunblockingCheck to MozillaRunBlockingCheck * For https://github.com/mozilla-mobile/fenix/issues/15278: Added setup for unit test, since it failed without restting counter * For https://github.com/mozilla-mobile/fenix/issues/15278: Fixed naming for RunBlocking lint check * For https://github.com/mozilla-mobile/fenix/issues/15278: removed changes made to test to use runBlockingIncrement * For https://github.com/mozilla-mobile/fenix/issues/15728: added test exclusion for runBlocking check * For https://github.com/mozilla-mobile/fenix/issues/15278: changed null check and added Synchronized to count setter * For https://github.com/mozilla-mobile/fenix/issues/15278: fix for nits * For https://github.com/mozilla-mobile/fenix/issues/15278: added StartupExcessiveResourceUseTest to CODEOWNERS * For https://github.com/mozilla-mobile/fenix/issues/15278: fixed for nits * For https://github.com/mozilla-mobile/fenix/issues/15278: Moved increment function to extension function and fixed indentation * For https://github.com/mozilla-mobile/fenix/issues/15278: Added tests for Atomic Integer extension and nit fix
4 years ago
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.ext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
[fenix] 15278 detekt rule runblocking (https://github.com/mozilla-mobile/fenix/pull/15942) * For https://github.com/mozilla-mobile/fenix/issues/15278: added CoroutineManager to count runBlocking calls * For https://github.com/mozilla-mobile/fenix/issues/15278: Added actual detekt rule for runblocking and its config to the yaml * For https://github.com/mozilla-mobile/fenix/issues/15278: Added unit test for RunblockingCounter * For https://github.com/mozilla-mobile/fenix/issues/15278: renamed StrictModeStartupSuppressionCountTest.kt to PerformanceStartupTest.kt and added runBlockingCount test * Lint fix * For https://github.com/mozilla-mobile/fenix/issues/15278: made runblocking a Long to prevent overflow * For https://github.com/mozilla-mobile/fenix/issues/15278: fixed MozRunblocking name, description and moved RunBlockingCounter to perf package * For https://github.com/mozilla-mobile/fenix/issues/15278:Renamed MozillaRunblockingCheck to MozillaRunBlockingCheck * For https://github.com/mozilla-mobile/fenix/issues/15278: Added setup for unit test, since it failed without restting counter * For https://github.com/mozilla-mobile/fenix/issues/15278: Fixed naming for RunBlocking lint check * For https://github.com/mozilla-mobile/fenix/issues/15278: removed changes made to test to use runBlockingIncrement * For https://github.com/mozilla-mobile/fenix/issues/15728: added test exclusion for runBlocking check * For https://github.com/mozilla-mobile/fenix/issues/15278: changed null check and added Synchronized to count setter * For https://github.com/mozilla-mobile/fenix/issues/15278: fix for nits * For https://github.com/mozilla-mobile/fenix/issues/15278: added StartupExcessiveResourceUseTest to CODEOWNERS * For https://github.com/mozilla-mobile/fenix/issues/15278: fixed for nits * For https://github.com/mozilla-mobile/fenix/issues/15278: Moved increment function to extension function and fixed indentation * For https://github.com/mozilla-mobile/fenix/issues/15278: Added tests for Atomic Integer extension and nit fix
4 years ago
import org.junit.Test
import java.util.concurrent.atomic.AtomicInteger
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
class AtomicIntegerTest {
@Test
fun `Safely increment an AtomicInteger from different coroutines`() {
val integer = AtomicInteger(0)
runBlocking {
for (i in 1..2) {
launch(Dispatchers.Default) {
integer.getAndIncrementNoOverflow()
}
}
}
assertEquals(integer.get(), 2)
}
@Test
fun `Incrementing the AtomicInteger should not overflow`() {
val integer = AtomicInteger(Integer.MAX_VALUE)
integer.getAndIncrementNoOverflow()
assertEquals(integer.get(), Integer.MAX_VALUE)
}
}