forked from googleapis/cloud-debug-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfib.js
96 lines (86 loc) · 2.82 KB
/
fib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* KEEP THIS CODE AT THE TOP SO THAT THE BREAKPOINT LINE NUMBERS DON'T CHANGE */
'use strict';
function fib(n) {
if (n < 2) { return n; } var o = { a: [1, 'hi', true] };
return fib(n - 1, o) + fib(n - 2, o); // adding o to appease linter.
}
// Copyright 2016 Google LLC
//
// 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.
const uuid = require('uuid');
// eslint-disable-next-line node/no-missing-require
const nocks = require('../nocks.js');
nocks.projectId('fake-project-id');
// mock the metadata instance to uniformly make this look like a non-gcp
// environment.
nocks.metadataInstance();
const UUID = process.argv[2] || uuid.v4();
console.log('UUID: ', UUID);
// eslint-disable-next-line node/no-missing-require
const debuglet = require('../../..').start({
debug: {
logLevel: 2,
log: {
maxLogsPerSecond: 2,
logDelaySeconds: 5,
// Use a custom logpoint function that converts everything lower case.
logFunction: message => {
console.log(message.toLowerCase());
},
},
breakpointUpdateIntervalSec: 1,
testMode_: true,
allowExpressions: true,
description: UUID,
},
});
// Make troubleshooting easier if run by itself
if (!process.send) {
process.send = console.log;
}
let timedOut = false;
const registrationTimeout = setTimeout(() => {
timedOut = true;
process.send({error: "debuggee didn't register in time"});
setTimeout(() => {
// eslint-disable-next-line no-process-exit
process.exit(1);
}, 2000);
}, 5000);
debuglet.once('registered', () => {
if (timedOut) {
return;
}
clearTimeout(registrationTimeout);
let errorMessage;
function setErrorIfNotOk(predicate, message) {
if (!errorMessage && !predicate) {
errorMessage = message;
}
}
const debuggee = debuglet.debuggee;
setErrorIfNotOk(debuggee, 'should create debuggee');
setErrorIfNotOk(debuggee.project, 'debuggee should have a project');
setErrorIfNotOk(debuggee.id, 'debuggee should have registered');
if (!errorMessage) {
// The parent process needs to know the debuggee and project IDs.
process.send({debuggeeId: debuggee.id, projectId: debuggee.project});
setInterval(fib.bind(null, 12), 2000);
} else {
process.send({error: errorMessage});
setTimeout(() => {
// eslint-disable-next-line no-process-exit
process.exit(1);
}, 2000);
}
});