bug 1440673 - Test event summary scalar collection r?Dexter draft
authorChris H-C <chutten@mozilla.com>
Wed, 28 Mar 2018 11:36:51 -0400
changeset 778102 65524bb81db80c2adc91e58ff3a6ce5fe4d2b073
parent 778101 078a5167589c2a5979a2d2d42b68d546ff01414d
child 778103 920b6472477a26316601a438e05fdaa771f91c78
push id105384
push userbmo:chutten@mozilla.com
push dateThu, 05 Apr 2018 20:33:48 +0000
reviewersDexter
bugs1440673
milestone61.0a1
bug 1440673 - Test event summary scalar collection r?Dexter MozReview-Commit-ID: 6wiiX8pCoHT
toolkit/components/telemetry/tests/gtest/TestScalars.cpp
--- a/toolkit/components/telemetry/tests/gtest/TestScalars.cpp
+++ b/toolkit/components/telemetry/tests/gtest/TestScalars.cpp
@@ -6,21 +6,24 @@
 #include "gtest/gtest.h"
 
 #include "js/Conversions.h"
 #include "mozilla/Unused.h"
 #include "nsJSUtils.h" // nsAutoJSString
 #include "nsITelemetry.h"
 #include "nsThreadUtils.h"
 #include "Telemetry.h"
+#include "mozilla/TelemetryProcessEnums.h"
 #include "TelemetryFixture.h"
+#include "TelemetryScalar.h"
 #include "TelemetryTestHelpers.h"
 
 using namespace mozilla;
 using namespace TelemetryTestHelpers;
+using mozilla::Telemetry::ProcessID;
 
 #define EXPECTED_STRING "Nice, expected and creative string."
 
 // Test that we can properly write unsigned scalars using the C++ API.
 TEST_F(TelemetryTestFixture, ScalarUnsigned) {
   AutoJSContextWithGlobal cx(mCleanGlobal);
 
   // Make sure we don't get scalars from other tests.
@@ -242,8 +245,54 @@ TEST_F(TelemetryTestFixture, ScalarUnkno
 
     // Make sure that nothing was recorded in the keyed scalars.
     JS::RootedValue keyedSnapshot(cx.GetJSContext());
     GetScalarsSnapshot(true, cx.GetJSContext(), &keyedSnapshot);
     ASSERT_TRUE(keyedSnapshot.isUndefined()) << "No keyed scalar must be recorded";
   }
 #endif
 }
+
+TEST_F(TelemetryTestFixture, ScalarEventSummary) {
+  AutoJSContextWithGlobal cx(mCleanGlobal);
+
+  // Make sure we don't get scalars from other tests.
+  Unused << mTelemetry->ClearScalars();
+
+  const char* kScalarName = "telemetry.event_counts";
+
+  const char* kLongestEvent = "oohwowlookthiscategoryissolong#thismethodislongtooo#thisobjectisnoslouch";
+  TelemetryScalar::SummarizeEvent(nsCString(kLongestEvent), ProcessID::Parent, false /* aDynamic */);
+
+  // Check the recorded value.
+  JS::RootedValue scalarsSnapshot(cx.GetJSContext());
+  GetScalarsSnapshot(true, cx.GetJSContext(), &scalarsSnapshot);
+
+  CheckKeyedUintScalar(kScalarName, kLongestEvent, cx.GetJSContext(), scalarsSnapshot, 1);
+
+// Don't run this part in debug builds as that intentionally asserts.
+#ifndef DEBUG
+  const char* kTooLongEvent = "oohwowlookthiscategoryissolong#thismethodislongtooo#thisobjectisnoslouch2";
+  TelemetryScalar::SummarizeEvent(nsCString(kTooLongEvent), ProcessID::Parent, false /* aDynamic */);
+
+  GetScalarsSnapshot(true, cx.GetJSContext(), &scalarsSnapshot);
+  CheckNumberOfProperties(kScalarName, cx.GetJSContext(), scalarsSnapshot, 1);
+#endif // #ifndef DEBUG
+
+  // Test we can fill the next 499 keys up to our 500 maximum
+  for (int i = 1; i < 500; i++) {
+    std::ostringstream eventName;
+    eventName << "category#method#object" << i;
+    TelemetryScalar::SummarizeEvent(nsCString(eventName.str().c_str()), ProcessID::Parent, false /* aDynamic */);
+  }
+
+  GetScalarsSnapshot(true, cx.GetJSContext(), &scalarsSnapshot);
+  CheckNumberOfProperties(kScalarName, cx.GetJSContext(), scalarsSnapshot, 500);
+
+// Don't run this part in debug builds as that intentionally asserts.
+#ifndef DEBUG
+  TelemetryScalar::SummarizeEvent(nsCString("whoops#too#many"), ProcessID::Parent, false /* aDynamic */);
+
+  GetScalarsSnapshot(true, cx.GetJSContext(), &scalarsSnapshot);
+  CheckNumberOfProperties(kScalarName, cx.GetJSContext(), scalarsSnapshot, 500);
+#endif // #ifndef DEBUG
+
+}