grafana/public/app/features/plugins/sql/ResponseParser.test.ts
Kyle Cunningham bf687fff45
SQL Datasources: Prevent Call Stack Overflows with Large Numbers of Values for Variable (#64937)
* Push values with every map call to avoid hitting the maximum call stack size.

* Add test and refactor to for of

* Use native fill instead of lodash

---------

Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
2023-03-22 14:50:54 +01:00

24 lines
768 B
TypeScript

import { DataFrameDTO, FieldType, MutableDataFrame } from '@grafana/data';
import { ResponseParser } from './ResponseParser';
describe('transformMetricFindResponse function', () => {
it('should handle big arrays', () => {
const responseParser = new ResponseParser();
const stringValues = new Array(150_000).fill('a');
const numberValues = new Array(150_000).fill(1);
const frame: DataFrameDTO = {
fields: [
{ name: 'name', type: FieldType.string, values: stringValues },
{ name: 'value', type: FieldType.number, values: numberValues },
],
};
const dataFrame = new MutableDataFrame(frame);
const result = responseParser.transformMetricFindResponse(dataFrame);
expect(result).toHaveLength(2);
});
});