Skip to content

Commit

Permalink
non-suspend method triggers a call but doesn't wait for it
Browse files Browse the repository at this point in the history
  • Loading branch information
Bohdan-Kim committed Mar 6, 2025
1 parent f1a38e2 commit 5868957
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class SDKBuilder(
* This method is open to be overridden by subclasses
*/
abstract suspend fun initialize(): GrowthBookSDK
abstract fun initializeWithoutCall(): GrowthBookSDK
abstract fun initializeWithoutWaitForCall(): GrowthBookSDK
}

/**
Expand Down Expand Up @@ -158,7 +158,7 @@ class GBSDKBuilder(
* Initialize the Kotlin SDK
* This init method takes less time than suspend version
*/
override fun initializeWithoutCall(): GrowthBookSDK {
override fun initializeWithoutWaitForCall(): GrowthBookSDK {
val gbContext = createGbContext()

if (enableLogging && !cachingEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ internal fun buildSDK(
encryptionKey = "",
trackingCallback = trackingCallback,
networkDispatcher = networkDispatcher,
).initializeWithoutCall()
).initializeWithoutWaitForCall()
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class GBEncryptedFeatures {
encryptionKey = "",
trackingCallback = { _, _ -> },
networkDispatcher = MockNetworkClient(null, null),
).initializeWithoutCall()
).initializeWithoutWaitForCall()

val keyString = "Ns04T5n9+59rl2x3SlNHtQ=="
val encryptedFeatures =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class GBFeatureValueTests {
actualNumberOfOnFeatureUsageCalls++
}

val sdk: GrowthBookSDK = builder.initializeWithoutCall()
val sdk: GrowthBookSDK = builder.initializeWithoutWaitForCall()

for (item in evalConditions) {
if (item is JsonArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GrowthBookSDKBuilderTests {
trackingCallback = { _: GBExperiment, _: GBExperimentResult? -> },
networkDispatcher = MockNetworkClient(null, null),
remoteEval = false
).initializeWithoutCall()
).initializeWithoutWaitForCall()

assertEquals(sdkInstance.getGBContext().apiKey, testApiKey)
assertTrue(sdkInstance.getGBContext().enabled)
Expand All @@ -64,7 +64,7 @@ class GrowthBookSDKBuilderTests {
networkDispatcher = MockNetworkClient(null, null),
remoteEval = false
).setRefreshHandler { isRefreshed, gbError ->
}.setEnabled(false).setForcedVariations(variations).setQAMode(true).initializeWithoutCall()
}.setEnabled(false).setForcedVariations(variations).setQAMode(true).initializeWithoutWaitForCall()

assertTrue(sdkInstance.getGBContext().apiKey == testApiKey)
assertFalse(sdkInstance.getGBContext().enabled)
Expand All @@ -90,7 +90,7 @@ class GrowthBookSDKBuilderTests {
).setRefreshHandler { isRefreshed, gbError ->

}
.setEnabled(false).setForcedVariations(variations).setQAMode(true).initializeWithoutCall()
.setEnabled(false).setForcedVariations(variations).setQAMode(true).initializeWithoutWaitForCall()

assertTrue(sdkInstance.getGBContext().apiKey == testApiKey)
assertFalse(sdkInstance.getGBContext().enabled)
Expand All @@ -114,7 +114,7 @@ class GrowthBookSDKBuilderTests {
remoteEval = false
).setRefreshHandler { _, gbError ->
isRefreshed = true
}.initializeWithoutCall()
}.initializeWithoutWaitForCall()

assertTrue(isRefreshed)

Expand Down Expand Up @@ -142,7 +142,7 @@ class GrowthBookSDKBuilderTests {
remoteEval = false
).setRefreshHandler { _, gbError ->
isRefreshed = true
}.initializeWithoutCall()
}.initializeWithoutWaitForCall()

assertTrue(isRefreshed)

Expand All @@ -162,7 +162,7 @@ class GrowthBookSDKBuilderTests {
networkDispatcher = MockNetworkClient(MockResponse.successResponse, null),
remoteEval = false
).setRefreshHandler { isRefreshed, gbError ->
}.initializeWithoutCall()
}.initializeWithoutWaitForCall()

val featureValue = sdkInstance.feature("fwrfewrfe")
assertEquals(featureValue.source, GBFeatureSource.unknownFeature)
Expand Down Expand Up @@ -198,7 +198,7 @@ class GrowthBookSDKBuilderTests {
remoteEval = false
).setPrefixForStickyBucketCachedDirectory(
prefix = "test_prefix"
).initializeWithoutCall()
).initializeWithoutWaitForCall()

assertTrue { sdkInstance.getGBContext().stickyBucketService != null }
assertTrue { sdkInstance.getGBContext().stickyBucketService is GBStickyBucketServiceImp }
Expand All @@ -215,7 +215,7 @@ class GrowthBookSDKBuilderTests {
networkDispatcher = MockNetworkClient(MockResponse.successResponse, null),
remoteEval = false
).setStickyBucketService()
.initializeWithoutCall()
.initializeWithoutWaitForCall()

assertTrue { sdkInstance.getGBContext().stickyBucketService != null }
assertTrue { sdkInstance.getGBContext().stickyBucketService is GBStickyBucketServiceImp }
Expand All @@ -233,7 +233,7 @@ class GrowthBookSDKBuilderTests {
networkDispatcher = MockNetworkClient(MockResponse.successResponse, null),
remoteEval = false
).setForcedVariations(expectedForcedVariation)
.initializeWithoutCall()
.initializeWithoutWaitForCall()

val actualForcedVariation = sdkInstance.getGBContext().forcedVariations

Expand All @@ -253,7 +253,7 @@ class GrowthBookSDKBuilderTests {
networkDispatcher = MockNetworkClient(MockResponse.successResponse, null),
remoteEval = true
).setForcedVariations(expectedForcedVariation)
.initializeWithoutCall()
.initializeWithoutWaitForCall()
sdkInstance.forcedFeatures = mapOf("featureForce" to GBNumber(112))

val actualForcedVariation = sdkInstance.getGBContext().forcedVariations
Expand All @@ -275,7 +275,7 @@ class GrowthBookSDKBuilderTests {
networkDispatcher = MockNetworkClient(MockResponse.successResponse, null),
remoteEval = false
)
.initializeWithoutCall()
.initializeWithoutWaitForCall()

sdkInstance.setAttributeOverrides(expectedAttributes)

Expand All @@ -297,7 +297,7 @@ class GrowthBookSDKBuilderTests {
networkDispatcher = MockNetworkClient(MockResponse.successResponse, null),
remoteEval = true
).setStickyBucketService(GBStickyBucketServiceImp())
.initializeWithoutCall()
.initializeWithoutWaitForCall()

sdkInstance.setAttributeOverrides(expectedAttributes)

Expand All @@ -321,7 +321,7 @@ class GrowthBookSDKBuilderTests {
trackingCallback = { _, _ -> },
networkDispatcher = MockNetworkClient(json, null),
remoteEval = false
).initializeWithoutCall()
).initializeWithoutWaitForCall()
}

// @Test
Expand Down

0 comments on commit 5868957

Please sign in to comment.