|
| 1 | +/** |
| 2 | + * Copyright 2015 Google Inc. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +'use strict'; |
| 17 | + |
| 18 | +var assert = require('assert'); |
| 19 | +var request = require('request'); |
| 20 | +var logger = require('@google/cloud-diagnostics-common').logger; |
| 21 | +var config = require('../../config.js'); |
| 22 | +var semver = require('semver'); |
| 23 | +var Debuglet = require('../../lib/debuglet.js'); |
| 24 | + |
| 25 | +var DEBUGGEE_ID = 'bar'; |
| 26 | +var API = 'https://clouddebugger.googleapis.com'; |
| 27 | +var REGISTER_PATH = '/v2/controller/debuggees/register'; |
| 28 | +var BPS_PATH = '/v2/controller/debuggees/' + DEBUGGEE_ID + '/breakpoints'; |
| 29 | + |
| 30 | +var nock = require('nock'); |
| 31 | +nock.disableNetConnect(); |
| 32 | + |
| 33 | +var debuglet; |
| 34 | + |
| 35 | +describe(__filename, function(){ |
| 36 | + beforeEach(function() { |
| 37 | + process.env.GCLOUD_PROJECT_NUM = 0; |
| 38 | + debuglet = new Debuglet( |
| 39 | + config, logger.create(config.logLevel, '@google/cloud-debug')); |
| 40 | + debuglet.once('started', function() { |
| 41 | + debuglet.debugletApi_.request_ = request; // Avoid authing. |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + afterEach(function() { |
| 46 | + debuglet.stop(); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should capture breakpoint quickly', function(done) { |
| 50 | + var h = require('../fixtures/expensive-capture.js'); |
| 51 | + var hitMillis; |
| 52 | + var reportedMillis; |
| 53 | + var expensiveBp = { |
| 54 | + id: 'test', |
| 55 | + location: { path: 'fixtures/expensive-capture.js', line: 7}, |
| 56 | + condition: 'n===7', |
| 57 | + expressions: ['a', 'process'] |
| 58 | + }; |
| 59 | + |
| 60 | + var scope = nock(API) |
| 61 | + .post(REGISTER_PATH) |
| 62 | + .reply(200, { |
| 63 | + debuggee: { |
| 64 | + id: DEBUGGEE_ID |
| 65 | + } |
| 66 | + }) |
| 67 | + .get(BPS_PATH) |
| 68 | + .reply(200, { |
| 69 | + breakpoints: [expensiveBp] |
| 70 | + }) |
| 71 | + .put(BPS_PATH + '/test', function(body) { |
| 72 | + reportedMillis = Date.now(); |
| 73 | + return body.breakpoint.isFinalState && !body.breakpoint.status; |
| 74 | + }) |
| 75 | + .reply(200); |
| 76 | + |
| 77 | + debuglet.once('registered', function(id) { |
| 78 | + assert(id === DEBUGGEE_ID); |
| 79 | + setTimeout(function() { |
| 80 | + hitMillis = Date.now(); |
| 81 | + h.rec(7); |
| 82 | + setTimeout(function() { |
| 83 | + // See slowdown in state.js#resolveMirror_ |
| 84 | + if (semver.satisfies(process.version, '<1.6')) { |
| 85 | + assert(reportedMillis - hitMillis < 110); |
| 86 | + } else { |
| 87 | + assert(reportedMillis - hitMillis < 20); |
| 88 | + } |
| 89 | + scope.done(); |
| 90 | + done(); |
| 91 | + }, 10); |
| 92 | + }, 500); |
| 93 | + }); |
| 94 | + |
| 95 | + debuglet.start(); |
| 96 | + }); |
| 97 | +}); |
| 98 | + |
0 commit comments