-
Notifications
You must be signed in to change notification settings - Fork 127
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
Bug 1653244 - Fix experiment info getting cleared before getting into metrics ping #1069
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -476,7 +476,8 @@ class MetricsPingSchedulerTest { | |
} | ||
|
||
@Test | ||
fun `startup ping sends old version when upgraded`() { | ||
@Suppress("LongMethod") | ||
fun `startup ping sends correct data when upgraded`() { | ||
// Start the web-server that will receive the metrics ping. | ||
val server = getMockWebServer() | ||
val configuration = Configuration( | ||
|
@@ -510,10 +511,15 @@ class MetricsPingSchedulerTest { | |
val expectedValue = "canary" | ||
expectedStringMetric.set(expectedValue) | ||
|
||
// Set an experiment active to verify it gets sent in the pings | ||
Glean.setExperimentActive("test-experiment", "a") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should really be an integration test for our sample app, along with most of the tests in this file. Nothing you can do here, though - this whole thing would require its own bug. @travis79 would you kindly file it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
// Reset Glean. | ||
Glean.testDestroyGleanHandle() | ||
@Suppress("EXPERIMENTAL_API_USAGE") | ||
Dispatchers.API.setTaskQueueing(true) | ||
@Suppress("EXPERIMENTAL_API_USAGE") | ||
Dispatchers.API.setTestingMode(false) | ||
|
||
// Initialize Glean again with the new version. | ||
// This should trigger a metrics ping after an upgrade (differing version). | ||
|
@@ -523,6 +529,10 @@ class MetricsPingSchedulerTest { | |
configuration | ||
) | ||
|
||
// Unfortunately, we need to delay a bit here to give init time to run because we are | ||
// running async at this point in the test. | ||
Thread.sleep(500) | ||
|
||
// Trigger worker task to upload the pings in the background. | ||
triggerWorkManager(context) | ||
|
||
|
@@ -534,15 +544,31 @@ class MetricsPingSchedulerTest { | |
val metricsJsonData = request.getPlainBody() | ||
val pingJson = JSONObject(metricsJsonData) | ||
|
||
assertEquals("The metrics ping reason must be 'upgrade'", | ||
"upgrade", pingJson.getJSONObject("ping_info")["reason"]) | ||
|
||
assertEquals("The received ping must contain the old version", | ||
oldVersion, pingJson.getJSONObject("client_info")["app_display_version"]) | ||
|
||
val stringMetrics = pingJson.getJSONObject("metrics")["string"] as JSONObject | ||
assertEquals("The received ping must contain the expected metric", | ||
expectedValue, stringMetrics.getString("telemetry.expected_metric")) | ||
|
||
val experiments = pingJson.getJSONObject("ping_info")["experiments"] as JSONObject | ||
val testExperiment = experiments["test-experiment"] as JSONObject | ||
assertNotNull("The received ping must contain the experiment", | ||
testExperiment) | ||
assertEquals("Experiment branch should exist and match", | ||
"a", testExperiment.getString("branch")) | ||
} finally { | ||
server.shutdown() | ||
|
||
// Reset Glean. | ||
Glean.testDestroyGleanHandle() | ||
@Suppress("EXPERIMENTAL_API_USAGE") | ||
Dispatchers.API.setTaskQueueing(true) | ||
@Suppress("EXPERIMENTAL_API_USAGE") | ||
Dispatchers.API.setTestingMode(true) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a changelog entry for this!