trr_performance.js (1679B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* eslint-env node */ 6 7 const { logTest } = require("./utils/profiling"); 8 9 module.exports = logTest( 10 "dns lookup pageload", 11 async function (context, commands) { 12 context.log.info("Starting a pageload to measure DNS lookup time"); 13 14 const testType = `${context.options.browsertime.test_type}`; 15 context.log.info("testType: " + testType); 16 17 const url = "https://httpbin.org/"; 18 19 await commands.navigate("about:blank"); 20 21 // Idle to allow for confirmation 22 await commands.wait.byTime(45000); 23 24 if (testType === "trr_warm") { 25 // Ensure the trr connection has been warmed up by making an arbitrary request 26 await commands.navigate("https://www.w3.org"); 27 await commands.wait.byTime(2000); 28 } 29 30 // Start measuring 31 await commands.measure.start(); 32 await commands.navigate(url); 33 await commands.measure.stop(); 34 35 let dns_lookup_time = await commands.js.run(` 36 return (window.performance.timing.domainLookupEnd - window.performance.timing.domainLookupStart); 37 `); 38 39 let connect_time = await commands.js.run(` 40 return (window.performance.timing.connectEnd - window.performance.timing.navigationStart); 41 `); 42 43 context.log.info("dns_lookup_time: " + dns_lookup_time); 44 context.log.info("connect_time: " + connect_time); 45 46 await commands.measure.addObject({ 47 custom_data: { dns_lookup_time, connect_time }, 48 }); 49 50 context.log.info("DNS lookup test finished."); 51 return true; 52 } 53 );