Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / devtools / server / tests / chrome / test_memory_allocations_02.html
blob632903bc04dc4e580ebd9547ce8a83c0c005a0a1
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 Bug 1132764 - Test controlling the maximum allocations log length over the RDP.
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Memory monitoring actor test</title>
9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
11 </head>
12 <body>
13 <pre id="test">
14 <script src="memory-helpers.js" type="application/javascript"></script>
15 <script>
16 "use strict";
18 window.onload = function() {
19 SimpleTest.waitForExplicitFinish();
21 (async function() {
22 const { memory, target } = await startServerAndGetSelectedTabMemory();
23 await memory.attach();
25 const allocs = [];
26 let eventsFired = 0;
27 let intervalId = null;
28 function onAlloc() {
29 eventsFired++;
31 function startAllocating() {
32 intervalId = setInterval(() => {
33 for (let i = 100000; --i;) {
34 allocs.push({});
36 }, 1);
38 function stopAllocating() {
39 clearInterval(intervalId);
42 memory.on("allocations", onAlloc);
44 await memory.startRecordingAllocations({
45 drainAllocationsTimeout: 10,
46 });
48 await waitUntil(() => eventsFired > 5);
49 ok(eventsFired > 5,
50 "Some allocation events fired without allocating much via auto drain");
51 await memory.stopRecordingAllocations();
53 // Set a really high auto drain timer so we can test if
54 // it fires on GC
55 eventsFired = 0;
56 const startTime = performance.now();
57 const drainTimer = 1000000;
58 await memory.startRecordingAllocations({
59 drainAllocationsTimeout: drainTimer,
60 });
62 startAllocating();
63 await waitUntil(() => {
64 Cu.forceGC();
65 return eventsFired > 1;
66 });
67 stopAllocating();
68 ok(performance.now() - drainTimer < startTime,
69 "Allocation events fired on GC before timer");
70 await memory.stopRecordingAllocations();
72 memory.off("allocations", onAlloc);
73 await memory.detach();
74 destroyServerAndFinish(target);
75 })();
77 </script>
78 </pre>
79 </body>
80 </html>