Browse Source

PanelQueryState: check for existing running query (#16894)

Fixes #16880
Ryan McKinley 6 years ago
parent
commit
513c79d392

+ 12 - 4
public/app/features/dashboard/state/PanelQueryState.test.ts

@@ -34,14 +34,22 @@ describe('PanelQueryState', () => {
     expect(empty.series.length).toBe(0);
     expect(empty.series.length).toBe(0);
     expect(hasRun).toBeFalsy();
     expect(hasRun).toBeFalsy();
 
 
-    empty = await state.execute(
-      ds,
-      getQueryOptions({ targets: [{ hide: true, refId: 'X' }, { hide: true, refId: 'Y' }, { hide: true, refId: 'Z' }] })
-    );
+    const query = getQueryOptions({
+      targets: [{ hide: true, refId: 'X' }, { hide: true, refId: 'Y' }, { hide: true, refId: 'Z' }],
+    });
+
+    empty = await state.execute(ds, query);
     // should not run any hidden queries'
     // should not run any hidden queries'
     expect(state.getActiveRunner()).toBeFalsy();
     expect(state.getActiveRunner()).toBeFalsy();
     expect(empty.series.length).toBe(0);
     expect(empty.series.length).toBe(0);
     expect(hasRun).toBeFalsy();
     expect(hasRun).toBeFalsy();
+
+    // Check for the same query
+    expect(state.isSameQuery(ds, query)).toBeTruthy();
+
+    // Check for differnet queries
+    expect(state.isSameQuery(new MockDataSourceApi('test'), query)).toBeFalsy();
+    expect(state.isSameQuery(ds, getQueryOptions({ targets: [{ refId: 'differnet' }] }))).toBeFalsy();
   });
   });
 });
 });
 
 

+ 1 - 0
public/app/features/dashboard/state/PanelQueryState.ts

@@ -95,6 +95,7 @@ export class PanelQueryState {
 
 
   execute(ds: DataSourceApi, req: DataQueryRequest): Promise<PanelData> {
   execute(ds: DataSourceApi, req: DataQueryRequest): Promise<PanelData> {
     this.request = req;
     this.request = req;
+    this.datasource = ds;
 
 
     // Return early if there are no queries to run
     // Return early if there are no queries to run
     if (!req.targets.length) {
     if (!req.targets.length) {