Skip to content

Commit

Permalink
Bug 1920702 - Correctly record is_first_run as boolean r=chumphreys,a…
Browse files Browse the repository at this point in the history
…ndroid-reviewers,jonalmeida

Bug 1898552 added the recorded context, which recorded the "isFirstRun" param
as a boolean. However, the recorded context is splatted into the targeting
attributes inside the Nimbus SDK [1] and overrides other targeting members,
which include `isFirstRun: String` and `is_first_run: bool`. This has resulted
in targeting evaluation that checks against `isFirstRun == "'true'"` failing,
causing first run experiments to not enroll correctly. Recording the value as
`is_first_run` instead, which is expected to be a boolean, addresses the issue.


[1]: https://github.com/mozilla/application-services/blob/b10c1319e74041b2777e07657fc83dc879f841f4/components/nimbus/src/stateful/evaluator.rs#L22-L23

Differential Revision: https://phabricator.services.mozilla.com/D223399
  • Loading branch information
brennie committed Sep 26, 2024
1 parent 934b62e commit c59b4f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RecordedNimbusContext(

override fun toJson(): JsonObject {
val obj = JSONObject()
obj.put("isFirstRun", isFirstRun)
obj.put("is_first_run", isFirstRun)
return obj
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package org.mozilla.fenix.experiments

import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.put
import mozilla.components.support.test.robolectric.testContext
import mozilla.telemetry.glean.testing.GleanTestRule
import org.junit.Assert.assertEquals
Expand All @@ -23,16 +26,38 @@ class RecordedNimbusContextTest {
val gleanTestRule = GleanTestRule(testContext)

@Test
fun `GIVEN an instance of RecordedNimbusContext WHEN record called THEN its JSON structure and the value recorded to Glean should be the same`() {
fun `GIVEN an instance of RecordedNimbusContext WHEN serialized to JSON THEN its JSON structure matches the expected value`() {
val context = RecordedNimbusContext(
isFirstRun = true,
)

context.record()
// RecordedNimbusContext.toJson() returns
// org.mozilla.experiments.nimbus.internal.JsonObject, which is a
// different type.
val contextAsJson = Json.decodeFromString<JsonObject>(context.toJson().toString())

val value = GleanNimbus.recordedNimbusContext.testGetValue()
assertEquals(
contextAsJson,
buildJsonObject {
put("is_first_run", true)
},
)
}

assertNotNull(value)
assertEquals(Json.decodeFromString<JsonObject>(context.toJson().toString()), value)
@Test
fun `GIVEN an instance of RecordedNimbusContext WHEN record called THEN the value recorded to Glean should match the expected value`() {
RecordedNimbusContext(
isFirstRun = true,
).record()

val recordedValue = GleanNimbus.recordedNimbusContext.testGetValue()

assertNotNull(recordedValue)
assertEquals(
recordedValue?.jsonObject,
buildJsonObject {
put("isFirstRun", true)
},
)
}
}

0 comments on commit c59b4f5

Please sign in to comment.