From b831405fb696cd2aca2a54da9cb752b233887e50 Mon Sep 17 00:00:00 2001 From: Joshua Marshall Date: Tue, 28 Nov 2023 16:33:38 +0000 Subject: [PATCH] Bug 1299271 - Service worker performance test r=asuth,sparky These are a first-cut of service worker performance tests, just running as vanilla mochitests for now. Bug 1832059 tracks the integration work necessary. Differential Revision: https://phabricator.services.mozilla.com/D177427 --- dom/serviceworkers/moz.build | 1 + .../test/performance/intercepted.txt | 1 + .../test/performance/perftest.toml | 14 ++ .../test/performance/perfutils.js | 46 +++++ .../test/performance/sw_cacher.js | 18 ++ .../test/performance/sw_empty.js | 0 .../test/performance/sw_intercept_target.js | 7 + .../test/performance/target.txt | 1 + .../test/performance/test_caching.html | 89 ++++++++++ .../test/performance/test_fetch.html | 168 ++++++++++++++++++ .../test/performance/test_registration.html | 89 ++++++++++ .../test/performance/time_fetch.html | 38 ++++ .../mozperftest/mozperftest/test/mochitest.py | 4 +- taskcluster/ci/perftest/linux.yml | 19 ++ 14 files changed, 494 insertions(+), 1 deletion(-) create mode 100644 dom/serviceworkers/test/performance/intercepted.txt create mode 100644 dom/serviceworkers/test/performance/perftest.toml create mode 100644 dom/serviceworkers/test/performance/perfutils.js create mode 100644 dom/serviceworkers/test/performance/sw_cacher.js create mode 100644 dom/serviceworkers/test/performance/sw_empty.js create mode 100644 dom/serviceworkers/test/performance/sw_intercept_target.js create mode 100644 dom/serviceworkers/test/performance/target.txt create mode 100644 dom/serviceworkers/test/performance/test_caching.html create mode 100644 dom/serviceworkers/test/performance/test_fetch.html create mode 100644 dom/serviceworkers/test/performance/test_registration.html create mode 100644 dom/serviceworkers/test/performance/time_fetch.html diff --git a/dom/serviceworkers/moz.build b/dom/serviceworkers/moz.build index fff2f576a095..951b20488e88 100644 --- a/dom/serviceworkers/moz.build +++ b/dom/serviceworkers/moz.build @@ -114,6 +114,7 @@ FINAL_LIBRARY = "xul" MOCHITEST_MANIFESTS += [ "test/mochitest-dFPI.ini", "test/mochitest.toml", + "test/performance/perftest.toml", ] MOCHITEST_CHROME_MANIFESTS += [ diff --git a/dom/serviceworkers/test/performance/intercepted.txt b/dom/serviceworkers/test/performance/intercepted.txt new file mode 100644 index 000000000000..87c7a8efe772 --- /dev/null +++ b/dom/serviceworkers/test/performance/intercepted.txt @@ -0,0 +1 @@ +intercepted diff --git a/dom/serviceworkers/test/performance/perftest.toml b/dom/serviceworkers/test/performance/perftest.toml new file mode 100644 index 000000000000..6a7e5928bea3 --- /dev/null +++ b/dom/serviceworkers/test/performance/perftest.toml @@ -0,0 +1,14 @@ +[DEFAULT] +support-files = [ + "intercepted.txt", + "perfutils.js", + "sw_cacher.js", + "sw_empty.js", + "sw_intercept_target.js", + "target.txt", + "time_fetch.html", +] + +["test_caching.html"] +["test_fetch.html"] +["test_registration.html"] diff --git a/dom/serviceworkers/test/performance/perfutils.js b/dom/serviceworkers/test/performance/perfutils.js new file mode 100644 index 000000000000..d7edbe2fe7c1 --- /dev/null +++ b/dom/serviceworkers/test/performance/perfutils.js @@ -0,0 +1,46 @@ +"use strict"; + +/** + * Given a map from test names to arrays of results, report perfherder metrics + * and log full results. + */ +function reportMetrics(journal) { + let metrics = {}; + let text = "\nResults (ms)\n"; + + const names = Object.keys(journal); + const prefixLen = 1 + Math.max(...names.map(str => str.length)); + + for (const name in journal) { + const med = median(journal[name]); + text += (name + ":").padEnd(prefixLen, " ") + stringify(journal[name]); + text += " median " + med + "\n"; + metrics[name] = med; + } + + dump(text); + info("perfMetrics", JSON.stringify(metrics)); +} + +function median(arr) { + arr = [...arr].sort((a, b) => a - b); + const mid = Math.floor(arr.length / 2); + + if (arr.length % 2) { + return arr[mid]; + } + + return (arr[mid - 1] + arr[mid]) / 2; +} + +function stringify(arr) { + function pad(num) { + let s = num.toString().padStart(5, " "); + if (s[0] != " ") { + s = " " + s; + } + return s; + } + + return arr.reduce((acc, elem) => acc + pad(elem), ""); +} diff --git a/dom/serviceworkers/test/performance/sw_cacher.js b/dom/serviceworkers/test/performance/sw_cacher.js new file mode 100644 index 000000000000..5a441ef7854b --- /dev/null +++ b/dom/serviceworkers/test/performance/sw_cacher.js @@ -0,0 +1,18 @@ +"use strict"; + +oninstall = function (event) { + event.waitUntil( + caches.open("perftest").then(function (cache) { + return cache.put("cached.txt", new Response("cached.txt")); + }) + ); +}; + +onfetch = function (event) { + if (event.request.url.endsWith("/cached.txt")) { + var p = caches.match("cached.txt", { cacheName: "perftest" }); + event.respondWith(p); + } else if (event.request.url.endsWith("/uncached.txt")) { + event.respondWith(new Response("uncached.txt")); + } +}; diff --git a/dom/serviceworkers/test/performance/sw_empty.js b/dom/serviceworkers/test/performance/sw_empty.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/dom/serviceworkers/test/performance/sw_intercept_target.js b/dom/serviceworkers/test/performance/sw_intercept_target.js new file mode 100644 index 000000000000..47b385397829 --- /dev/null +++ b/dom/serviceworkers/test/performance/sw_intercept_target.js @@ -0,0 +1,7 @@ +"use strict"; + +onfetch = function (event) { + if (event.request.url.indexOf("target.txt") != -1) { + event.respondWith(fetch("intercepted.txt")); + } +}; diff --git a/dom/serviceworkers/test/performance/target.txt b/dom/serviceworkers/test/performance/target.txt new file mode 100644 index 000000000000..eb5a316cbd19 --- /dev/null +++ b/dom/serviceworkers/test/performance/target.txt @@ -0,0 +1 @@ +target diff --git a/dom/serviceworkers/test/performance/test_caching.html b/dom/serviceworkers/test/performance/test_caching.html new file mode 100644 index 000000000000..cd6d4cf49397 --- /dev/null +++ b/dom/serviceworkers/test/performance/test_caching.html @@ -0,0 +1,89 @@ + + + + Service worker performance test: caching + + + + + + + + diff --git a/dom/serviceworkers/test/performance/test_fetch.html b/dom/serviceworkers/test/performance/test_fetch.html new file mode 100644 index 000000000000..29dd65b59541 --- /dev/null +++ b/dom/serviceworkers/test/performance/test_fetch.html @@ -0,0 +1,168 @@ + + + + Service worker performance test: fetch + + + + + + + + diff --git a/dom/serviceworkers/test/performance/test_registration.html b/dom/serviceworkers/test/performance/test_registration.html new file mode 100644 index 000000000000..d5abbf677506 --- /dev/null +++ b/dom/serviceworkers/test/performance/test_registration.html @@ -0,0 +1,89 @@ + + + + Service worker performance test: registration + + + + + + + + diff --git a/dom/serviceworkers/test/performance/time_fetch.html b/dom/serviceworkers/test/performance/time_fetch.html new file mode 100644 index 000000000000..a771d4889fc5 --- /dev/null +++ b/dom/serviceworkers/test/performance/time_fetch.html @@ -0,0 +1,38 @@ + + + + + + + + diff --git a/python/mozperftest/mozperftest/test/mochitest.py b/python/mozperftest/mozperftest/test/mochitest.py index fa237de8277f..44cbaf15ba7f 100644 --- a/python/mozperftest/mozperftest/test/mochitest.py +++ b/python/mozperftest/mozperftest/test/mochitest.py @@ -151,6 +151,7 @@ class Mochitest(Layer): # Bug 1858155 - Attempting to only use one test_path triggers a failure # during test execution args.test_paths = [str(test.name), str(test.name)] + args.keep_open = False args.runByManifest = True args.manifestFile = manifest args.topobjdir = self.topobjdir @@ -183,7 +184,8 @@ class Mochitest(Layer): status, log_processor = FunctionalTestRunner.test( self.mach_cmd, [str(test)], - self._parse_extra_args(self.get_arg("extra-args")), + self._parse_extra_args(self.get_arg("extra-args")) + + ["--keep-open=False"], ) if status is not None and status != 0: diff --git a/taskcluster/ci/perftest/linux.yml b/taskcluster/ci/perftest/linux.yml index 855f955b3340..13f69ab6bd82 100644 --- a/taskcluster/ci/perftest/linux.yml +++ b/taskcluster/ci/perftest/linux.yml @@ -118,6 +118,25 @@ domcount: --browsertime-geckodriver ${MOZ_FETCHES_DIR}/geckodriver --output $MOZ_FETCHES_DIR/../artifacts +service-worker: + description: Run service worker tests + treeherder: + symbol: perftest(linux-sw) + tier: 2 + attributes: + batch: false + cron: false + run-on-projects: [autoland, mozilla-central] + run: + command: >- + mkdir -p $MOZ_FETCHES_DIR/../artifacts && + cd $MOZ_FETCHES_DIR && + python3 python/mozperftest/mozperftest/runner.py + dom/serviceworkers/test/performance/test_registration.html + --mochitest-binary ${MOZ_FETCHES_DIR}/firefox/firefox-bin + --flavor mochitest + --output $MOZ_FETCHES_DIR/../artifacts + http3: description: Run HTTP/3 test treeherder: