mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Clean up query subscriptions when a query is canceled (#70235)
* Ensure clean up functions are called when query subscriptions are canceled * Fix unit tests
This commit is contained in:
parent
d00f455f2d
commit
cb2cc591da
@ -4,6 +4,7 @@ import { thunkTester } from 'test/core/thunk/thunkTester';
|
|||||||
import { assertIsDefined } from 'test/helpers/asserts';
|
import { assertIsDefined } from 'test/helpers/asserts';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
DataQueryRequest,
|
||||||
DataQueryResponse,
|
DataQueryResponse,
|
||||||
DataSourceApi,
|
DataSourceApi,
|
||||||
DataSourceJsonData,
|
DataSourceJsonData,
|
||||||
@ -52,6 +53,7 @@ import { makeExplorePaneState } from './utils';
|
|||||||
const { testRange, defaultInitialState } = createDefaultInitialState();
|
const { testRange, defaultInitialState } = createDefaultInitialState();
|
||||||
|
|
||||||
const exploreId = 'left';
|
const exploreId = 'left';
|
||||||
|
const cleanUpMock = jest.fn();
|
||||||
const datasources: DataSourceApi[] = [
|
const datasources: DataSourceApi[] = [
|
||||||
{
|
{
|
||||||
name: 'testDs',
|
name: 'testDs',
|
||||||
@ -769,6 +771,39 @@ describe('reducer', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when data source does not support log volume supplementary query', () => {
|
||||||
|
it('cleans up query subscription correctly (regression #70049)', async () => {
|
||||||
|
const store: { dispatch: ThunkDispatch; getState: () => StoreState } = configureStore({
|
||||||
|
...defaultInitialState,
|
||||||
|
explore: {
|
||||||
|
panes: {
|
||||||
|
left: {
|
||||||
|
...defaultInitialState.explore.panes.left,
|
||||||
|
datasourceInstance: {
|
||||||
|
getRef: jest.fn(),
|
||||||
|
meta: {
|
||||||
|
id: 'something',
|
||||||
|
},
|
||||||
|
query(
|
||||||
|
request: DataQueryRequest<DataQuery>
|
||||||
|
): Promise<DataQueryResponse> | Observable<DataQueryResponse> {
|
||||||
|
return new Observable(() => cleanUpMock);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as unknown as Partial<StoreState>);
|
||||||
|
|
||||||
|
const dispatch = store.dispatch;
|
||||||
|
|
||||||
|
cleanUpMock.mockClear();
|
||||||
|
await dispatch(runQueries({ exploreId: 'left' }));
|
||||||
|
await dispatch(cancelQueries('left'));
|
||||||
|
expect(cleanUpMock).toBeCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('supplementary queries', () => {
|
describe('supplementary queries', () => {
|
||||||
let dispatch: ThunkDispatch,
|
let dispatch: ThunkDispatch,
|
||||||
getState: () => StoreState,
|
getState: () => StoreState,
|
||||||
|
@ -58,7 +58,7 @@ const createFallbackLogVolumeProvider = (
|
|||||||
datasourceName: string
|
datasourceName: string
|
||||||
): Observable<DataQueryResponse> => {
|
): Observable<DataQueryResponse> => {
|
||||||
return new Observable<DataQueryResponse>((observer) => {
|
return new Observable<DataQueryResponse>((observer) => {
|
||||||
explorePanelData.subscribe((exploreData) => {
|
return explorePanelData.subscribe((exploreData) => {
|
||||||
if (
|
if (
|
||||||
exploreData.logsResult &&
|
exploreData.logsResult &&
|
||||||
exploreData.logsResult.rows &&
|
exploreData.logsResult.rows &&
|
||||||
|
Loading…
Reference in New Issue
Block a user