diff --git a/.circleci/config.yml b/.circleci/config.yml
index 15205bf6e..20dca0e91 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -151,9 +151,7 @@ jobs:
- android/restore-build-cache
- run:
name: Run Tests
- # We are running tests in the "defaults" flavor only. If we ever add/remove flavors, we will need to update
- # this command.
- command: ./gradlew lint testDefaultsDebugUnitTest testDefaultsReleaseUnitTest
+ command: ./gradlew lint test
- run:
name: Consolidate artifacts
command: |
@@ -161,12 +159,12 @@ jobs:
find . -type f -regex ".*/build/test-results/.*xml" -exec cp --parents {} build/test-results/ \;
- run:
name: Kover HTML
- command: ./gradlew purchases:koverHtmlReportDefaultsRelease
+ command: ./gradlew purchases:koverHtmlReportRelease
- run:
name: Kover XML
- command: ./gradlew purchases:koverXmlReportDefaultsRelease
+ command: ./gradlew purchases:koverXmlReportRelease
- codecov/upload:
- file: purchases/build/reports/kover/reportDefaultsRelease.xml
+ file: purchases/build/reports/kover/reportRelease.xml
- android/save-build-cache
- store_artifacts:
path: build/reports
diff --git a/.run/Debug tests.run.xml b/.run/Debug tests.run.xml
index 75065f4f4..1b2d8596b 100644
--- a/.run/Debug tests.run.xml
+++ b/.run/Debug tests.run.xml
@@ -10,7 +10,7 @@
diff --git a/.run/Purchases Integration Tests (set purchases module variant before executing).run.xml b/.run/Purchases Integration Tests.run.xml
similarity index 94%
rename from .run/Purchases Integration Tests (set purchases module variant before executing).run.xml
rename to .run/Purchases Integration Tests.run.xml
index ce6353d65..583d8a7f4 100644
--- a/.run/Purchases Integration Tests (set purchases module variant before executing).run.xml
+++ b/.run/Purchases Integration Tests.run.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/.run/Release tests.run.xml b/.run/Release tests.run.xml
index 926d36958..648732859 100644
--- a/.run/Release tests.run.xml
+++ b/.run/Release tests.run.xml
@@ -10,7 +10,7 @@
-
+
diff --git a/base-application.gradle b/base-application.gradle
index f514118f7..b1226da2d 100644
--- a/base-application.gradle
+++ b/base-application.gradle
@@ -5,10 +5,6 @@ android {
defaultConfig {
minSdkVersion minVersion
targetSdkVersion compileVersion
- // Library modules have a new dimension used to add extra APIs for integration tests
- // Our applications however don't need the extra flavor. This makes sure that we use the
- // flavor without the extra APIs in our applications.
- missingDimensionStrategy 'extraAPIs', 'defaults'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
diff --git a/fastlane/Fastfile b/fastlane/Fastfile
index ee3329e3b..a25f743c4 100644
--- a/fastlane/Fastfile
+++ b/fastlane/Fastfile
@@ -175,12 +175,11 @@ platform :android do
new_text: ENV['LOAD_SHEDDER_REVENUECAT_API_KEY'],
paths_of_files_to_update: [constants_path]
)
- # Running integration test flavor in order to make backend tests run faster, since the jittering is too
- # long in the `defaults` flavor.
gradle(
- task: ':purchases:testIntegrationTestDebugUnitTest',
+ task: ':purchases:testDebugUnitTest',
properties: {
- "RUN_INTEGRATION_TESTS" => true
+ "RUN_INTEGRATION_TESTS" => true,
+ "minSdkVersion" => 21,
}
)
end
@@ -221,7 +220,7 @@ platform :android do
def build_purchases_integration_tests(app_name:, api_key:, google_purchase_token:, product_id_to_purchase:,
base_plan_id_to_purchase:, active_entitlements_to_verify: '',
proxy_url: nil, build_type: 'release')
- constants_path = './purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/Constants.kt'
+ constants_path = './purchases/src/androidTest/kotlin/com/revenuecat/purchases/Constants.kt'
replace_text_in_files(
previous_text: "REVENUECAT_API_KEY",
new_text: api_key,
@@ -472,11 +471,12 @@ def build_purchases_android_test_apk(package_name, apk_name, build_type)
task: ':purchases:assembleAndroidTest',
properties: {
"testApplicationId" => package_name,
- "testBuildType" => build_type
+ "testBuildType" => build_type,
+ "minSdkVersion" => 21
}
)
- apk_path = "../purchases/build/outputs/apk/androidTest/integrationTest/#{build_type}/purchases-integrationTest-#{build_type}-androidTest.apk"
- new_apk_path = "../purchases/build/outputs/apk/androidTest/integrationTest/#{build_type}/#{apk_name}.apk"
+ apk_path = "../purchases/build/outputs/apk/androidTest/#{build_type}/purchases-#{build_type}-androidTest.apk"
+ new_apk_path = "../purchases/build/outputs/apk/androidTest/#{build_type}/#{apk_name}.apk"
sh "mv #{apk_path} #{new_apk_path}"
copy_artifacts(
target_path: 'purchases/test_artifacts',
diff --git a/gradle.properties b/gradle.properties
index b0b9ef17f..d692e92c5 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -42,7 +42,7 @@ purchaseTesterMinSdkVersion=21
#Do not sign releases. When calling uploadArchives pass -PRELEASE_SIGNING_ENABLED=true
RELEASE_SIGNING_ENABLED=false
-ANDROID_VARIANT_TO_PUBLISH=defaultsRelease
+ANDROID_VARIANT_TO_PUBLISH=release
SONATYPE_HOST=DEFAULT
SONATYPE_AUTOMATIC_RELEASE=true
diff --git a/library.gradle b/library.gradle
index 51c6fac77..19c659af0 100644
--- a/library.gradle
+++ b/library.gradle
@@ -2,19 +2,8 @@ android {
compileSdkVersion compileVersion
buildToolsVersion buildToolsVersion
- flavorDimensions "extraAPIs"
- productFlavors {
- defaults {
- dimension "extraAPIs"
- }
- integrationTest {
- dimension "extraAPIs"
- minSdkVersion 21 // Needed because mockk-android requires API 21
- }
- }
-
defaultConfig {
- minSdkVersion minVersion
+ minSdkVersion obtainMinSdkVersion()
targetSdkVersion compileVersion
versionCode 1
versionName "6.8.0-SNAPSHOT"
@@ -42,3 +31,13 @@ project.afterEvaluate {
// after https://github.com/Kotlin/kotlinx-kover/issues/362 is fixed
project.pluginManager.apply("org.jetbrains.kotlinx.kover")
}
+
+def obtainMinSdkVersion() {
+ def result = minVersion
+
+ if (project.hasProperty("minSdkVersion")) {
+ result = project.getProperties().get("minSdkVersion").toInteger()
+ }
+
+ result
+}
diff --git a/purchases/build.gradle b/purchases/build.gradle
index 455551f73..a696b4974 100644
--- a/purchases/build.gradle
+++ b/purchases/build.gradle
@@ -15,14 +15,12 @@ android {
buildConfig true
}
- productFlavors {
- integrationTest {
- testApplicationId obtainTestApplicationId()
- testBuildType obtainTestBuildType()
- packagingOptions {
- resources.excludes.add("META-INF/LICENSE.md")
- resources.excludes.add("META-INF/LICENSE-notice.md")
- }
+ defaultConfig {
+ testApplicationId obtainTestApplicationId()
+ testBuildType obtainTestBuildType()
+ packagingOptions {
+ resources.excludes.add("META-INF/LICENSE.md")
+ resources.excludes.add("META-INF/LICENSE-notice.md")
}
}
@@ -81,18 +79,15 @@ dependencies {
testImplementation libs.okhttp.mockwebserver
testImplementation libs.playServices.ads.identifier
- integrationTestImplementation libs.androidx.appcompat
- integrationTestImplementation libs.material
- integrationTestImplementation libs.androidx.constraintlayout
-
- androidTestIntegrationTestImplementation libs.androidx.lifecycle.runtime.ktx
- androidTestIntegrationTestImplementation libs.androidx.test.espresso.core
- androidTestIntegrationTestImplementation libs.androidx.test.runner
- androidTestIntegrationTestImplementation libs.androidx.test.rules
- androidTestIntegrationTestImplementation libs.androidx.test.junit
- androidTestIntegrationTestImplementation libs.assertJ
- androidTestIntegrationTestImplementation libs.mockk.android
- androidTestIntegrationTestImplementation libs.mockk.agent
+ androidTestImplementation libs.androidx.appcompat
+ androidTestImplementation libs.androidx.lifecycle.runtime.ktx
+ androidTestImplementation libs.androidx.test.espresso.core
+ androidTestImplementation libs.androidx.test.runner
+ androidTestImplementation libs.androidx.test.rules
+ androidTestImplementation libs.androidx.test.junit
+ androidTestImplementation libs.assertJ
+ androidTestImplementation libs.mockk.android
+ androidTestImplementation libs.mockk.agent
}
tasks.dokkaHtmlPartial.configure {
diff --git a/purchases/src/androidTest/AndroidManifest.xml b/purchases/src/androidTest/AndroidManifest.xml
new file mode 100644
index 000000000..2d4d152b6
--- /dev/null
+++ b/purchases/src/androidTest/AndroidManifest.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
diff --git a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/BasePurchasesIntegrationTest.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/BasePurchasesIntegrationTest.kt
similarity index 100%
rename from purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/BasePurchasesIntegrationTest.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/BasePurchasesIntegrationTest.kt
diff --git a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/Constants.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/Constants.kt
similarity index 100%
rename from purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/Constants.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/Constants.kt
diff --git a/purchases/src/integrationTest/kotlin/com/revenuecat/purchases/MainActivity.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/MainActivity.kt
similarity index 72%
rename from purchases/src/integrationTest/kotlin/com/revenuecat/purchases/MainActivity.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/MainActivity.kt
index ee8c0253c..a1ea185a9 100644
--- a/purchases/src/integrationTest/kotlin/com/revenuecat/purchases/MainActivity.kt
+++ b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/MainActivity.kt
@@ -2,9 +2,9 @@ package com.revenuecat.purchases
import android.os.Bundle
import android.widget.LinearLayout
-import androidx.appcompat.app.AppCompatActivity
+import androidx.fragment.app.FragmentActivity
-class MainActivity : AppCompatActivity() {
+class MainActivity : FragmentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(LinearLayout(this))
diff --git a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/PurchasesIntegrationTest.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/PurchasesIntegrationTest.kt
similarity index 100%
rename from purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/PurchasesIntegrationTest.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/PurchasesIntegrationTest.kt
diff --git a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/factories/StoreProductFactory.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/factories/StoreProductFactory.kt
similarity index 100%
rename from purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/factories/StoreProductFactory.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/factories/StoreProductFactory.kt
diff --git a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/factories/StoreTransactionFactory.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/factories/StoreTransactionFactory.kt
similarity index 100%
rename from purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/factories/StoreTransactionFactory.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/factories/StoreTransactionFactory.kt
diff --git a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/helpers/BillingAbstractMockHelper.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/helpers/BillingAbstractMockHelper.kt
similarity index 100%
rename from purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/helpers/BillingAbstractMockHelper.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/helpers/BillingAbstractMockHelper.kt
diff --git a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/offlineentitlements/BaseOfflineEntitlementsIntegrationTest.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/offlineentitlements/BaseOfflineEntitlementsIntegrationTest.kt
similarity index 100%
rename from purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/offlineentitlements/BaseOfflineEntitlementsIntegrationTest.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/offlineentitlements/BaseOfflineEntitlementsIntegrationTest.kt
diff --git a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/offlineentitlements/OfflineEntitlementsFreshInstallIntegrationTest.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/offlineentitlements/OfflineEntitlementsFreshInstallIntegrationTest.kt
similarity index 100%
rename from purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/offlineentitlements/OfflineEntitlementsFreshInstallIntegrationTest.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/offlineentitlements/OfflineEntitlementsFreshInstallIntegrationTest.kt
diff --git a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/offlineentitlements/OfflineEntitlementsWithInitialRequestsCompletedIntegrationTest.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/offlineentitlements/OfflineEntitlementsWithInitialRequestsCompletedIntegrationTest.kt
similarity index 100%
rename from purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/offlineentitlements/OfflineEntitlementsWithInitialRequestsCompletedIntegrationTest.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/offlineentitlements/OfflineEntitlementsWithInitialRequestsCompletedIntegrationTest.kt
diff --git a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/purchasesExtensions.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/purchasesExtensions.kt
similarity index 96%
rename from purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/purchasesExtensions.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/purchasesExtensions.kt
index 2a84a48cd..f8fe299b2 100644
--- a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/purchasesExtensions.kt
+++ b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/purchasesExtensions.kt
@@ -16,6 +16,7 @@ internal fun Purchases.Companion.configure(
overrideBillingAbstract,
forceServerErrors,
forceSigningErrors,
+ runningIntegrationTests = true,
).also {
@SuppressLint("RestrictedApi")
sharedInstance = it
diff --git a/purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/trustedentitlements/TrustedEntitlementsInformationalModeIntegrationTest.kt b/purchases/src/androidTest/kotlin/com/revenuecat/purchases/trustedentitlements/TrustedEntitlementsInformationalModeIntegrationTest.kt
similarity index 100%
rename from purchases/src/androidTestIntegrationTest/kotlin/com/revenuecat/purchases/trustedentitlements/TrustedEntitlementsInformationalModeIntegrationTest.kt
rename to purchases/src/androidTest/kotlin/com/revenuecat/purchases/trustedentitlements/TrustedEntitlementsInformationalModeIntegrationTest.kt
diff --git a/purchases/src/integrationTest/AndroidManifest.xml b/purchases/src/integrationTest/AndroidManifest.xml
deleted file mode 100644
index b1b7b73b1..000000000
--- a/purchases/src/integrationTest/AndroidManifest.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/purchases/src/integrationTest/kotlin/com/revenuecat/purchases/common/DispatcherConstants.kt b/purchases/src/integrationTest/kotlin/com/revenuecat/purchases/common/DispatcherConstants.kt
deleted file mode 100644
index 234d58c52..000000000
--- a/purchases/src/integrationTest/kotlin/com/revenuecat/purchases/common/DispatcherConstants.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.revenuecat.purchases.common
-
-import kotlin.time.Duration.Companion.milliseconds
-
-// These values are reduced from the values used in the original code to make the tests run faster.
-internal object DispatcherConstants {
- val jitterDelay = 500L.milliseconds
- val jitterLongDelay = 1000L.milliseconds
-}
diff --git a/purchases/src/integrationTest/res/mipmap-hdpi/ic_launcher.png b/purchases/src/integrationTest/res/mipmap-hdpi/ic_launcher.png
deleted file mode 100644
index a571e6009..000000000
Binary files a/purchases/src/integrationTest/res/mipmap-hdpi/ic_launcher.png and /dev/null differ
diff --git a/purchases/src/integrationTest/res/mipmap-hdpi/ic_launcher_round.png b/purchases/src/integrationTest/res/mipmap-hdpi/ic_launcher_round.png
deleted file mode 100644
index 61da551c5..000000000
Binary files a/purchases/src/integrationTest/res/mipmap-hdpi/ic_launcher_round.png and /dev/null differ
diff --git a/purchases/src/integrationTest/res/mipmap-mdpi/ic_launcher.png b/purchases/src/integrationTest/res/mipmap-mdpi/ic_launcher.png
deleted file mode 100644
index c41dd2853..000000000
Binary files a/purchases/src/integrationTest/res/mipmap-mdpi/ic_launcher.png and /dev/null differ
diff --git a/purchases/src/integrationTest/res/mipmap-mdpi/ic_launcher_round.png b/purchases/src/integrationTest/res/mipmap-mdpi/ic_launcher_round.png
deleted file mode 100644
index db5080a75..000000000
Binary files a/purchases/src/integrationTest/res/mipmap-mdpi/ic_launcher_round.png and /dev/null differ
diff --git a/purchases/src/integrationTest/res/mipmap-xhdpi/ic_launcher.png b/purchases/src/integrationTest/res/mipmap-xhdpi/ic_launcher.png
deleted file mode 100644
index 6dba46dab..000000000
Binary files a/purchases/src/integrationTest/res/mipmap-xhdpi/ic_launcher.png and /dev/null differ
diff --git a/purchases/src/integrationTest/res/mipmap-xhdpi/ic_launcher_round.png b/purchases/src/integrationTest/res/mipmap-xhdpi/ic_launcher_round.png
deleted file mode 100644
index da31a871c..000000000
Binary files a/purchases/src/integrationTest/res/mipmap-xhdpi/ic_launcher_round.png and /dev/null differ
diff --git a/purchases/src/integrationTest/res/mipmap-xxhdpi/ic_launcher.png b/purchases/src/integrationTest/res/mipmap-xxhdpi/ic_launcher.png
deleted file mode 100644
index 15ac68172..000000000
Binary files a/purchases/src/integrationTest/res/mipmap-xxhdpi/ic_launcher.png and /dev/null differ
diff --git a/purchases/src/integrationTest/res/mipmap-xxhdpi/ic_launcher_round.png b/purchases/src/integrationTest/res/mipmap-xxhdpi/ic_launcher_round.png
deleted file mode 100644
index b216f2d31..000000000
Binary files a/purchases/src/integrationTest/res/mipmap-xxhdpi/ic_launcher_round.png and /dev/null differ
diff --git a/purchases/src/integrationTest/res/mipmap-xxxhdpi/ic_launcher.png b/purchases/src/integrationTest/res/mipmap-xxxhdpi/ic_launcher.png
deleted file mode 100644
index f25a41974..000000000
Binary files a/purchases/src/integrationTest/res/mipmap-xxxhdpi/ic_launcher.png and /dev/null differ
diff --git a/purchases/src/integrationTest/res/mipmap-xxxhdpi/ic_launcher_round.png b/purchases/src/integrationTest/res/mipmap-xxxhdpi/ic_launcher_round.png
deleted file mode 100644
index e96783ccc..000000000
Binary files a/purchases/src/integrationTest/res/mipmap-xxxhdpi/ic_launcher_round.png and /dev/null differ
diff --git a/purchases/src/integrationTest/res/values/colors.xml b/purchases/src/integrationTest/res/values/colors.xml
deleted file mode 100644
index f8c6127d3..000000000
--- a/purchases/src/integrationTest/res/values/colors.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
- #FFBB86FC
- #FF6200EE
- #FF3700B3
- #FF03DAC5
- #FF018786
- #FF000000
- #FFFFFFFF
-
\ No newline at end of file
diff --git a/purchases/src/integrationTest/res/values/strings.xml b/purchases/src/integrationTest/res/values/strings.xml
deleted file mode 100644
index 39fc1b1b7..000000000
--- a/purchases/src/integrationTest/res/values/strings.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
- Integration Tests
-
\ No newline at end of file
diff --git a/purchases/src/main/kotlin/com/revenuecat/purchases/PurchasesFactory.kt b/purchases/src/main/kotlin/com/revenuecat/purchases/PurchasesFactory.kt
index 8d71440fc..811bf338e 100644
--- a/purchases/src/main/kotlin/com/revenuecat/purchases/PurchasesFactory.kt
+++ b/purchases/src/main/kotlin/com/revenuecat/purchases/PurchasesFactory.kt
@@ -6,7 +6,6 @@ import android.content.Context
import android.content.pm.PackageManager
import android.preference.PreferenceManager
import androidx.annotation.VisibleForTesting
-import com.revenuecat.purchases.api.BuildConfig
import com.revenuecat.purchases.common.Anonymizer
import com.revenuecat.purchases.common.AppConfig
import com.revenuecat.purchases.common.Backend
@@ -45,7 +44,6 @@ import java.util.concurrent.ThreadFactory
internal class PurchasesFactory(
private val apiKeyValidator: APIKeyValidator = APIKeyValidator(),
) {
- private val integrationTestFlavor = "integrationTest"
@Suppress("LongMethod", "LongParameterList")
fun createPurchases(
@@ -55,6 +53,7 @@ internal class PurchasesFactory(
overrideBillingAbstract: BillingAbstract? = null,
forceServerErrors: Boolean = false,
forceSigningError: Boolean = false,
+ runningIntegrationTests: Boolean = false,
): Purchases {
validateConfiguration(configuration)
@@ -67,7 +66,7 @@ internal class PurchasesFactory(
proxyURL,
store,
dangerousSettings,
- BuildConfig.FLAVOR == integrationTestFlavor,
+ runningIntegrationTests,
forceServerErrors,
forceSigningError,
)
@@ -77,8 +76,8 @@ internal class PurchasesFactory(
val sharedPreferencesForETags = ETagManager.initializeSharedPreferences(context)
val eTagManager = ETagManager(sharedPreferencesForETags)
- val dispatcher = Dispatcher(service ?: createDefaultExecutor())
- val diagnosticsDispatcher = Dispatcher(createDiagnosticsExecutor())
+ val dispatcher = Dispatcher(service ?: createDefaultExecutor(), runningIntegrationTests)
+ val diagnosticsDispatcher = Dispatcher(createDiagnosticsExecutor(), runningIntegrationTests)
var diagnosticsFileHelper: DiagnosticsFileHelper? = null
var diagnosticsTracker: DiagnosticsTracker? = null
diff --git a/purchases/src/main/kotlin/com/revenuecat/purchases/common/Dispatcher.kt b/purchases/src/main/kotlin/com/revenuecat/purchases/common/Dispatcher.kt
index 7cdf6a731..53f9bfae5 100644
--- a/purchases/src/main/kotlin/com/revenuecat/purchases/common/Dispatcher.kt
+++ b/purchases/src/main/kotlin/com/revenuecat/purchases/common/Dispatcher.kt
@@ -24,7 +24,11 @@ internal enum class Delay(val minDelay: Duration, val maxDelay: Duration) {
internal open class Dispatcher(
private val executorService: ExecutorService,
+ private val runningIntegrationTests: Boolean = false,
) {
+ private companion object {
+ const val INTEGRATION_TEST_DELAY_PERCENTAGE: Double = .01
+ }
abstract class AsyncCall : Runnable {
@Throws(JSONException::class, IOException::class)
@@ -56,7 +60,10 @@ internal open class Dispatcher(
synchronized(this.executorService) {
if (!executorService.isShutdown) {
val future = if (delay != Delay.NONE && executorService is ScheduledExecutorService) {
- val delayToApply = (delay.minDelay.inWholeMilliseconds..delay.maxDelay.inWholeMilliseconds).random()
+ var delayToApply = (delay.minDelay.inWholeMilliseconds..delay.maxDelay.inWholeMilliseconds).random()
+ if (runningIntegrationTests) {
+ delayToApply = (delayToApply * INTEGRATION_TEST_DELAY_PERCENTAGE).toLong()
+ }
executorService.schedule(command, delayToApply, TimeUnit.MILLISECONDS)
} else {
executorService.submit(command)
diff --git a/purchases/src/defaults/kotlin/com/revenuecat/purchases/common/DispatcherConstants.kt b/purchases/src/main/kotlin/com/revenuecat/purchases/common/DispatcherConstants.kt
similarity index 70%
rename from purchases/src/defaults/kotlin/com/revenuecat/purchases/common/DispatcherConstants.kt
rename to purchases/src/main/kotlin/com/revenuecat/purchases/common/DispatcherConstants.kt
index c5b2df91f..024cfa2b9 100644
--- a/purchases/src/defaults/kotlin/com/revenuecat/purchases/common/DispatcherConstants.kt
+++ b/purchases/src/main/kotlin/com/revenuecat/purchases/common/DispatcherConstants.kt
@@ -2,7 +2,6 @@ package com.revenuecat.purchases.common
import kotlin.time.Duration.Companion.milliseconds
-// These values are modified in the `integrationTest` flavor to make the tests run faster.
internal object DispatcherConstants {
val jitterDelay = 5000L.milliseconds
val jitterLongDelay = 10000L.milliseconds
diff --git a/purchases/src/test/java/com/revenuecat/purchases/backend_integration_tests/BaseBackendIntegrationTest.kt b/purchases/src/test/java/com/revenuecat/purchases/backend_integration_tests/BaseBackendIntegrationTest.kt
index 51c55a4f4..bc054df6a 100644
--- a/purchases/src/test/java/com/revenuecat/purchases/backend_integration_tests/BaseBackendIntegrationTest.kt
+++ b/purchases/src/test/java/com/revenuecat/purchases/backend_integration_tests/BaseBackendIntegrationTest.kt
@@ -81,8 +81,8 @@ internal abstract class BaseBackendIntegrationTest {
every { forceServerErrors } returns false
every { forceSigningErrors } returns false
}
- dispatcher = Dispatcher(Executors.newSingleThreadScheduledExecutor())
- diagnosticsDispatcher = Dispatcher(Executors.newSingleThreadScheduledExecutor())
+ dispatcher = Dispatcher(Executors.newSingleThreadScheduledExecutor(), runningIntegrationTests = true)
+ diagnosticsDispatcher = Dispatcher(Executors.newSingleThreadScheduledExecutor(), runningIntegrationTests = true)
sharedPreferencesEditor = mockk().apply {
every { putString(any(), any()) } returns this
every { apply() } just Runs
diff --git a/purchases/src/test/java/com/revenuecat/purchases/common/DispatcherTest.kt b/purchases/src/test/java/com/revenuecat/purchases/common/DispatcherTest.kt
index 48fad4d59..7239eb37e 100644
--- a/purchases/src/test/java/com/revenuecat/purchases/common/DispatcherTest.kt
+++ b/purchases/src/test/java/com/revenuecat/purchases/common/DispatcherTest.kt
@@ -12,6 +12,7 @@ import com.revenuecat.purchases.common.networking.HTTPResult
import com.revenuecat.purchases.common.verification.SignatureVerificationException
import io.mockk.every
import io.mockk.mockk
+import io.mockk.spyk
import io.mockk.verify
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.fail
@@ -21,6 +22,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
import java.util.concurrent.ExecutorService
+import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.SynchronousQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
@@ -184,6 +186,40 @@ class DispatcherTest {
assertThat(currentThreadExecutorService.executeCalled).isTrue
}
+ @Test
+ fun `executes with correct delay when not in integration tests`() {
+ val executorService = mockk(relaxed = true)
+ val dispatcher = Dispatcher(executorService, runningIntegrationTests = false)
+ dispatcher.enqueue({ }, delay = Delay.LONG)
+ verify(exactly = 1) {
+ executorService.schedule(
+ any(),
+ withArg { delay ->
+ assertThat(delay).isGreaterThanOrEqualTo(5000L)
+ assertThat(delay).isLessThan(10000L)
+ },
+ TimeUnit.MILLISECONDS,
+ )
+ }
+ }
+
+ @Test
+ fun `executes with correct delay when in integration tests`() {
+ val executorService = mockk(relaxed = true)
+ val dispatcher = Dispatcher(executorService, runningIntegrationTests = true)
+ dispatcher.enqueue({ }, delay = Delay.LONG)
+ verify(exactly = 1) {
+ executorService.schedule(
+ any(),
+ withArg { delay ->
+ assertThat(delay).isGreaterThanOrEqualTo(50L)
+ assertThat(delay).isLessThan(100L)
+ },
+ TimeUnit.MILLISECONDS,
+ )
+ }
+ }
+
class CurrentThreadExecutorService(
private val callerRunsPolicy: CallerRunsPolicy = CallerRunsPolicy()
): ThreadPoolExecutor(