Skip to content

Commit 9026b40

Browse files
authored
test: breakpoint after breakpoint (#10)
* fix: LiveLog.toJson * test: breakpoint after breakpoint
1 parent a632d16 commit 9026b40

File tree

4 files changed

+63
-9
lines changed

4 files changed

+63
-9
lines changed

src/control/LiveInstrumentRemote.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export default class LiveInstrumentRemote {
3232
breakpointIdToInstrumentIds: Map<string, string[]> = new Map<string, string[]>();
3333
instrumentCache: Map<string, CachedInstrument> = new Map<string, CachedInstrument>();
3434
eventBus: EventBus;
35-
pendingBreakpoints: Map<string, Promise<string>> = new Map<string, Promise<string>>();
3635

3736
constructor(eventBus: EventBus) {
3837
this.eventBus = eventBus;
@@ -147,6 +146,7 @@ export default class LiveInstrumentRemote {
147146
if (data[i].success) {
148147
let instrument = instruments[i];
149148
if (!instrument) {
149+
debugLog(`Instrument ${instrumentIds[i]} not found`);
150150
continue;
151151
}
152152

@@ -225,26 +225,23 @@ export default class LiveInstrumentRemote {
225225

226226
private async setBreakpoint(scriptId: string, line: number): Promise<string> {
227227
debugLog(`Setting breakpoint at ${scriptId}:${line}`);
228-
if (this.pendingBreakpoints.has(scriptId + ':' + line)) {
229-
return this.pendingBreakpoints.get(scriptId + ':' + line);
230-
}
231-
let promise = new Promise<string>((resolve, reject) => this.session.post("Debugger.setBreakpoint", {
228+
return new Promise<string>((resolve, reject) => this.session.post("Debugger.setBreakpoint", {
232229
location: {
233230
scriptId: scriptId,
234231
lineNumber: line
235232
}
236233
}, (err, res) => {
237234
if (err) {
235+
debugLog(`Error setting breakpoint at ${scriptId}:${line}: ${err}`);
238236
reject(err);
239237
} else {
240238
resolve(res.breakpointId);
241239
}
242240
}));
243-
this.pendingBreakpoints.set(scriptId + ':' + line, promise);
244-
return promise;
245241
}
246242

247243
private removeBreakpoint(breakpointId: string) {
244+
debugLog(`Removing breakpoint ${breakpointId}`);
248245
this.breakpointIdToInstrumentIds.delete(breakpointId);
249246
this.locationToBreakpointId.forEach((value, key) => {
250247
if (value === breakpointId) {
@@ -279,15 +276,17 @@ export default class LiveInstrumentRemote {
279276
if (breakpointId) {
280277
this.breakpointIdToInstrumentIds.get(breakpointId).push(instrument.id);
281278
instrument.meta.breakpointId = breakpointId;
282-
this.eventBus.publish("spp.processor.status.live-instrument-applied", instrument.toJson())
279+
this.eventBus.publish("spp.processor.status.live-instrument-applied", instrument.toJson());
280+
debugLog(`Applied instrument: ${JSON.stringify(instrument.toJson())}`);
283281
return;
284282
}
285283

286284
return this.setBreakpoint(location.scriptId, location.line).then(breakpointId => {
287285
this.locationToBreakpointId.set(location.scriptId + ":" + location.line, breakpointId);
288286
this.breakpointIdToInstrumentIds.set(breakpointId, [instrument.id]);
289287
instrument.meta.breakpointId = breakpointId;
290-
this.eventBus.publish("spp.processor.status.live-instrument-applied", instrument.toJson())
288+
this.eventBus.publish("spp.processor.status.live-instrument-applied", instrument.toJson());
289+
debugLog(`Applied instrument: ${JSON.stringify(instrument.toJson())}`);
291290
})
292291
}
293292

src/model/instruments/LiveLog.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ export default class LiveLog extends LiveInstrument {
2828
})()`;
2929
}
3030
}
31+
32+
toJson(): any {
33+
return {
34+
...super.toJson(),
35+
logFormat: this.logFormat,
36+
logArguments: this.logArguments
37+
};
38+
}
3139
}

test/BreakpointAfterBreakpointTest.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const assert = require('assert');
2+
const TestUtils = require("./TestUtils.js");
3+
4+
module.exports = function () {
5+
function hitBreakpoint() {
6+
TestUtils.addLineLabel("done", () => TestUtils.getLineNumber())
7+
}
8+
9+
it('add first live breakpoint', async function () {
10+
hitBreakpoint() //setup labels
11+
12+
await TestUtils.addLiveBreakpoint({
13+
"source": TestUtils.getFilename()(),
14+
"line": TestUtils.getLineLabelNumber("done")
15+
}, null, 1).then(function (res) {
16+
assert.equal(res.status, 200);
17+
hitBreakpoint(); //trigger breakpoint
18+
}).catch(function (err) {
19+
assert.fail(err)
20+
});
21+
});
22+
23+
it('verify first breakpoint hit', async function () {
24+
this.timeout(2000)
25+
let event = await TestUtils.awaitMarkerEvent("BREAKPOINT_HIT");
26+
assert.notEqual(event, null);
27+
});
28+
29+
it('add second live breakpoint', async function () {
30+
await TestUtils.addLiveBreakpoint({
31+
"source": TestUtils.getFilename()(),
32+
"line": TestUtils.getLineLabelNumber("done")
33+
}, null, 1).then(function (res) {
34+
assert.equal(res.status, 200);
35+
hitBreakpoint(); //trigger breakpoint
36+
}).catch(function (err) {
37+
assert.fail(err)
38+
});
39+
});
40+
41+
it('verify second breakpoint hit', async function () {
42+
this.timeout(2000)
43+
let event = await TestUtils.awaitMarkerEvent("BREAKPOINT_HIT");
44+
assert.notEqual(event, null);
45+
});
46+
};

test/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const TestUtils = require("./TestUtils");
33
before(TestUtils.setupProbe);
44
after(TestUtils.teardownProbe);
55

6+
describe("test breakpoint after breakpoint", require("./BreakpointAfterBreakpointTest"));
67
describe("test simple primitives", require("./SimplePrimitivesLiveInstrumentTest"));
78
describe("test simple collections", require("./SimpleCollectionsLiveInstrumentTest"));
89
describe("test live log", require("./LiveLogTest"));

0 commit comments

Comments
 (0)