Skip to content

Commit

Permalink
PanelModel: Clear queryRunner on destroy (grafana#16906)
Browse files Browse the repository at this point in the history
* PanelModel: Clear queryRunner on destroy

* fix test asumptions
  • Loading branch information
torkelo authored May 6, 2019
1 parent 48ae930 commit f8393fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
20 changes: 13 additions & 7 deletions public/app/features/dashboard/state/PanelModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ describe('PanelModel', () => {
});

describe('when changing panel type', () => {
let panelQueryRunner: any;

beforeEach(() => {
panelQueryRunner = model.getQueryRunner();
model.changePlugin(getPanelPlugin({ id: 'graph' }));
model.alert = { id: 2 };
});
Expand All @@ -109,9 +106,9 @@ describe('PanelModel', () => {
expect(model.alert).toBe(undefined);
});

it('getQueryRunner() should return same instance after plugin change', () => {
const sameQueryRunner = model.getQueryRunner();
expect(panelQueryRunner).toBe(sameQueryRunner);
it('panelQueryRunner should be cleared', () => {
const panelQueryRunner = (model as any).queryRunner;
expect(panelQueryRunner).toBeFalsy();
});
});

Expand All @@ -131,19 +128,28 @@ describe('PanelModel', () => {
});
});

describe('when changing to react panel', () => {
describe('when changing to react panel from angular panel', () => {
let panelQueryRunner: any;

const onPanelTypeChanged = jest.fn();
const reactPlugin = getPanelPlugin({ id: 'react' }).setPanelChangeHandler(onPanelTypeChanged as any);

beforeEach(() => {
model.changePlugin(reactPlugin);
panelQueryRunner = model.getQueryRunner();
});

it('should call react onPanelTypeChanged', () => {
expect(onPanelTypeChanged.mock.calls.length).toBe(1);
expect(onPanelTypeChanged.mock.calls[0][1]).toBe('table');
expect(onPanelTypeChanged.mock.calls[0][2].thresholds).toBeDefined();
});

it('getQueryRunner() should return same instance after changing to another react panel', () => {
model.changePlugin(getPanelPlugin({ id: 'react2' }));
const sameQueryRunner = model.getQueryRunner();
expect(panelQueryRunner).toBe(sameQueryRunner);
});
});

describe('get panel options', () => {
Expand Down
1 change: 1 addition & 0 deletions public/app/features/dashboard/state/PanelModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export class PanelModel {

if (this.queryRunner) {
this.queryRunner.destroy();
this.queryRunner = null;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion public/app/features/dashboard/state/PanelQueryState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class PanelQueryState {
sendLegacy = false;

// A promise for the running query
private executor?: Promise<PanelData>;
private executor?: Promise<PanelData> = null;
private rejector = (reason?: any) => {};
private datasource: DataSourceApi = {} as any;

Expand Down

0 comments on commit f8393fb

Please sign in to comment.