Skip to content
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

fix: Remove STALE event #122

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import dev.openfeature.sdk.FlagEvaluationDetails
import dev.openfeature.sdk.ImmutableContext
import dev.openfeature.sdk.OpenFeatureAPI
import dev.openfeature.sdk.Value
import dev.openfeature.sdk.async.setProviderAndWait
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.UUID
Expand Down
2 changes: 1 addition & 1 deletion Provider/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

object Versions {
const val openFeatureSDK = "0.2.2"
const val openFeatureSDK = "0.2.3"
const val okHttp = "4.10.0"
const val kotlinxSerialization = "1.6.0"
const val coroutines = "1.7.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ class ConfidenceFeatureProvider private constructor(
newContext: EvaluationContext
) {
if (newContext != oldContext) {
eventHandler.publish(OpenFeatureEvents.ProviderStale)

// on the new context we want to fetch new values and update
// the storage & cache right away which is why we pass `InitialisationStrategy.FetchAndActivate`
internalInitialize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import dev.openfeature.sdk.ImmutableContext
import dev.openfeature.sdk.ImmutableStructure
import dev.openfeature.sdk.Reason
import dev.openfeature.sdk.Value
import dev.openfeature.sdk.async.awaitReadyOrError
import dev.openfeature.sdk.events.EventHandler
import dev.openfeature.sdk.events.OpenFeatureEvents
import dev.openfeature.sdk.events.awaitReadyOrError
import junit.framework.TestCase
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
Expand Down Expand Up @@ -64,13 +62,12 @@ class StorageFileCacheTests {
whenever(mockContext.filesDir).thenReturn(Files.createTempDirectory("tmpTests").toFile())
}

@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun testOfflineScenarioLoadsStoredCache() = runTest {
val mockClient: ConfidenceClient = mock()
whenever(mockClient.apply(any(), any())).thenReturn(Result.Success)
val testDispatcher = UnconfinedTestDispatcher(testScheduler)
val eventPublisher = EventHandler(testDispatcher)
eventPublisher.publish(OpenFeatureEvents.ProviderStale)
val cache1 = InMemoryCache()
whenever(mockClient.resolve(eq(listOf()), any())).thenReturn(
ResolveResponse.Resolved(
Expand All @@ -81,7 +78,6 @@ class StorageFileCacheTests {
context = mockContext,
clientSecret = "",
client = mockClient,
eventHandler = eventPublisher,
cache = cache1
)
provider1.initialize(ImmutableContext(targetingKey = "user1"))
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ Where:

### Changing context after the provider initialization
The evaluation context can be changed during the app session using `setEvaluationContext(...)`.
After calling this method the new context is set for the provider and the flags will be fetched again and the cache and storage will be updated accordingly.
The OpenFeature Events `ProviderStale` and `ProviderReady` events will be emitted accordingly.
After calling this method the new context is set for the provider, the flags will be fetched again and the cache and storage will be updated accordingly. The event `ProviderReady` will be emitted once the new flags are ready to be consumed by the application (note that the selected initialization strategy property doesn't play a role in this case).

Notes:
- If a flag can't be resolved from cache, the provider does NOT automatically resort to calling remote: refreshing the cache from remote only happens when setting a new provider and/or evaluation context in the global OpenFeatureAPI
- It's advised not to perform resolves while `setProvider` and `setEvaluationContext` are running: resolves might return the default value with reason `STALE` during such operations.
- It's advised not to perform resolves while `setProvider` and `setEvaluationContext` are running: resolves might return the default value with reason `STALE` during such operations. The event `ProviderReady` can be used to guarantee correctness.

## Apply events
This Provider automatically emits `apply` events to the Confidence backend once a flag's property is read by the application. This allows Confidence to track who was exposed to what variant and when.
Expand Down
Loading