Bug 1510979 - add a telemetry xpcshell-test for socket process r=janerik

We need a test-only IPC message to socket process to trigger the Telemetry::Scalar set since no js engine in the socket process.
And hook the IPC call to AddPendingEvent |CallOrWaitSocketProcess| introduced by bug 1496257.

Differential Revision: https://phabricator.services.mozilla.com/D14822

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Junior Hsu 2019-01-15 23:15:38 +00:00
Родитель a94714d9aa
Коммит c54c918b66
7 изменённых файлов: 72 добавлений и 0 удалений

Просмотреть файл

@ -224,6 +224,11 @@ interface nsINetUtil : nsISupports
*/
ACString getReferrerPolicyString(in unsigned long aPolicy);
/**
* This is test-only. Send an IPC message to let socket process send a
* telemetry.
*/
void socketProcessTelemetryPing();
/**
* This is a void method that is C++ implemented and always

Просмотреть файл

@ -507,6 +507,15 @@ RefPtr<MemoryReportingProcess> nsIOService::GetSocketProcessMemoryReporter() {
return new SocketProcessMemoryReporter();
}
NS_IMETHODIMP
nsIOService::SocketProcessTelemetryPing() {
CallOrWaitForSocketProcess([]() {
Unused << gIOService->mSocketProcess->GetActor()
->SendSocketProcessTelemetryPing();
});
return NS_OK;
}
NS_IMPL_ISUPPORTS(nsIOService, nsIIOService, nsINetUtil, nsISpeculativeConnect,
nsIObserver, nsIIOServiceInternal, nsISupportsWeakReference)

Просмотреть файл

@ -43,6 +43,8 @@ child:
async SetOffline(bool offline);
async InitSocketProcessBridgeParent(ProcessId processId, Endpoint<PSocketProcessBridgeParent> endpoint);
async InitProfiler(Endpoint<PProfilerChild> aEndpoint);
// test-only
async SocketProcessTelemetryPing();
};
} // namespace net

Просмотреть файл

@ -151,6 +151,13 @@ mozilla::ipc::IPCResult SocketProcessChild::RecvInitProfiler(
return IPC_OK();
}
mozilla::ipc::IPCResult SocketProcessChild::RecvSocketProcessTelemetryPing() {
const uint32_t kExpectedUintValue = 42;
Telemetry::ScalarSet(Telemetry::ScalarID::TELEMETRY_TEST_SOCKET_ONLY_UINT,
kExpectedUintValue);
return IPC_OK();
}
void SocketProcessChild::DestroySocketProcessBridgeParent(ProcessId aId) {
MOZ_ASSERT(NS_IsMainThread());

Просмотреть файл

@ -42,6 +42,7 @@ class SocketProcessChild final : public PSocketProcessChild {
Endpoint<mozilla::net::PSocketProcessBridgeParent>&& aEndpoint) override;
mozilla::ipc::IPCResult RecvInitProfiler(
Endpoint<mozilla::PProfilerChild>&& aEndpoint) override;
mozilla::ipc::IPCResult RecvSocketProcessTelemetryPing() override;
void CleanUp();
void DestroySocketProcessBridgeParent(ProcessId aId);

Просмотреть файл

@ -0,0 +1,46 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
*/
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/TelemetryController.jsm");
ChromeUtils.import("resource://testing-common/ContentTaskUtils.jsm");
const SOCKET_ONLY_UINT_SCALAR = "telemetry.test.socket_only_uint";
/**
* This function waits until socket scalars are reported into the
* scalar snapshot.
*/
async function waitForSocketScalars() {
await ContentTaskUtils.waitForCondition(() => {
const scalars = Telemetry.getSnapshotForScalars("main", false);
return Object.keys(scalars).includes("socket");
});
}
add_task(async function() {
if (!Services.prefs.getBoolPref("network.process.enabled")) {
Assert.ok(true, "Test finished: no point to test telemetry from socket process with lanuching the process");
return;
}
do_test_pending();
do_get_profile(true);
await TelemetryController.testSetup();
Services.netUtils.socketProcessTelemetryPing();
// Once scalars are set by the socket process, they don't immediately get
// sent to the parent process. Wait for the Telemetry IPC Timer to trigger
// and batch send the data back to the parent process.
await waitForSocketScalars();
Assert.equal(Telemetry.getSnapshotForScalars("main", false)
.socket[SOCKET_ONLY_UINT_SCALAR],
42,
`${SOCKET_ONLY_UINT_SCALAR} must have the correct value (socket process).`);
do_test_finished();
});

Просмотреть файл

@ -67,6 +67,8 @@ skip-if = os == "android" # Disabled due to crashes (see bug 1331366)
tags = addons
[test_ChildScalars.js]
skip-if = os == "android" # Disabled due to crashes (see bug 1331366)
[test_SocketScalars.js]
skip-if = os == "android"
[test_TelemetryReportingPolicy.js]
skip-if = os == "android" # Disabled due to crashes (see bug 1367762)
tags = addons