From 0d9a312cb511be986843469d44396ca572f0a8ad Mon Sep 17 00:00:00 2001 From: Matt Loring Date: Thu, 14 Jan 2016 14:10:13 -0800 Subject: [PATCH] Add performance test to monitor capture time Adds a test which captures a breakpoint with large watch expressions and ensures that it takes less than 20ms e2e after node 1.6 and less than 110ms e2e before node 1.6. Actual capture time is shorter as it does not include code running before breakpoint is hit or simulated network operation afterwards. Capturing state is too slow on travis so this test does not run with unit tests. Addresses #71 --- test/e2e/test-capture-time.js | 98 ++++++++++++++++++++++++++++++ test/fixtures/expensive-capture.js | 9 +++ 2 files changed, 107 insertions(+) create mode 100644 test/e2e/test-capture-time.js create mode 100644 test/fixtures/expensive-capture.js diff --git a/test/e2e/test-capture-time.js b/test/e2e/test-capture-time.js new file mode 100644 index 00000000..9ceddfa0 --- /dev/null +++ b/test/e2e/test-capture-time.js @@ -0,0 +1,98 @@ +/** + * Copyright 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +var assert = require('assert'); +var request = require('request'); +var logger = require('@google/cloud-diagnostics-common').logger; +var config = require('../../config.js'); +var semver = require('semver'); +var Debuglet = require('../../lib/debuglet.js'); + +var DEBUGGEE_ID = 'bar'; +var API = 'https://clouddebugger.googleapis.com'; +var REGISTER_PATH = '/v2/controller/debuggees/register'; +var BPS_PATH = '/v2/controller/debuggees/' + DEBUGGEE_ID + '/breakpoints'; + +var nock = require('nock'); +nock.disableNetConnect(); + +var debuglet; + +describe(__filename, function(){ + beforeEach(function() { + process.env.GCLOUD_PROJECT_NUM = 0; + debuglet = new Debuglet( + config, logger.create(config.logLevel, '@google/cloud-debug')); + debuglet.once('started', function() { + debuglet.debugletApi_.request_ = request; // Avoid authing. + }); + }); + + afterEach(function() { + debuglet.stop(); + }); + + it('should capture breakpoint quickly', function(done) { + var h = require('../fixtures/expensive-capture.js'); + var hitMillis; + var reportedMillis; + var expensiveBp = { + id: 'test', + location: { path: 'fixtures/expensive-capture.js', line: 7}, + condition: 'n===7', + expressions: ['a', 'process'] + }; + + var scope = nock(API) + .post(REGISTER_PATH) + .reply(200, { + debuggee: { + id: DEBUGGEE_ID + } + }) + .get(BPS_PATH) + .reply(200, { + breakpoints: [expensiveBp] + }) + .put(BPS_PATH + '/test', function(body) { + reportedMillis = Date.now(); + return body.breakpoint.isFinalState && !body.breakpoint.status; + }) + .reply(200); + + debuglet.once('registered', function(id) { + assert(id === DEBUGGEE_ID); + setTimeout(function() { + hitMillis = Date.now(); + h.rec(7); + setTimeout(function() { + // See slowdown in state.js#resolveMirror_ + if (semver.satisfies(process.version, '<1.6')) { + assert(reportedMillis - hitMillis < 110); + } else { + assert(reportedMillis - hitMillis < 20); + } + scope.done(); + done(); + }, 10); + }, 500); + }); + + debuglet.start(); + }); +}); + diff --git a/test/fixtures/expensive-capture.js b/test/fixtures/expensive-capture.js new file mode 100644 index 00000000..f10e488b --- /dev/null +++ b/test/fixtures/expensive-capture.js @@ -0,0 +1,9 @@ +'use strict'; +var a = new Array(50).map(function() { return ','; }); +module.exports.rec = function rec(n) { + if (n === 0) { + return 5; + } else { + return rec(n - 1); + } +};