Skip to content

Fix settings not propogate to plugins when offline #269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
propagate cached settings object in network failure
  • Loading branch information
wenxi-zeng committed Jun 24, 2025
commit f4fad4fed45cc0c9c30ffdf44eecbaaf3bdbb6ab
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ suspend fun Analytics.checkSettings() {
settingsObj?.let {
log("Dispatching update settings on ${Thread.currentThread().name}")
store.dispatch(System.UpdateSettingsAction(settingsObj), System::class)
update(settingsObj)
}

store.currentState(System::class)?.let { system ->
system.settings?.let { settings ->
log("Propagating settings on ${Thread.currentThread().name}")
update(settings)
}
}

// we're good to go back to a running state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.segment.analytics.kotlin.core.platform.Plugin
import com.segment.analytics.kotlin.core.utils.StubPlugin
import com.segment.analytics.kotlin.core.utils.mockHTTPClient
import com.segment.analytics.kotlin.core.utils.testAnalytics
import io.mockk.every
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.test.TestScope
Expand Down Expand Up @@ -75,6 +76,34 @@ class SettingsTests {
}

@Test
fun `cached settings propagates to plugins when network error`() = runTest {
every { anyConstructed<HTTPClient>().settings("cdn-settings.segment.com/v1") } throws Exception()
val mockPlugin = spyk(StubPlugin())

val settings = Settings(
integrations = buildJsonObject {
put(
"cachedSettings",
buildJsonObject {
put(
"apiKey",
"1vNgUqwJeCHmqgI9S1sOm9UHCyfYqbaQ"
)
})
},
plan = emptyJsonObject,
edgeFunction = emptyJsonObject,
middlewareSettings = emptyJsonObject
)
analytics.store.dispatch(System.UpdateSettingsAction(settings), System::class)
analytics.add(mockPlugin)
verify {
mockPlugin.update(settings, Plugin.UpdateType.Initial)
}
}

// Disabled because now we always propagate settings regardless network status
@Test @Disabled
fun `plugin added before settings is available updates plugin correctly`() = runTest {
// forces settings to fail
mockHTTPClient("")
Expand Down