test_HeapAnalyses_getCreationTime_01.js (1562B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test that the HeapAnalyses{Client,Worker} can get a HeapSnapshot's 6 // creation time. 7 8 function waitForThirtyMilliseconds() { 9 const start = Date.now(); 10 while (Date.now() - start < 30) { 11 // do nothing 12 } 13 } 14 15 const BREAKDOWN = { 16 by: "internalType", 17 then: { by: "count", count: true, bytes: true }, 18 }; 19 20 add_task(async function () { 21 const client = new HeapAnalysesClient(); 22 const start = Date.now() * 1000; 23 24 // Because Date.now() is less precise than the snapshot's time stamp, give it 25 // a little bit of head room. Additionally, WinXP's timers have a granularity 26 // of only +/-15 ms. 27 waitForThirtyMilliseconds(); 28 const snapshotFilePath = saveNewHeapSnapshot(); 29 waitForThirtyMilliseconds(); 30 const end = Date.now() * 1000; 31 32 await client.readHeapSnapshot(snapshotFilePath); 33 ok(true, "Should have read the heap snapshot"); 34 35 let threw = false; 36 try { 37 await client.getCreationTime("/not/a/real/path", { 38 breakdown: BREAKDOWN, 39 }); 40 } catch (_) { 41 threw = true; 42 } 43 ok(threw, "getCreationTime should throw when snapshot does not exist"); 44 45 const time = await client.getCreationTime(snapshotFilePath, { 46 breakdown: BREAKDOWN, 47 }); 48 49 dumpn("Start = " + start); 50 dumpn("End = " + end); 51 dumpn("Time = " + time); 52 53 Assert.greaterOrEqual(time, start, "creation time occurred after start"); 54 Assert.lessOrEqual(time, end, "creation time occurred before end"); 55 56 client.destroy(); 57 });