diff --git a/src/control/ContextReceiver.ts b/src/control/ContextReceiver.ts index c27a417..3d1220b 100644 --- a/src/control/ContextReceiver.ts +++ b/src/control/ContextReceiver.ts @@ -53,8 +53,15 @@ namespace ContextReceiver { export function applyBreakpoint(breakpointId: string, source: string | undefined, line: number, frames: Debugger.CallFrame[], variables) { debugLog(`applyBreakpoint: ${breakpointId} ${source} ${line}`); - let activeSpan = ContextManager.current.newLocalSpan(callFrameToString(frames[0])); + let liveBreakpoint = SourcePlusPlus.liveInstrumentRemote.instruments.get(breakpointId); + if (liveBreakpoint.throttle.isRateLimited()) { + return; + } else { + //todo: eval condition + } + + let activeSpan = ContextManager.current.newLocalSpan(callFrameToString(frames[0])); activeSpan.start(); let localVars = variables['local']; @@ -94,6 +101,16 @@ namespace ContextReceiver { }) activeSpan.stop(); + + if (liveBreakpoint.isFinished()) { + debugLog(`Finished breakpoint: ${breakpointId}`); + SourcePlusPlus.liveInstrumentRemote.removeInstrument(breakpointId); + + SourcePlusPlus.liveInstrumentRemote.eventBus.publish("spp.processor.status.live-instrument-removed", { + instrument: JSON.stringify(liveBreakpoint.toJson()), + occurredAt: Date.now() + }) + } } export function applyLog(liveLogId: string, logFormat: string, logArguments: any) { diff --git a/test/HitLimitTest.js b/test/HitLimitTest.js new file mode 100644 index 0000000..01eb573 --- /dev/null +++ b/test/HitLimitTest.js @@ -0,0 +1,28 @@ +const assert = require('assert'); +const TestUtils = require("./TestUtils.js"); + +module.exports = function () { + function hitLimit() { + TestUtils.addLineLabel("done", () => TestUtils.getLineNumber()) + } + + it('add live breakpoint', async function () { + hitLimit() //setup labels + + await TestUtils.addLiveBreakpoint({ + "source": TestUtils.getFilename()(), + "line": TestUtils.getLineLabelNumber("done") + }, null, 1).then(function (res) { + assert.equal(res.status, 200); + hitLimit(); //trigger breakpoint + }).catch(function (err) { + assert.fail(err) + }); + }); + + it('verify breakpoint removed', async function () { + this.timeout(2000) + let event = await TestUtils.awaitMarkerEvent("BREAKPOINT_REMOVED"); + assert.notEqual(event, null); + }); +}; \ No newline at end of file diff --git a/test/test.js b/test/test.js index 1097a5c..0bc2001 100644 --- a/test/test.js +++ b/test/test.js @@ -5,4 +5,5 @@ after(TestUtils.teardownProbe); describe("test simple primitives", require("./SimplePrimitivesLiveInstrumentTest")); describe("test simple collections", require("./SimpleCollectionsLiveInstrumentTest")); -describe("test live log", require("./LiveLogTest")); \ No newline at end of file +describe("test live log", require("./LiveLogTest")); +describe("test hit limit", require("./HitLimitTest")); \ No newline at end of file