OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 InspectorTest.log('Checks that we drop old async call chains.'); |
| 6 |
| 7 Protocol.Debugger.enable(); |
| 8 Protocol.Runtime.enable(); |
| 9 InspectorTest.runAsyncTestSuite([ |
| 10 async function testInfrastructure() { |
| 11 Protocol.Debugger.setAsyncCallStackDepth({maxDepth: 128}); |
| 12 await setMaxAsyncTaskStacks(1024); |
| 13 runWithAsyncChainPromise(1, 'console.trace(42)'); |
| 14 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 15 |
| 16 await setMaxAsyncTaskStacks(1024); |
| 17 runWithAsyncChainPromise(2, 'console.trace(42)'); |
| 18 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 19 |
| 20 await setMaxAsyncTaskStacks(1024); |
| 21 runWithAsyncChainPromise(5, 'console.trace(42)'); |
| 22 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 23 |
| 24 await setMaxAsyncTaskStacks(1024); |
| 25 runWithAsyncChainSetTimeout(1, 'console.trace(42)'); |
| 26 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 27 |
| 28 await setMaxAsyncTaskStacks(1024); |
| 29 runWithAsyncChainSetTimeout(2, 'console.trace(42)'); |
| 30 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 31 |
| 32 await setMaxAsyncTaskStacks(1024); |
| 33 runWithAsyncChainSetTimeout(5, 'console.trace(42)'); |
| 34 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 35 }, |
| 36 |
| 37 async function testZeroLimit() { |
| 38 const limit = 0; |
| 39 Protocol.Debugger.setAsyncCallStackDepth({maxDepth: 128}); |
| 40 |
| 41 await setMaxAsyncTaskStacks(limit); |
| 42 runWithAsyncChainPromise(1, 'console.trace(42)'); |
| 43 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 44 |
| 45 await setMaxAsyncTaskStacks(limit); |
| 46 runWithAsyncChainPromise(2, 'console.trace(42)'); |
| 47 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 48 |
| 49 await setMaxAsyncTaskStacks(limit); |
| 50 runWithAsyncChainSetTimeout(1, 'console.trace(42)'); |
| 51 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 52 |
| 53 await setMaxAsyncTaskStacks(limit); |
| 54 runWithAsyncChainSetTimeout(2, 'console.trace(42)'); |
| 55 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 56 }, |
| 57 |
| 58 async function testOneLimit() { |
| 59 const limit = 1; |
| 60 Protocol.Debugger.setAsyncCallStackDepth({maxDepth: 128}); |
| 61 |
| 62 await setMaxAsyncTaskStacks(limit); |
| 63 runWithAsyncChainPromise(1, 'console.trace(42)'); |
| 64 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 65 |
| 66 await setMaxAsyncTaskStacks(limit); |
| 67 runWithAsyncChainPromise(2, 'console.trace(42)'); |
| 68 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 69 |
| 70 await setMaxAsyncTaskStacks(limit); |
| 71 runWithAsyncChainSetTimeout(1, 'console.trace(42)'); |
| 72 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 73 |
| 74 await setMaxAsyncTaskStacks(limit); |
| 75 runWithAsyncChainSetTimeout(2, 'console.trace(42)'); |
| 76 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 77 }, |
| 78 |
| 79 async function testTwoLimit() { |
| 80 const limit = 2; |
| 81 Protocol.Debugger.setAsyncCallStackDepth({maxDepth: 128}); |
| 82 |
| 83 await setMaxAsyncTaskStacks(limit); |
| 84 runWithAsyncChainPromise(1, 'console.trace(42)'); |
| 85 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 86 |
| 87 await setMaxAsyncTaskStacks(limit); |
| 88 runWithAsyncChainPromise(2, 'console.trace(42)'); |
| 89 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 90 |
| 91 await setMaxAsyncTaskStacks(limit); |
| 92 runWithAsyncChainPromise(3, 'console.trace(42)'); |
| 93 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 94 |
| 95 await setMaxAsyncTaskStacks(limit); |
| 96 runWithAsyncChainSetTimeout(1, 'console.trace(42)'); |
| 97 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 98 |
| 99 await setMaxAsyncTaskStacks(limit); |
| 100 runWithAsyncChainSetTimeout(2, 'console.trace(42)'); |
| 101 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 102 |
| 103 await setMaxAsyncTaskStacks(limit); |
| 104 runWithAsyncChainSetTimeout(3, 'console.trace(42)'); |
| 105 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 106 }, |
| 107 |
| 108 async function testMoreThanTwoLimit() { |
| 109 for (let limit = 3; limit <= 7; ++limit) { |
| 110 Protocol.Debugger.setAsyncCallStackDepth({maxDepth: 128}); |
| 111 |
| 112 await setMaxAsyncTaskStacks(limit); |
| 113 runWithAsyncChainPromise(1, 'console.trace(42)'); |
| 114 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 115 |
| 116 await setMaxAsyncTaskStacks(limit); |
| 117 runWithAsyncChainPromise(2, 'console.trace(42)'); |
| 118 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 119 |
| 120 await setMaxAsyncTaskStacks(limit); |
| 121 runWithAsyncChainPromise(3, 'console.trace(42)'); |
| 122 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 123 |
| 124 await setMaxAsyncTaskStacks(limit); |
| 125 runWithAsyncChainSetTimeout(1, 'console.trace(42)'); |
| 126 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 127 |
| 128 await setMaxAsyncTaskStacks(limit); |
| 129 runWithAsyncChainSetTimeout(2, 'console.trace(42)'); |
| 130 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 131 |
| 132 await setMaxAsyncTaskStacks(limit); |
| 133 runWithAsyncChainSetTimeout(3, 'console.trace(42)'); |
| 134 dumpAsyncChainLength(await Protocol.Runtime.onceConsoleAPICalled()); |
| 135 } |
| 136 }, |
| 137 ]); |
| 138 |
| 139 function runWithAsyncChainPromise(len, source) { |
| 140 InspectorTest.log(`Run expression '${source}' with async chain len: ${len}`); |
| 141 let then = '.then(() => 1)'; |
| 142 let pause = `.then(() => { ${source} })`; |
| 143 Protocol.Runtime.evaluate({ |
| 144 expression: `Promise.resolve()${then.repeat(len - 1)}${pause}` |
| 145 }); |
| 146 } |
| 147 |
| 148 function runWithAsyncChainSetTimeout(len, source) { |
| 149 InspectorTest.log(`Run expression '${source}' with async chain len: ${len}`); |
| 150 let setTimeoutPrefix = '() => setTimeout('; |
| 151 let setTimeoutSuffix = ', 0)'; |
| 152 Protocol.Runtime.evaluate({ |
| 153 expression: `setTimeout(${setTimeoutPrefix.repeat(len - 1)}'${source}'${setT
imeoutSuffix.repeat(len - 1)}, 0)` |
| 154 }); |
| 155 } |
| 156 |
| 157 function dumpAsyncChainLength(message) { |
| 158 let stackTrace = message.params.asyncStackTrace || message.params.stackTrace.p
arent; |
| 159 let asyncChainCount = 0; |
| 160 while (stackTrace) { |
| 161 ++asyncChainCount; |
| 162 stackTrace = stackTrace.parent; |
| 163 } |
| 164 InspectorTest.log(`actual async chain len: ${asyncChainCount}\n`); |
| 165 } |
| 166 |
| 167 async function setMaxAsyncTaskStacks(max) { |
| 168 let expression = `setMaxAsyncTaskStacks(${max})`; |
| 169 InspectorTest.log(expression); |
| 170 await Protocol.Runtime.evaluate({expression}); |
| 171 } |
OLD | NEW |