1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00
Files
node-redis/packages/search/lib/commands/PROFILE_SEARCH.spec.ts
Bobby I. 69d507a572 refactor!: redis 8 compatibility improvements and test infrastructure updates (#2893)
* churn(test): use redislabs/client-libs-test for testing

This  switches our testing infrastructure from redis/redis-stack to
redislabs/client-libs-test Docker image across all packages. This change
also updates the default Docker version from 7.4.0-v1 to 8.0-M04-pre.

* churn(test): verify CONFIG SET / GET compatibility with Redis 8

- Add tests for Redis 8 search configuration settings
- Deprecate Redis Search CONFIG commands in favor of standard CONFIG
- Test read-only config restrictions for Redis 8

* churn(test): handle Redis 8 coordinate precision in GEOPOS

- Update GEOPOS tests to handle increased precision in Redis 8 (17 decimal places vs 14)
- Add precision-aware coordinate comparison helper
- Add comprehensive test suite for coordinate comparison function

* test(search): adapt SUGGET tests for Redis 8 empty results

- Update tests to expect empty array ([]) instead of null for SUGGET variants
- Affects sugGet, sugGetWithPayloads, sugGetWithScores, and sugGetWithScoresWithPayloads

* test(search): support Redis 8 INFO indexes_all field

- Add indexes_all field introduced in Redis 8 to index definition test

* refactor!(search): simplify PROFILE commands to return raw response

- BREAKING CHANGE: FT.PROFILE now returns raw response, letting users implement their own parsing

* test: improve version-specific test coverage

- Add `testWithClientIfVersionWithinRange` method to run tests for specific Redis versions
- Refactor TestUtils to handle version comparisons more accurately
- Update test utilities across Redis modules to run tests against multiple versions, and not against latest only
2025-02-27 10:56:58 +02:00

96 lines
3.2 KiB
TypeScript

import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import PROFILE_SEARCH from './PROFILE_SEARCH';
import { SCHEMA_FIELD_TYPE } from './CREATE';
import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
import { DEFAULT_DIALECT } from '../dialect/default';
describe('PROFILE SEARCH', () => {
describe('transformArguments', () => {
it('without options', () => {
assert.deepEqual(
parseArgs(PROFILE_SEARCH, 'index', 'query'),
['FT.PROFILE', 'index', 'SEARCH', 'QUERY', 'query', 'DIALECT', DEFAULT_DIALECT]
);
});
it('with options', () => {
assert.deepEqual(
parseArgs(PROFILE_SEARCH, 'index', 'query', {
LIMITED: true,
VERBATIM: true,
INKEYS: 'key'
}),
['FT.PROFILE', 'index', 'SEARCH', 'LIMITED', 'QUERY', 'query',
'VERBATIM', 'INKEYS', '1', 'key', 'DIALECT', DEFAULT_DIALECT]
);
});
});
testUtils.testWithClientIfVersionWithinRange([[8], 'LATEST'], 'client.ft.search', async client => {
await Promise.all([
client.ft.create('index', {
field: SCHEMA_FIELD_TYPE.NUMERIC
}),
client.hSet('1', 'field', '1')
]);
const normalizeObject = obj => JSON.parse(JSON.stringify(obj));
const res = await client.ft.profileSearch('index', '*');
const normalizedRes = normalizeObject(res);
assert.equal(normalizedRes.results.total, 1);
assert.ok(normalizedRes.profile[0] === 'Shards');
assert.ok(Array.isArray(normalizedRes.profile[1]));
assert.ok(normalizedRes.profile[2] === 'Coordinator');
assert.ok(Array.isArray(normalizedRes.profile[3]));
const shardProfile = normalizedRes.profile[1][0];
assert.ok(shardProfile.includes('Total profile time'));
assert.ok(shardProfile.includes('Parsing time'));
assert.ok(shardProfile.includes('Pipeline creation time'));
assert.ok(shardProfile.includes('Warning'));
assert.ok(shardProfile.includes('Iterators profile'));
;
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClientIfVersionWithinRange([[7, 2, 0], [7, 4, 0]], 'client.ft.search', async client => {
await Promise.all([
client.ft.create('index', {
field: SCHEMA_FIELD_TYPE.NUMERIC
}),
client.hSet('1', 'field', '1')
]);
const normalizeObject = obj => JSON.parse(JSON.stringify(obj));
const res = await client.ft.profileSearch('index', '*');
const normalizedRes = normalizeObject(res);
assert.equal(normalizedRes.results.total, 1);
assert.ok(Array.isArray(normalizedRes.profile));
assert.equal(normalizedRes.profile[0][0], 'Total profile time');
assert.equal(normalizedRes.profile[1][0], 'Parsing time');
assert.equal(normalizedRes.profile[2][0], 'Pipeline creation time');
assert.equal(normalizedRes.profile[3][0], 'Warning');
assert.equal(normalizedRes.profile[4][0], 'Iterators profile');
assert.equal(normalizedRes.profile[5][0], 'Result processors profile');
const iteratorsProfile = normalizedRes.profile[4][1];
assert.equal(iteratorsProfile[0], 'Type');
assert.equal(iteratorsProfile[1], 'WILDCARD');
assert.equal(iteratorsProfile[2], 'Time');
assert.equal(iteratorsProfile[4], 'Counter');
}, GLOBAL.SERVERS.OPEN);
});