mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Fix intermittent time-related test failure in explore datasource instance update (#30109)
* Chore: Ensure base time is the same when calculating default time range * Chore: Fix intermittent test failure due to timing
This commit is contained in:
parent
1c808be0f3
commit
7b5a9cefc1
@ -43,9 +43,11 @@ export type TimeFragment = string | DateTime;
|
|||||||
export const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
|
export const TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
|
||||||
|
|
||||||
export function getDefaultTimeRange(): TimeRange {
|
export function getDefaultTimeRange(): TimeRange {
|
||||||
|
const now = dateTime();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
from: dateTime().subtract(6, 'hour'),
|
from: dateTime(now).subtract(6, 'hour'),
|
||||||
to: dateTime(),
|
to: now,
|
||||||
raw: { from: 'now-6h', to: 'now' },
|
raw: { from: 'now-6h', to: 'now' },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,13 @@ describe('Datasource reducer', () => {
|
|||||||
queries,
|
queries,
|
||||||
queryKeys,
|
queryKeys,
|
||||||
} as unknown) as ExploreItemState;
|
} as unknown) as ExploreItemState;
|
||||||
const expectedState: any = {
|
|
||||||
|
const result = datasourceReducer(
|
||||||
|
initialState,
|
||||||
|
updateDatasourceInstanceAction({ exploreId: ExploreId.left, datasourceInstance, history: [] })
|
||||||
|
);
|
||||||
|
|
||||||
|
const expectedState: Partial<ExploreItemState> = {
|
||||||
datasourceInstance,
|
datasourceInstance,
|
||||||
queries,
|
queries,
|
||||||
queryKeys,
|
queryKeys,
|
||||||
@ -31,13 +37,14 @@ describe('Datasource reducer', () => {
|
|||||||
tableResult: null,
|
tableResult: null,
|
||||||
latency: 0,
|
latency: 0,
|
||||||
loading: false,
|
loading: false,
|
||||||
queryResponse: createEmptyQueryResponse(),
|
queryResponse: {
|
||||||
|
// When creating an empty query response we also create a timeRange object with the current time.
|
||||||
|
// Copying the range from the reducer here prevents intermittent failures when creating them at different times.
|
||||||
|
...createEmptyQueryResponse(),
|
||||||
|
timeRange: result.queryResponse.timeRange,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = datasourceReducer(
|
|
||||||
initialState,
|
|
||||||
updateDatasourceInstanceAction({ exploreId: ExploreId.left, datasourceInstance, history: [] })
|
|
||||||
);
|
|
||||||
expect(result).toMatchObject(expectedState);
|
expect(result).toMatchObject(expectedState);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user