-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Disable crashing pugins When one of the plugins subscriptions fails, disable the whole plugin. * pr feedback * fix logging * lint
- Loading branch information
1 parent
1b9ee54
commit 679e7e2
Showing
2 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use strict' | ||
|
||
require('../setup/tap') | ||
|
||
const Plugin = require('../../src/plugins/plugin') | ||
const plugins = require('../../src/plugins') | ||
const { channel } = require('dc-polyfill') | ||
|
||
describe('Plugin', () => { | ||
class BadPlugin extends Plugin { | ||
static get id () { return 'badPlugin' } | ||
|
||
constructor () { | ||
super() | ||
this.addSub('apm:badPlugin:start', this.start) | ||
} | ||
|
||
start () { | ||
throw new Error('this is one bad plugin') | ||
} | ||
} | ||
|
||
class GoodPlugin extends Plugin { | ||
static get id () { return 'goodPlugin' } | ||
|
||
constructor () { | ||
super() | ||
this.addSub('apm:goodPlugin:start', this.start) | ||
} | ||
|
||
start () { | ||
// | ||
} | ||
} | ||
|
||
const testPlugins = { badPlugin: BadPlugin, goodPlugin: GoodPlugin } | ||
const loadChannel = channel('dd-trace:instrumentation:load') | ||
|
||
before(() => { | ||
for (const [name, cls] of Object.entries(testPlugins)) { | ||
plugins[name] = cls | ||
loadChannel.publish({ name }) | ||
} | ||
}) | ||
|
||
after(() => { Object.keys(testPlugins).forEach(name => delete plugins[name]) }) | ||
|
||
it('should disable upon error', () => { | ||
const plugin = new BadPlugin() | ||
plugin.configure({ enabled: true }) | ||
|
||
expect(plugin._enabled).to.be.true | ||
|
||
channel('apm:badPlugin:start').publish({ foo: 'bar' }) | ||
|
||
expect(plugin._enabled).to.be.false | ||
}) | ||
|
||
it('should not disable with no error', () => { | ||
const plugin = new GoodPlugin() | ||
plugin.configure({ enabled: true }) | ||
|
||
expect(plugin._enabled).to.be.true | ||
|
||
channel('apm:goodPlugin:start').publish({ foo: 'bar' }) | ||
|
||
expect(plugin._enabled).to.be.true | ||
}) | ||
}) |