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

feat: Impression events #25

Merged
merged 3 commits into from
Jul 17, 2024
Merged

feat: Impression events #25

merged 3 commits into from
Jul 17, 2024

Conversation

gastonfournier
Copy link
Contributor

No description provided.

Comment on lines +52 to +53
assertThat(config.proxyUrl).isEmpty()
assertThat(config.clientKey).isEmpty()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proxy url and clientKey are required but we don't need them for testing (when both polling and metrics are disabled), therefore I think it's easier to keep them as empty as in production they should have a value

Comment on lines 173 to 179
while (!ready) {
println("Waiting for unleash to be ready")
waits ++
Thread.sleep(50)
if (waits > 100) {
throw IllegalStateException("Unleash did not become ready")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://medium.com/androiddevelopers/alternatives-to-idling-resources-in-compose-tests-8ae71f9fc473

Seems to only relate to compose though. But feels waitUntil(ready, Duration.ofSeconds(1)) would make for a much more readable test.

We could add https://github.com/awaitility/awaitility as a testDependency, that would give you an await api for anything async.

Copy link
Member

@chriswk chriswk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, small nit about the sleep in while loop and readability, but nothing that should stop you from moving forward.

@gastonfournier gastonfournier force-pushed the delayed-init branch 2 times, most recently from 3e2bddb to abe670c Compare July 17, 2024 07:45
Base automatically changed from delayed-init to main July 17, 2024 07:56
… therefore I think it's easier to keep them as empty as in production they should have a value
@gastonfournier gastonfournier merged commit 2abbf3d into main Jul 17, 2024
1 check passed
@gastonfournier gastonfournier deleted the impression-events branch July 17, 2024 09:47
val enabled = toggle?.enabled ?: defaultValue
val impressionData = toggle?.impressionData ?: unleashConfig.forceImpressionData
if (impressionData) {
emit(ImpressionEvent(toggleName, enabled, unleashContextState.value))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chriswk @sighphyre there's a chance that context might change from checking isEnabled to obtaining the context in this line. Is this something we should be worried about? Maybe the js proxy SDK won't suffer from this issue because there's a single thread and I'm not sure this method can be interrupted by other thread setting the context:
https://github.com/Unleash/unleash-proxy-client-js/blob/d13ad709213cad7bedd92c8a4c1bc9ee09d4a5c7/src/index.ts#L252-L269

Server side SDKs don't suffer from this problem because they need the context to evaluate isEnabled, therefore it's guaranteed that the context used for the evaluation is the same one sent in the impression event.

There is a solution for this... the cache should also store the current context and should return it when we get a toggle. It'd be something like: val (toggle, context) = cache.get(toggleName)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants