Chromium Code Reviews| Index: test/inspector/debugger/async-stacks-limit.js |
| diff --git a/test/inspector/debugger/async-stacks-limit.js b/test/inspector/debugger/async-stacks-limit.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2d12a042fa3a51a2e37afde90bd10e38740eec45 |
| --- /dev/null |
| +++ b/test/inspector/debugger/async-stacks-limit.js |
| @@ -0,0 +1,136 @@ |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +print('Checks that async stacks works good with different limits'); |
| + |
| +InspectorTest.addScript(` |
| +var resolveTest; |
| + |
| +function foo1() { |
| + debugger; |
| +} |
| + |
| +function foo2() { |
| + debugger; |
| + if (resolveTest) resolveTest(); |
| +} |
| + |
| +function promise() { |
| + var resolve1; |
| + var p1 = new Promise(resolve => resolve1 = resolve); |
| + var p2 = p1.then(foo1); |
| + resolve1(); |
| + return p2; |
| +} |
| + |
| +function twoPromises() { |
| + var resolve1; |
| + var resolve2; |
| + var p1 = new Promise(resolve => resolve1 = resolve); |
| + var p2 = new Promise(resolve => resolve2 = resolve); |
| + var p3 = p1.then(foo1); |
| + var p4 = p2.then(foo2); |
| + resolve1(); |
| + resolve2(); |
| + return Promise.all([p3, p4]); |
| +} |
| + |
| +function twoSetTimeout() { |
| + setTimeout(foo1, 0); |
| + setTimeout(foo2, 0); |
| + return new Promise(resolve => resolveTest = resolve); |
| +} |
| + |
| +function threeSetTimeout() { |
| + setTimeout(foo1, 0); |
| + setTimeout(foo2, 0); |
| + return new Promise(resolve => resolveTest = resolve); |
| +} |
| + |
| +//# sourceURL=test.js`, 7, 26); |
| + |
| +InspectorTest.setupScriptMap(); |
| +Protocol.Debugger.onPaused(message => { |
| + InspectorTest.logCallFrames(message.params.callFrames); |
| + var asyncStackTrace = message.params.asyncStackTrace; |
| + while (asyncStackTrace) { |
| + InspectorTest.log(`-- ${asyncStackTrace.description} --`); |
| + InspectorTest.logCallFrames(asyncStackTrace.callFrames); |
| + asyncStackTrace = asyncStackTrace.parent; |
| + } |
| + InspectorTest.log(''); |
| + Protocol.Debugger.resume(); |
| +}); |
| + |
| +Protocol.Debugger.enable(); |
| +Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 }); |
| +InspectorTest.runTestSuite([ |
| + function testZeroLimit(next) { |
| + Protocol.Runtime.evaluate({ |
| + expression: 'setMaxAsyncTaskStacks(0)//# sourceURL=expr.js'}) |
| + .then(() => Protocol.Runtime.evaluate({ |
| + expression: 'promise()//# sourceURL=expr.js', awaitPromise: true |
| + })) |
| + .then(() => cancelAllAsyncTasks()) |
| + .then(next); |
| + }, |
| + |
| + function testOneLimit(next) { |
| + Protocol.Runtime.evaluate({ |
| + expression: 'setMaxAsyncTaskStacks(1)//# sourceURL=expr.js'}) |
| + .then(() => Protocol.Runtime.evaluate({ |
| + expression: 'promise()//# sourceURL=expr.js', awaitPromise: true |
| + })) |
| + .then(() => cancelAllAsyncTasks()) |
| + .then(next); |
| + }, |
| + |
| + function testOneLimitTwoPromises(next) { |
| + // Should be no async stacks because when first microtask is finished |
| + // it will resolve and schedule p3 - will remove async stack for scheduled |
| + // p2. |
| + Protocol.Runtime.evaluate({ |
| + expression: 'setMaxAsyncTaskStacks(1)//# sourceURL=expr.js'}) |
| + .then(() => Protocol.Runtime.evaluate({ |
| + expression: 'twoPromises()//# sourceURL=expr.js', awaitPromise: true |
| + })) |
| + .then(() => cancelAllAsyncTasks()) |
| + .then(next); |
| + }, |
| + |
| + function testTwoLimitTwoPromises(next) { |
| + Protocol.Runtime.evaluate({ |
| + expression: 'setMaxAsyncTaskStacks(2)//# sourceURL=expr.js'}) |
| + .then(() => Protocol.Runtime.evaluate({ |
| + expression: 'twoPromises()//# sourceURL=expr.js', awaitPromise: true |
| + })) |
| + .then(() => cancelAllAsyncTasks()) |
| + .then(next); |
| + }, |
| + |
| + function testOneLimitTwoSetTimeouts(next) { |
| + Protocol.Runtime.evaluate({ |
| + expression: 'setMaxAsyncTaskStacks(1)//# sourceURL=expr.js'}) |
| + .then(() => Protocol.Runtime.evaluate({ |
| + expression: 'twoSetTimeout()//# sourceURL=expr.js', awaitPromise: true |
| + })) |
| + .then(() => cancelAllAsyncTasks()) |
| + .then(next); |
| + }, |
| + |
| + function testTwoLimitTwoSetTimeouts(next) { |
|
dgozman
2016/12/18 03:31:01
Let's add testTenLimitTwentySetTimeouts.
kozy
2016/12/18 06:27:38
Done.
|
| + Protocol.Runtime.evaluate({ |
| + expression: 'setMaxAsyncTaskStacks(2)//# sourceURL=expr.js'}) |
| + .then(() => Protocol.Runtime.evaluate({ |
| + expression: 'twoSetTimeout()//# sourceURL=expr.js', awaitPromise: true |
| + })) |
| + .then(() => cancelAllAsyncTasks()) |
| + .then(next); |
| + } |
| +]); |
| + |
| +function cancelAllAsyncTasks() { |
| + return Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 0 }) |
| + .then(() => Protocol.Debugger.setAsyncCallStackDepth({ maxDepth: 128 })); |
| +} |