Bug 1580129 - Handle external metrics in TelemetryTest. r=snorp
authorAgi Sferro <agi@sferro.dev>
Wed, 25 Sep 2019 17:27:50 +0000
changeset 494953 e10b4084b51325e3ef992ced579a2c1b4f7c0581
parent 494952 6e13bb195ad174e2c66a58b0960bdbf6c54f9b8e
child 494954 f0292f2eb13953c0ec6d821a96d550c3f4f580e7
push id114131
push userdluca@mozilla.com
push dateThu, 26 Sep 2019 09:47:34 +0000
treeherdermozilla-inbound@1dc1a755079a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1580129
milestone71.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1580129 - Handle external metrics in TelemetryTest. r=snorp Right now testOnTelemetryReceived assumes that only the test histograms will fire during the test. This works because only the test histograms are enabled for streaming telemetry and will break as soon as some other histogram is enabled. Instead of relying on this fact we just wait for the test histogram to fire and ignore all the other unrelated ones. Differential Revision: https://phabricator.services.mozilla.com/D47015
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TelemetryTest.kt
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TelemetryTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/TelemetryTest.kt
@@ -1,82 +1,100 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
  * Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 package org.mozilla.geckoview.test
 
 import android.support.test.filters.MediumTest
 import android.support.test.runner.AndroidJUnit4
-import android.util.Log
 import org.hamcrest.CoreMatchers.equalTo
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.mozilla.geckoview.GeckoResult
 import org.mozilla.geckoview.RuntimeTelemetry
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
 
 @RunWith(AndroidJUnit4::class)
 @MediumTest
 class TelemetryTest : BaseSessionTest() {
     @Test
     fun testOnTelemetryReceived() {
-        sessionRule.addExternalDelegateUntilTestEnd(
-            RuntimeTelemetry.Delegate::class,
-                sessionRule::setTelemetryDelegate,
-                { sessionRule.setTelemetryDelegate(null) },
-                object : RuntimeTelemetry.Delegate {}
-        )
-
         // Let's make sure we batch the two telemetry calls
         sessionRule.setPrefsUntilTestEnd(
                 mapOf("toolkit.telemetry.geckoview.batchDurationMS" to 100000))
 
         sessionRule.addHistogram("TELEMETRY_TEST_STREAMING", 401)
         sessionRule.addHistogram("TELEMETRY_TEST_STREAMING", 12)
         sessionRule.addHistogram("TELEMETRY_TEST_STREAMING", 1)
         sessionRule.addHistogram("TELEMETRY_TEST_STREAMING", 109)
 
         sessionRule.setScalar("telemetry.test.boolean_kind", true)
         sessionRule.setScalar("telemetry.test.unsigned_int_kind", 1234)
         sessionRule.setScalar("telemetry.test.string_kind", "test scalar")
 
-        // Forces flushing telemetry data at next histogram
-        sessionRule.setPrefsUntilTestEnd(mapOf("toolkit.telemetry.geckoview.batchDurationMS" to 0))
-        sessionRule.addHistogram("TELEMETRY_TEST_STREAMING", 2000)
+        val histogram = GeckoResult<Void>()
+        val stringScalar = GeckoResult<Void>()
+        val booleanScalar = GeckoResult<Void>()
+        val longScalar = GeckoResult<Void>()
 
-        sessionRule.waitUntilCalled(object : RuntimeTelemetry.Delegate {
+        sessionRule.addExternalDelegateUntilTestEnd(
+                RuntimeTelemetry.Delegate::class,
+                sessionRule::setTelemetryDelegate,
+                { sessionRule.setTelemetryDelegate(null) },
+                object : RuntimeTelemetry.Delegate {
             @AssertCalled
             override fun onHistogram(metric: RuntimeTelemetry.Histogram) {
-                assertThat("Metric name should be correct", metric.name,
-                        equalTo("TELEMETRY_TEST_STREAMING"))
+                if (metric.name != "TELEMETRY_TEST_STREAMING") {
+                    return
+                }
+
                 assertThat("Metric name should be correct", metric.value,
                         equalTo(longArrayOf(401, 12, 1, 109, 2000)))
                 assertThat("The histogram should not be categorical", metric.isCategorical,
                         equalTo(false))
+                histogram.complete(null)
             }
 
             @AssertCalled
             override fun onStringScalar(metric: RuntimeTelemetry.Metric<String>) {
-                assertThat("Metric name should be correct", metric.name,
-                        equalTo("telemetry.test.string_kind"))
+                if (metric.name != "telemetry.test.string_kind") {
+                    return
+                }
+
                 assertThat("Metric name should be correct", metric.value,
                         equalTo("test scalar"))
+                stringScalar.complete(null)
             }
 
             @AssertCalled
             override fun onBooleanScalar(metric: RuntimeTelemetry.Metric<Boolean>) {
-                assertThat("Metric name should be correct", metric.name,
-                        equalTo("telemetry.test.boolean_kind"))
+                if (metric.name != "telemetry.test.boolean_kind") {
+                    return
+                }
+
                 assertThat("Metric name should be correct", metric.value,
                         equalTo(true))
+                booleanScalar.complete(null)
             }
 
             @AssertCalled
             override fun onLongScalar(metric: RuntimeTelemetry.Metric<Long>) {
-                assertThat("Metric name should be correct", metric.name,
-                        equalTo("telemetry.test.unsigned_int_kind"))
+                if (metric.name != "telemetry.test.unsigned_int_kind") {
+                    return
+                }
+
                 assertThat("Metric name should be correct", metric.value,
                         equalTo(1234L))
+                longScalar.complete(null)
             }
         })
+
+        // Forces flushing telemetry data at next histogram
+        sessionRule.setPrefsUntilTestEnd(mapOf("toolkit.telemetry.geckoview.batchDurationMS" to 0))
+        sessionRule.addHistogram("TELEMETRY_TEST_STREAMING", 2000)
+
+        sessionRule.waitForResult(histogram)
+        sessionRule.waitForResult(stringScalar)
+        sessionRule.waitForResult(booleanScalar)
+        sessionRule.waitForResult(longScalar)
     }
 }