Skip to content

test: breakpoint after breakpoint #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/control/LiveInstrumentRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export default class LiveInstrumentRemote {
breakpointIdToInstrumentIds: Map<string, string[]> = new Map<string, string[]>();
instrumentCache: Map<string, CachedInstrument> = new Map<string, CachedInstrument>();
eventBus: EventBus;
pendingBreakpoints: Map<string, Promise<string>> = new Map<string, Promise<string>>();

constructor(eventBus: EventBus) {
this.eventBus = eventBus;
Expand Down Expand Up @@ -147,6 +146,7 @@ export default class LiveInstrumentRemote {
if (data[i].success) {
let instrument = instruments[i];
if (!instrument) {
debugLog(`Instrument ${instrumentIds[i]} not found`);
continue;
}

Expand Down Expand Up @@ -225,26 +225,23 @@ export default class LiveInstrumentRemote {

private async setBreakpoint(scriptId: string, line: number): Promise<string> {
debugLog(`Setting breakpoint at ${scriptId}:${line}`);
if (this.pendingBreakpoints.has(scriptId + ':' + line)) {
return this.pendingBreakpoints.get(scriptId + ':' + line);
}
let promise = new Promise<string>((resolve, reject) => this.session.post("Debugger.setBreakpoint", {
return new Promise<string>((resolve, reject) => this.session.post("Debugger.setBreakpoint", {
location: {
scriptId: scriptId,
lineNumber: line
}
}, (err, res) => {
if (err) {
debugLog(`Error setting breakpoint at ${scriptId}:${line}: ${err}`);
reject(err);
} else {
resolve(res.breakpointId);
}
}));
this.pendingBreakpoints.set(scriptId + ':' + line, promise);
return promise;
}

private removeBreakpoint(breakpointId: string) {
debugLog(`Removing breakpoint ${breakpointId}`);
this.breakpointIdToInstrumentIds.delete(breakpointId);
this.locationToBreakpointId.forEach((value, key) => {
if (value === breakpointId) {
Expand Down Expand Up @@ -279,15 +276,17 @@ export default class LiveInstrumentRemote {
if (breakpointId) {
this.breakpointIdToInstrumentIds.get(breakpointId).push(instrument.id);
instrument.meta.breakpointId = breakpointId;
this.eventBus.publish("spp.processor.status.live-instrument-applied", instrument.toJson())
this.eventBus.publish("spp.processor.status.live-instrument-applied", instrument.toJson());
debugLog(`Applied instrument: ${JSON.stringify(instrument.toJson())}`);
return;
}

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

Expand Down
8 changes: 8 additions & 0 deletions src/model/instruments/LiveLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ export default class LiveLog extends LiveInstrument {
})()`;
}
}

toJson(): any {
return {
...super.toJson(),
logFormat: this.logFormat,
logArguments: this.logArguments
};
}
}
46 changes: 46 additions & 0 deletions test/BreakpointAfterBreakpointTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const assert = require('assert');
const TestUtils = require("./TestUtils.js");

module.exports = function () {
function hitBreakpoint() {
TestUtils.addLineLabel("done", () => TestUtils.getLineNumber())
}

it('add first live breakpoint', async function () {
hitBreakpoint() //setup labels

await TestUtils.addLiveBreakpoint({
"source": TestUtils.getFilename()(),
"line": TestUtils.getLineLabelNumber("done")
}, null, 1).then(function (res) {
assert.equal(res.status, 200);
hitBreakpoint(); //trigger breakpoint
}).catch(function (err) {
assert.fail(err)
});
});

it('verify first breakpoint hit', async function () {
this.timeout(2000)
let event = await TestUtils.awaitMarkerEvent("BREAKPOINT_HIT");
assert.notEqual(event, null);
});

it('add second live breakpoint', async function () {
await TestUtils.addLiveBreakpoint({
"source": TestUtils.getFilename()(),
"line": TestUtils.getLineLabelNumber("done")
}, null, 1).then(function (res) {
assert.equal(res.status, 200);
hitBreakpoint(); //trigger breakpoint
}).catch(function (err) {
assert.fail(err)
});
});

it('verify second breakpoint hit', async function () {
this.timeout(2000)
let event = await TestUtils.awaitMarkerEvent("BREAKPOINT_HIT");
assert.notEqual(event, null);
});
};
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const TestUtils = require("./TestUtils");
before(TestUtils.setupProbe);
after(TestUtils.teardownProbe);

describe("test breakpoint after breakpoint", require("./BreakpointAfterBreakpointTest"));
describe("test simple primitives", require("./SimplePrimitivesLiveInstrumentTest"));
describe("test simple collections", require("./SimpleCollectionsLiveInstrumentTest"));
describe("test live log", require("./LiveLogTest"));
Expand Down