2022-01-05 12:34:09 -06:00
|
|
|
import { EMPTY, interval, Observable, of } from 'rxjs';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { thunkTester } from 'test/core/thunk/thunkTester';
|
2022-06-21 07:47:33 -05:00
|
|
|
import { assertIsDefined } from 'test/helpers/asserts';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-05-24 06:56:48 -05:00
|
|
|
import {
|
|
|
|
ArrayVector,
|
2021-09-07 03:44:47 -05:00
|
|
|
DataFrame,
|
|
|
|
DataQuery,
|
2021-05-24 06:56:48 -05:00
|
|
|
DataQueryResponse,
|
2021-09-07 03:44:47 -05:00
|
|
|
DataSourceApi,
|
|
|
|
DataSourceJsonData,
|
2022-02-18 05:05:29 -06:00
|
|
|
DataSourceWithLogsVolumeSupport,
|
2021-09-07 03:44:47 -05:00
|
|
|
LoadingState,
|
2021-05-24 06:56:48 -05:00
|
|
|
MutableDataFrame,
|
2021-09-07 03:44:47 -05:00
|
|
|
PanelData,
|
2021-05-24 06:56:48 -05:00
|
|
|
RawTimeRange,
|
|
|
|
} from '@grafana/data';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { ExploreId, ExploreItemState, StoreState, ThunkDispatch } from 'app/types';
|
|
|
|
|
2020-11-09 07:48:24 -06:00
|
|
|
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
2021-02-10 08:23:19 -06:00
|
|
|
import { configureStore } from '../../../store/configureStore';
|
|
|
|
import { setTimeSrv } from '../../dashboard/services/TimeSrv';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2022-03-29 08:10:40 -05:00
|
|
|
import { createDefaultInitialState } from './helpers';
|
2022-04-22 08:33:13 -05:00
|
|
|
import {
|
|
|
|
addQueryRowAction,
|
|
|
|
addResultsToCache,
|
|
|
|
cancelQueries,
|
|
|
|
cancelQueriesAction,
|
|
|
|
cleanLogsVolumeAction,
|
|
|
|
clearCache,
|
|
|
|
importQueries,
|
|
|
|
queryReducer,
|
|
|
|
runQueries,
|
|
|
|
scanStartAction,
|
|
|
|
scanStopAction,
|
|
|
|
storeLogsVolumeDataProviderAction,
|
|
|
|
} from './query';
|
|
|
|
import { makeExplorePaneState } from './utils';
|
|
|
|
|
2022-03-29 08:10:40 -05:00
|
|
|
const { testRange, defaultInitialState } = createDefaultInitialState();
|
|
|
|
|
|
|
|
jest.mock('app/features/dashboard/services/TimeSrv', () => ({
|
|
|
|
...jest.requireActual('app/features/dashboard/services/TimeSrv'),
|
|
|
|
getTimeSrv: () => ({
|
|
|
|
init: jest.fn(),
|
|
|
|
timeRange: jest.fn().mockReturnValue({}),
|
|
|
|
}),
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock('@grafana/runtime', () => ({
|
|
|
|
...(jest.requireActual('@grafana/runtime') as unknown as object),
|
|
|
|
getTemplateSrv: () => ({
|
|
|
|
updateTimeRange: jest.fn(),
|
|
|
|
}),
|
|
|
|
}));
|
2021-02-10 08:23:19 -06:00
|
|
|
|
2021-09-30 08:46:11 -05:00
|
|
|
function setupQueryResponse(state: StoreState) {
|
2022-06-21 07:47:33 -05:00
|
|
|
const leftDatasourceInstance = assertIsDefined(state.explore[ExploreId.left].datasourceInstance);
|
|
|
|
|
|
|
|
jest.mocked(leftDatasourceInstance.query).mockReturnValueOnce(
|
2021-09-30 08:46:11 -05:00
|
|
|
of({
|
|
|
|
error: { message: 'test error' },
|
|
|
|
data: [
|
|
|
|
new MutableDataFrame({
|
|
|
|
fields: [{ name: 'test', values: new ArrayVector() }],
|
|
|
|
meta: {
|
|
|
|
preferredVisualisationType: 'graph',
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
} as DataQueryResponse)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-10 08:23:19 -06:00
|
|
|
describe('runQueries', () => {
|
|
|
|
it('should pass dataFrames to state even if there is error in response', async () => {
|
2022-01-05 12:34:09 -06:00
|
|
|
setTimeSrv({ init() {} } as any);
|
|
|
|
const { dispatch, getState } = configureStore({
|
2021-02-10 08:23:19 -06:00
|
|
|
...(defaultInitialState as any),
|
|
|
|
});
|
2021-09-30 08:46:11 -05:00
|
|
|
setupQueryResponse(getState());
|
2021-09-07 03:44:47 -05:00
|
|
|
await dispatch(runQueries(ExploreId.left));
|
|
|
|
expect(getState().explore[ExploreId.left].showMetrics).toBeTruthy();
|
|
|
|
expect(getState().explore[ExploreId.left].graphResult).toBeDefined();
|
2021-02-10 08:23:19 -06:00
|
|
|
});
|
2022-01-05 12:34:09 -06:00
|
|
|
|
2022-02-18 05:05:29 -06:00
|
|
|
it('should modify the request-id for log-volume queries', async () => {
|
|
|
|
setTimeSrv({ init() {} } as any);
|
|
|
|
const { dispatch, getState } = configureStore({
|
|
|
|
...(defaultInitialState as any),
|
|
|
|
});
|
|
|
|
setupQueryResponse(getState());
|
|
|
|
await dispatch(runQueries(ExploreId.left));
|
|
|
|
|
|
|
|
const state = getState().explore[ExploreId.left];
|
|
|
|
expect(state.queryResponse.request?.requestId).toBe('explore_left');
|
|
|
|
const datasource = state.datasourceInstance as any as DataSourceWithLogsVolumeSupport<DataQuery>;
|
|
|
|
expect(datasource.getLogsVolumeDataProvider).toBeCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
requestId: 'explore_left_log_volume',
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-01-05 12:34:09 -06:00
|
|
|
it('should set state to done if query completes without emitting', async () => {
|
|
|
|
setTimeSrv({ init() {} } as any);
|
|
|
|
const { dispatch, getState } = configureStore({
|
|
|
|
...(defaultInitialState as any),
|
|
|
|
});
|
2022-06-21 07:47:33 -05:00
|
|
|
const leftDatasourceInstance = assertIsDefined(getState().explore[ExploreId.left].datasourceInstance);
|
|
|
|
jest.mocked(leftDatasourceInstance.query).mockReturnValueOnce(EMPTY);
|
2022-01-05 12:34:09 -06:00
|
|
|
await dispatch(runQueries(ExploreId.left));
|
|
|
|
await new Promise((resolve) => setTimeout(() => resolve(''), 500));
|
|
|
|
expect(getState().explore[ExploreId.left].queryResponse.state).toBe(LoadingState.Done);
|
|
|
|
});
|
2021-02-10 08:23:19 -06:00
|
|
|
});
|
2020-11-09 07:48:24 -06:00
|
|
|
|
|
|
|
describe('running queries', () => {
|
|
|
|
it('should cancel running query when cancelQueries is dispatched', async () => {
|
|
|
|
const unsubscribable = interval(1000);
|
|
|
|
unsubscribable.subscribe();
|
|
|
|
const exploreId = ExploreId.left;
|
|
|
|
const initialState = {
|
|
|
|
explore: {
|
|
|
|
[exploreId]: {
|
2020-11-19 04:33:52 -06:00
|
|
|
datasourceInstance: { name: 'testDs' },
|
2020-11-09 07:48:24 -06:00
|
|
|
initialized: true,
|
|
|
|
loading: true,
|
|
|
|
querySubscription: unsubscribable,
|
|
|
|
queries: ['A'],
|
|
|
|
range: testRange,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
user: {
|
|
|
|
orgId: 'A',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const dispatchedActions = await thunkTester(initialState)
|
|
|
|
.givenThunk(cancelQueries)
|
|
|
|
.whenThunkIsDispatched(exploreId);
|
|
|
|
|
2021-11-24 08:34:19 -06:00
|
|
|
expect(dispatchedActions).toEqual([
|
|
|
|
scanStopAction({ exploreId }),
|
|
|
|
cancelQueriesAction({ exploreId }),
|
|
|
|
storeLogsVolumeDataProviderAction({ exploreId, logsVolumeDataProvider: undefined }),
|
|
|
|
cleanLogsVolumeAction({ exploreId }),
|
|
|
|
]);
|
2020-11-09 07:48:24 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-06-28 09:12:46 -05:00
|
|
|
describe('importing queries', () => {
|
|
|
|
describe('when importing queries between the same type of data source', () => {
|
|
|
|
it('remove datasource property from all of the queries', async () => {
|
2021-09-07 03:44:47 -05:00
|
|
|
const { dispatch, getState }: { dispatch: ThunkDispatch; getState: () => StoreState } = configureStore({
|
2021-06-28 09:12:46 -05:00
|
|
|
...(defaultInitialState as any),
|
|
|
|
explore: {
|
|
|
|
[ExploreId.left]: {
|
|
|
|
...defaultInitialState.explore[ExploreId.left],
|
|
|
|
datasourceInstance: { name: 'testDs', type: 'postgres' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-09-07 03:44:47 -05:00
|
|
|
await dispatch(
|
2021-06-28 09:12:46 -05:00
|
|
|
importQueries(
|
|
|
|
ExploreId.left,
|
|
|
|
[
|
2021-10-29 12:57:24 -05:00
|
|
|
{ datasource: { type: 'postgresql' }, refId: 'refId_A' },
|
|
|
|
{ datasource: { type: 'postgresql' }, refId: 'refId_B' },
|
2021-06-28 09:12:46 -05:00
|
|
|
],
|
|
|
|
{ name: 'Postgres1', type: 'postgres' } as DataSourceApi<DataQuery, DataSourceJsonData, {}>,
|
|
|
|
{ name: 'Postgres2', type: 'postgres' } as DataSourceApi<DataQuery, DataSourceJsonData, {}>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2021-09-07 03:44:47 -05:00
|
|
|
expect(getState().explore[ExploreId.left].queries[0]).toHaveProperty('refId', 'refId_A');
|
|
|
|
expect(getState().explore[ExploreId.left].queries[1]).toHaveProperty('refId', 'refId_B');
|
|
|
|
expect(getState().explore[ExploreId.left].queries[0]).not.toHaveProperty('datasource');
|
|
|
|
expect(getState().explore[ExploreId.left].queries[1]).not.toHaveProperty('datasource');
|
2021-06-28 09:12:46 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-09 07:48:24 -06:00
|
|
|
describe('reducer', () => {
|
|
|
|
describe('scanning', () => {
|
|
|
|
it('should start scanning', () => {
|
2021-03-19 07:10:03 -05:00
|
|
|
const initialState: ExploreItemState = {
|
2020-11-09 07:48:24 -06:00
|
|
|
...makeExplorePaneState(),
|
|
|
|
scanning: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
reducerTester<ExploreItemState>()
|
|
|
|
.givenReducer(queryReducer, initialState)
|
|
|
|
.whenActionIsDispatched(scanStartAction({ exploreId: ExploreId.left }))
|
|
|
|
.thenStateShouldEqual({
|
2021-01-07 04:26:56 -06:00
|
|
|
...initialState,
|
2020-11-09 07:48:24 -06:00
|
|
|
scanning: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
it('should stop scanning', () => {
|
|
|
|
const initialState = {
|
|
|
|
...makeExplorePaneState(),
|
|
|
|
scanning: true,
|
|
|
|
scanRange: {} as RawTimeRange,
|
|
|
|
};
|
|
|
|
|
|
|
|
reducerTester<ExploreItemState>()
|
|
|
|
.givenReducer(queryReducer, initialState)
|
|
|
|
.whenActionIsDispatched(scanStopAction({ exploreId: ExploreId.left }))
|
|
|
|
.thenStateShouldEqual({
|
2021-01-07 04:26:56 -06:00
|
|
|
...initialState,
|
2020-11-09 07:48:24 -06:00
|
|
|
scanning: false,
|
|
|
|
scanRange: undefined,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('query rows', () => {
|
|
|
|
it('adds a new query row', () => {
|
|
|
|
reducerTester<ExploreItemState>()
|
2022-02-02 06:02:32 -06:00
|
|
|
.givenReducer(queryReducer, {
|
2020-11-09 07:48:24 -06:00
|
|
|
queries: [],
|
2022-02-02 06:02:32 -06:00
|
|
|
} as unknown as ExploreItemState)
|
2020-11-09 07:48:24 -06:00
|
|
|
.whenActionIsDispatched(
|
|
|
|
addQueryRowAction({
|
|
|
|
exploreId: ExploreId.left,
|
|
|
|
query: { refId: 'A', key: 'mockKey' },
|
|
|
|
index: 0,
|
|
|
|
})
|
|
|
|
)
|
2022-02-02 06:02:32 -06:00
|
|
|
.thenStateShouldEqual({
|
2020-11-09 07:48:24 -06:00
|
|
|
queries: [{ refId: 'A', key: 'mockKey' }],
|
|
|
|
queryKeys: ['mockKey-0'],
|
2022-02-02 06:02:32 -06:00
|
|
|
} as unknown as ExploreItemState);
|
2020-11-09 07:48:24 -06:00
|
|
|
});
|
|
|
|
});
|
2021-05-24 06:56:48 -05:00
|
|
|
|
|
|
|
describe('caching', () => {
|
|
|
|
it('should add response to cache', async () => {
|
2021-09-07 03:44:47 -05:00
|
|
|
const { dispatch, getState }: { dispatch: ThunkDispatch; getState: () => StoreState } = configureStore({
|
2021-05-24 06:56:48 -05:00
|
|
|
...(defaultInitialState as any),
|
|
|
|
explore: {
|
|
|
|
[ExploreId.left]: {
|
|
|
|
...defaultInitialState.explore[ExploreId.left],
|
|
|
|
queryResponse: {
|
|
|
|
series: [{ name: 'test name' }] as DataFrame[],
|
|
|
|
state: LoadingState.Done,
|
|
|
|
} as PanelData,
|
|
|
|
absoluteRange: { from: 1621348027000, to: 1621348050000 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-09-07 03:44:47 -05:00
|
|
|
await dispatch(addResultsToCache(ExploreId.left));
|
2021-05-24 06:56:48 -05:00
|
|
|
|
2021-09-07 03:44:47 -05:00
|
|
|
expect(getState().explore[ExploreId.left].cache).toEqual([
|
2021-05-24 06:56:48 -05:00
|
|
|
{ key: 'from=1621348027000&to=1621348050000', value: { series: [{ name: 'test name' }], state: 'Done' } },
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not add response to cache if response is still loading', async () => {
|
2021-09-07 03:44:47 -05:00
|
|
|
const { dispatch, getState }: { dispatch: ThunkDispatch; getState: () => StoreState } = configureStore({
|
2021-05-24 06:56:48 -05:00
|
|
|
...(defaultInitialState as any),
|
|
|
|
explore: {
|
|
|
|
[ExploreId.left]: {
|
|
|
|
...defaultInitialState.explore[ExploreId.left],
|
|
|
|
queryResponse: { series: [{ name: 'test name' }] as DataFrame[], state: LoadingState.Loading } as PanelData,
|
|
|
|
absoluteRange: { from: 1621348027000, to: 1621348050000 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-09-07 03:44:47 -05:00
|
|
|
await dispatch(addResultsToCache(ExploreId.left));
|
2021-05-24 06:56:48 -05:00
|
|
|
|
2021-09-07 03:44:47 -05:00
|
|
|
expect(getState().explore[ExploreId.left].cache).toEqual([]);
|
2021-05-24 06:56:48 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should not add duplicate response to cache', async () => {
|
2021-09-07 03:44:47 -05:00
|
|
|
const { dispatch, getState }: { dispatch: ThunkDispatch; getState: () => StoreState } = configureStore({
|
2021-05-24 06:56:48 -05:00
|
|
|
...(defaultInitialState as any),
|
|
|
|
explore: {
|
|
|
|
[ExploreId.left]: {
|
|
|
|
...defaultInitialState.explore[ExploreId.left],
|
|
|
|
queryResponse: {
|
|
|
|
series: [{ name: 'test name' }] as DataFrame[],
|
|
|
|
state: LoadingState.Done,
|
|
|
|
} as PanelData,
|
|
|
|
absoluteRange: { from: 1621348027000, to: 1621348050000 },
|
|
|
|
cache: [
|
|
|
|
{
|
|
|
|
key: 'from=1621348027000&to=1621348050000',
|
|
|
|
value: { series: [{ name: 'old test name' }], state: LoadingState.Done },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-09-07 03:44:47 -05:00
|
|
|
await dispatch(addResultsToCache(ExploreId.left));
|
2021-05-24 06:56:48 -05:00
|
|
|
|
2021-09-07 03:44:47 -05:00
|
|
|
expect(getState().explore[ExploreId.left].cache).toHaveLength(1);
|
|
|
|
expect(getState().explore[ExploreId.left].cache).toEqual([
|
2021-05-24 06:56:48 -05:00
|
|
|
{ key: 'from=1621348027000&to=1621348050000', value: { series: [{ name: 'old test name' }], state: 'Done' } },
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should clear cache', async () => {
|
2021-09-07 03:44:47 -05:00
|
|
|
const { dispatch, getState }: { dispatch: ThunkDispatch; getState: () => StoreState } = configureStore({
|
2021-05-24 06:56:48 -05:00
|
|
|
...(defaultInitialState as any),
|
|
|
|
explore: {
|
|
|
|
[ExploreId.left]: {
|
|
|
|
...defaultInitialState.explore[ExploreId.left],
|
|
|
|
cache: [
|
|
|
|
{
|
|
|
|
key: 'from=1621348027000&to=1621348050000',
|
|
|
|
value: { series: [{ name: 'old test name' }], state: 'Done' },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-09-07 03:44:47 -05:00
|
|
|
await dispatch(clearCache(ExploreId.left));
|
2021-05-24 06:56:48 -05:00
|
|
|
|
2021-09-07 03:44:47 -05:00
|
|
|
expect(getState().explore[ExploreId.left].cache).toEqual([]);
|
2021-05-24 06:56:48 -05:00
|
|
|
});
|
|
|
|
});
|
2021-09-30 08:46:11 -05:00
|
|
|
|
2021-11-24 08:34:19 -06:00
|
|
|
describe('log volume', () => {
|
2021-09-30 08:46:11 -05:00
|
|
|
let dispatch: ThunkDispatch,
|
|
|
|
getState: () => StoreState,
|
2021-10-21 08:56:31 -05:00
|
|
|
unsubscribes: Function[],
|
2021-09-30 08:46:11 -05:00
|
|
|
mockLogsVolumeDataProvider: () => Observable<DataQueryResponse>;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-11-24 08:34:19 -06:00
|
|
|
unsubscribes = [];
|
2021-09-30 08:46:11 -05:00
|
|
|
mockLogsVolumeDataProvider = () => {
|
2022-02-02 06:02:32 -06:00
|
|
|
return {
|
2021-11-24 08:34:19 -06:00
|
|
|
subscribe: () => {
|
|
|
|
const unsubscribe = jest.fn();
|
|
|
|
unsubscribes.push(unsubscribe);
|
|
|
|
return {
|
|
|
|
unsubscribe,
|
|
|
|
};
|
|
|
|
},
|
2022-02-02 06:02:32 -06:00
|
|
|
} as unknown as Observable<DataQueryResponse>;
|
2021-09-30 08:46:11 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const store: { dispatch: ThunkDispatch; getState: () => StoreState } = configureStore({
|
|
|
|
...(defaultInitialState as any),
|
|
|
|
explore: {
|
|
|
|
[ExploreId.left]: {
|
|
|
|
...defaultInitialState.explore[ExploreId.left],
|
|
|
|
datasourceInstance: {
|
|
|
|
query: jest.fn(),
|
2021-10-29 12:57:24 -05:00
|
|
|
getRef: jest.fn(),
|
2021-09-30 08:46:11 -05:00
|
|
|
meta: {
|
|
|
|
id: 'something',
|
|
|
|
},
|
|
|
|
getLogsVolumeDataProvider: () => {
|
|
|
|
return mockLogsVolumeDataProvider();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
dispatch = store.dispatch;
|
|
|
|
getState = store.getState;
|
|
|
|
|
|
|
|
setupQueryResponse(getState());
|
2021-10-21 08:56:31 -05:00
|
|
|
});
|
2021-09-30 08:46:11 -05:00
|
|
|
|
2021-11-24 08:34:19 -06:00
|
|
|
it('should cancel any unfinished logs volume queries when a new query is run', async () => {
|
2021-09-30 08:46:11 -05:00
|
|
|
await dispatch(runQueries(ExploreId.left));
|
2021-11-10 04:20:30 -06:00
|
|
|
// first query is run automatically
|
2021-09-30 08:46:11 -05:00
|
|
|
// loading in progress - one subscription created, not cleaned up yet
|
|
|
|
expect(unsubscribes).toHaveLength(1);
|
|
|
|
expect(unsubscribes[0]).not.toBeCalled();
|
|
|
|
|
|
|
|
setupQueryResponse(getState());
|
|
|
|
await dispatch(runQueries(ExploreId.left));
|
2021-11-10 04:20:30 -06:00
|
|
|
// a new query is run while log volume query is not resolve yet...
|
2021-09-30 08:46:11 -05:00
|
|
|
expect(unsubscribes[0]).toBeCalled();
|
2021-11-10 04:20:30 -06:00
|
|
|
// first subscription is cleaned up, a new subscription is created automatically
|
2021-09-30 08:46:11 -05:00
|
|
|
expect(unsubscribes).toHaveLength(2);
|
|
|
|
expect(unsubscribes[1]).not.toBeCalled();
|
|
|
|
});
|
2021-10-21 08:56:31 -05:00
|
|
|
|
2021-11-24 08:34:19 -06:00
|
|
|
it('should cancel log volume query when the main query is canceled', async () => {
|
|
|
|
await dispatch(runQueries(ExploreId.left));
|
|
|
|
expect(unsubscribes).toHaveLength(1);
|
|
|
|
expect(unsubscribes[0]).not.toBeCalled();
|
|
|
|
|
|
|
|
await dispatch(cancelQueries(ExploreId.left));
|
|
|
|
expect(unsubscribes).toHaveLength(1);
|
|
|
|
expect(unsubscribes[0]).toBeCalled();
|
|
|
|
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeData).toBeUndefined();
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeDataProvider).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2021-10-21 08:56:31 -05:00
|
|
|
it('should load logs volume after running the query', async () => {
|
|
|
|
await dispatch(runQueries(ExploreId.left));
|
|
|
|
expect(unsubscribes).toHaveLength(1);
|
|
|
|
});
|
2021-11-24 08:34:19 -06:00
|
|
|
|
|
|
|
it('should clean any incomplete log volume data when main query is canceled', async () => {
|
|
|
|
mockLogsVolumeDataProvider = () => {
|
|
|
|
return of({ state: LoadingState.Loading, error: undefined, data: [] });
|
|
|
|
};
|
|
|
|
await dispatch(runQueries(ExploreId.left));
|
|
|
|
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeData).toBeDefined();
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeData!.state).toBe(LoadingState.Loading);
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeDataProvider).toBeDefined();
|
|
|
|
|
|
|
|
await dispatch(cancelQueries(ExploreId.left));
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeData).toBeUndefined();
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeDataProvider).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('keeps complete log volume data when main query is canceled', async () => {
|
|
|
|
mockLogsVolumeDataProvider = () => {
|
|
|
|
return of(
|
|
|
|
{ state: LoadingState.Loading, error: undefined, data: [] },
|
|
|
|
{ state: LoadingState.Done, error: undefined, data: [{}] }
|
|
|
|
);
|
|
|
|
};
|
|
|
|
await dispatch(runQueries(ExploreId.left));
|
|
|
|
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeData).toBeDefined();
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeData!.state).toBe(LoadingState.Done);
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeDataProvider).toBeDefined();
|
|
|
|
|
|
|
|
await dispatch(cancelQueries(ExploreId.left));
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeData).toBeDefined();
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeData!.state).toBe(LoadingState.Done);
|
|
|
|
expect(getState().explore[ExploreId.left].logsVolumeDataProvider).toBeUndefined();
|
|
|
|
});
|
2021-09-30 08:46:11 -05:00
|
|
|
});
|
2020-11-09 07:48:24 -06:00
|
|
|
});
|