MixedDatasource: Fixes infinite loop with empty query panel (#44265)

* MixedDatasource: Fixes infinite loop with empty query panel
This commit is contained in:
kay delaney 2022-01-20 13:12:45 +00:00 committed by GitHub
parent 30aa24a183
commit a728e9b4dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import { LoadingState } from '@grafana/data';
import { lastValueFrom } from 'rxjs';
import { getQueryOptions } from 'test/helpers/getQueryOptions';
import { DatasourceSrvMock, MockObservableDataSourceApi } from 'test/mocks/datasource_srv';
import { MIXED_DATASOURCE_NAME } from './MixedDataSource';
import { MixedDatasource } from './module';
const defaultDS = new MockObservableDataSourceApi('DefaultDS', [{ data: ['DDD'] }]);
@ -126,4 +127,17 @@ describe('MixedDatasource', () => {
expect(results[1].state).toBe(LoadingState.Done);
});
});
it('should filter out MixedDataSource queries', async () => {
const ds = new MixedDatasource({} as any);
await expect(
ds.query({
targets: [{ refId: 'A', datasource: { uid: MIXED_DATASOURCE_NAME, id: 'datasource' } }],
} as any)
).toEmitValuesWith((results) => {
expect(results).toHaveLength(1);
expect(results[0].data).toHaveLength(0);
});
});
});

View File

@ -26,7 +26,7 @@ export class MixedDatasource extends DataSourceApi<DataQuery> {
query(request: DataQueryRequest<DataQuery>): Observable<DataQueryResponse> {
// Remove any invalid queries
const queries = request.targets.filter((t) => {
return t.datasource?.type !== MIXED_DATASOURCE_NAME;
return t.datasource?.uid !== MIXED_DATASOURCE_NAME;
});
if (!queries.length) {