Skip to content

Commit fe6ecb9

Browse files
authored
fix: impl breakpoint removed (#9)
1 parent 45bc5a8 commit fe6ecb9

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

src/control/ContextReceiver.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ namespace ContextReceiver {
5353
export function applyBreakpoint(breakpointId: string, source: string | undefined, line: number,
5454
frames: Debugger.CallFrame[], variables) {
5555
debugLog(`applyBreakpoint: ${breakpointId} ${source} ${line}`);
56-
let activeSpan = ContextManager.current.newLocalSpan(callFrameToString(frames[0]));
5756

57+
let liveBreakpoint = SourcePlusPlus.liveInstrumentRemote.instruments.get(breakpointId);
58+
if (liveBreakpoint.throttle.isRateLimited()) {
59+
return;
60+
} else {
61+
//todo: eval condition
62+
}
63+
64+
let activeSpan = ContextManager.current.newLocalSpan(callFrameToString(frames[0]));
5865
activeSpan.start();
5966

6067
let localVars = variables['local'];
@@ -94,6 +101,16 @@ namespace ContextReceiver {
94101
})
95102

96103
activeSpan.stop();
104+
105+
if (liveBreakpoint.isFinished()) {
106+
debugLog(`Finished breakpoint: ${breakpointId}`);
107+
SourcePlusPlus.liveInstrumentRemote.removeInstrument(breakpointId);
108+
109+
SourcePlusPlus.liveInstrumentRemote.eventBus.publish("spp.processor.status.live-instrument-removed", {
110+
instrument: JSON.stringify(liveBreakpoint.toJson()),
111+
occurredAt: Date.now()
112+
})
113+
}
97114
}
98115

99116
export function applyLog(liveLogId: string, logFormat: string, logArguments: any) {

test/HitLimitTest.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const assert = require('assert');
2+
const TestUtils = require("./TestUtils.js");
3+
4+
module.exports = function () {
5+
function hitLimit() {
6+
TestUtils.addLineLabel("done", () => TestUtils.getLineNumber())
7+
}
8+
9+
it('add live breakpoint', async function () {
10+
hitLimit() //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+
hitLimit(); //trigger breakpoint
18+
}).catch(function (err) {
19+
assert.fail(err)
20+
});
21+
});
22+
23+
it('verify breakpoint removed', async function () {
24+
this.timeout(2000)
25+
let event = await TestUtils.awaitMarkerEvent("BREAKPOINT_REMOVED");
26+
assert.notEqual(event, null);
27+
});
28+
};

test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ after(TestUtils.teardownProbe);
55

66
describe("test simple primitives", require("./SimplePrimitivesLiveInstrumentTest"));
77
describe("test simple collections", require("./SimpleCollectionsLiveInstrumentTest"));
8-
describe("test live log", require("./LiveLogTest"));
8+
describe("test live log", require("./LiveLogTest"));
9+
describe("test hit limit", require("./HitLimitTest"));

0 commit comments

Comments
 (0)