Skip to content

Commit 4260ba7

Browse files
Bug 1983107 - Update to jexl-eval 0.4.0 (#6893)
Nimbus now exposes a test only `recordEventSync` method to use in tests becuase `recordEvent` dispatches the event recording to a background thread. Because the new JEXL parser is so fast, our EventStoreTests are now intermittently failing as the event recording hasn't finished by the time we actually evaluate the JEXL expressions. Using `recordEventSync` bypasses this issue entirely.
1 parent 6cc4524 commit 4260ba7

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/nimbus/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ serde_json = "1"
2727
thiserror = "1"
2828
url = "2.5"
2929
rkv = { version = "0.19", optional = true }
30-
jexl-eval = "0.3.0"
30+
jexl-eval = "0.4.0"
3131
uuid = { version = "1.3", features = ["serde", "v4"]}
3232
sha2 = "^0.10"
3333
hex = "0.4"

components/nimbus/android/src/main/java/org/mozilla/experiments/nimbus/Nimbus.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import kotlinx.coroutines.CoroutineScope
2222
import kotlinx.coroutines.Job
2323
import kotlinx.coroutines.NonCancellable
2424
import kotlinx.coroutines.launch
25+
import kotlinx.coroutines.runBlocking
2526
import kotlinx.coroutines.withContext
2627
import mozilla.appservices.remotesettings.RemoteSettingsConfig
2728
import mozilla.appservices.remotesettings.RemoteSettingsServer
@@ -461,6 +462,9 @@ open class Nimbus(
461462
}
462463
}
463464

465+
override fun recordEventSync(count: Long, eventId: String) =
466+
nimbusClient.recordEvent(eventId, count)
467+
464468
override fun recordPastEvent(count: Long, eventId: String, secondsAgo: Long) =
465469
nimbusClient.recordPastEvent(eventId, secondsAgo, count)
466470

components/nimbus/android/src/main/java/org/mozilla/experiments/nimbus/NimbusInterface.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ interface NimbusEventStore {
249249
fun recordEvent(eventId: String) =
250250
recordEvent(1, eventId)
251251

252+
/**
253+
* Record an event synchronously on the main thread.
254+
*
255+
* For testing only.
256+
*/
257+
fun recordEventSync(count: Long = 1, eventId: String) = Unit
258+
252259
/**
253260
* Records an event as if it were emitted in the past.
254261
*

components/nimbus/android/src/test/java/org/mozilla/experiments/nimbus/EventStoreTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package org.mozilla.experiments.nimbus
66

77
import android.content.Context
88
import androidx.test.core.app.ApplicationProvider
9+
import kotlinx.coroutines.runBlocking
910
import org.junit.Assert.assertTrue
1011
import org.junit.Test
1112
import org.junit.runner.RunWith
@@ -44,7 +45,7 @@ class EventStoreTest {
4445
@Test
4546
fun `advancing time into the future`() {
4647
val helper = createHelper()
47-
events.recordEvent(eventId)
48+
events.recordEventSync(1, eventId)
4849

4950
assertTrue(helper.evalJexl("'$eventId'|eventLastSeen('Days') == 0"))
5051

components/remote_settings/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ viaduct = { path = "../viaduct" }
2626
url = "2"
2727
camino = "1.0"
2828
rusqlite = { version = "0.37.0", features = ["bundled"] }
29-
jexl-eval = { version = "0.3.0" }
29+
jexl-eval = { version = "0.4.0" }
3030
regex = "1.9"
3131
anyhow = "1.0"
3232
firefox-versioning = { path = "../support/firefox-versioning" }

0 commit comments

Comments
 (0)