From 41067177bdff39e6c4508bdb2ff9a8fa585829ef Mon Sep 17 00:00:00 2001 From: Chris H-C Date: Mon, 18 Jul 2022 14:24:32 +0000 Subject: [PATCH] Bug 1756057 - Move FOG init instrumentation test to xpcshell. r=janerik This instrumentation test has been disabled since bug 1763474 because delaying init to this test meant that the preinit queue would overflow. Because GoogleTest runs all at once and in its own decided order, we shouldn't write any test that depends on FOG init happening at a specific time unless we make it happen before the test suite even runs. ...and if we do that, the test resets that we perform in between will obliterate the value in the init instrumentation, meaning we can't test it anyway. Note also that we skip-OK this test near local 4AM in case a properly-but- inconveniently-timed "metrics" ping clears the value between FOG init and the test run. Now I thought we could put this in mochi, but it turns out that we reuse browsers between test files. This means previous files' init of FOG and wiping of all data causes the test to permafail when not run in isolation. So here we are in xpcshell where we control init ourselves. Differential Revision: https://phabricator.services.mozilla.com/D147448 --- .../components/glean/tests/gtest/TestFog.cpp | 6 ---- .../glean/tests/xpcshell/test_FOGInit.js | 34 +++++++++++++++++++ .../glean/tests/xpcshell/xpcshell.ini | 2 ++ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 toolkit/components/glean/tests/xpcshell/test_FOGInit.js diff --git a/toolkit/components/glean/tests/gtest/TestFog.cpp b/toolkit/components/glean/tests/gtest/TestFog.cpp index 03148478b4bb..d367a7df2c62 100644 --- a/toolkit/components/glean/tests/gtest/TestFog.cpp +++ b/toolkit/components/glean/tests/gtest/TestFog.cpp @@ -42,12 +42,6 @@ TEST(FOG, FogInitDoesntCrash) ASSERT_EQ(NS_OK, fog_test_reset(&empty, &empty)); } -extern "C" void Rust_MeasureInitializeTime(); -// Disabled because this depends on the preinit buffer not overflowing, -// which currently can't be guaranteed. See bug 1756057 for how to fix it. -TEST(FOG, DISABLED_TestMeasureInitializeTime) -{ Rust_MeasureInitializeTime(); } - TEST(FOG, BuiltinPingsRegistered) { Preferences::SetInt("telemetry.fog.test.localhost_port", -1); diff --git a/toolkit/components/glean/tests/xpcshell/test_FOGInit.js b/toolkit/components/glean/tests/xpcshell/test_FOGInit.js new file mode 100644 index 000000000000..a1bb6b532524 --- /dev/null +++ b/toolkit/components/glean/tests/xpcshell/test_FOGInit.js @@ -0,0 +1,34 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { AppConstants } = ChromeUtils.import( + "resource://gre/modules/AppConstants.jsm" +); + +add_setup( + /* on Android FOG is set up through head.js */ + { skip_if: () => AppConstants.platform == "android" }, + function test_setup() { + // FOG needs a profile directory to put its data in. + do_get_profile(); + + // We need to initialize it once, otherwise operations will be stuck in the pre-init queue. + Services.fog.initializeFOG(); + } +); + +add_task(function test_fog_init_works() { + if (new Date().getHours() >= 3 && new Date().getHours() <= 4) { + // We skip this test if it's too close to 4AM, when we might send a + // "metrics" ping between init and this test being run. + Assert.ok(true, "Too close to 'metrics' ping send window. Skipping test."); + return; + } + Assert.greater( + Glean.fog.initialization.testGetValue(), + 0, + "FOG init happened, and its time was measured." + ); +}); diff --git a/toolkit/components/glean/tests/xpcshell/xpcshell.ini b/toolkit/components/glean/tests/xpcshell/xpcshell.ini index f8916654d9c2..82613b1cec01 100644 --- a/toolkit/components/glean/tests/xpcshell/xpcshell.ini +++ b/toolkit/components/glean/tests/xpcshell/xpcshell.ini @@ -3,6 +3,8 @@ firefox-appdir = browser head = head.js +[test_FOGInit.js] + [test_FOGIPCLimit.js] [test_FOGPrefs.js]