1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-04 15:02:09 +03:00

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
This commit is contained in:
Bobby I.
2025-02-27 10:56:58 +02:00
committed by GitHub
parent 33cdc00746
commit 69d507a572
28 changed files with 1083 additions and 422 deletions

View File

@@ -19,7 +19,6 @@ describe('CONFIG GET', () => {
);
});
});
testUtils.testWithClient('client.configGet', async client => {
const config = await client.configGet('*');
@@ -29,4 +28,33 @@ describe('CONFIG GET', () => {
assert.equal(typeof value, 'string');
}
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('client.configSet.getSearchConfigSettingTest | Redis >= 8', async client => {
assert.ok(
await client.configGet('search-timeout'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('client.configSet.getTSConfigSettingTest | Redis >= 8', async client => {
assert.ok(
await client.configGet('ts-retention-policy'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('client.configSet.getBFConfigSettingTest | Redis >= 8', async client => {
assert.ok(
await client.configGet('bf-error-rate'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('client.configSet.getCFConfigSettingTest | Redis >= 8', async client => {
assert.ok(
await client.configGet('cf-initial-size'),
'OK'
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -30,4 +30,13 @@ describe('CONFIG SET', () => {
'OK'
);
}, GLOBAL.SERVERS.OPEN);
testUtils.testWithClient('client.configSet.setReadOnlySearchConfigTest | Redis >= 8',
async client => {
assert.rejects(
client.configSet('search-max-doctablesize', '0'),
new Error('ERR CONFIG SET failed (possibly related to argument \'search-max-doctablesize\') - can\'t set immutable config')
);
}, GLOBAL.SERVERS.OPEN);
});

View File

@@ -1,4 +1,4 @@
import { strict as assert } from 'node:assert';
import { strict as assert, fail } from 'node:assert';
import testUtils, { GLOBAL } from '../test-utils';
import GEOPOS from './GEOPOS';
import { parseArgs } from './generic-transformers';
@@ -41,12 +41,126 @@ describe('GEOPOS', () => {
...coordinates
});
assert.deepEqual(
await client.geoPos('key', 'member'),
[coordinates]
);
const result = await client.geoPos('key', 'member');
/**
* - Redis < 8: Returns coordinates with 14 decimal places (e.g., "-122.06429868936539")
* - Redis 8+: Returns coordinates with 17 decimal places (e.g., "-122.06429868936538696")
*
*/
const PRECISION = 13; // Number of decimal places to compare
if (result && result.length === 1 && result[0] != null) {
const { longitude, latitude } = result[0];
assert.ok(
compareWithPrecision(longitude, coordinates.longitude, PRECISION),
`Longitude mismatch: ${longitude} vs ${coordinates.longitude}`
);
assert.ok(
compareWithPrecision(latitude, coordinates.latitude, PRECISION),
`Latitude mismatch: ${latitude} vs ${coordinates.latitude}`
);
} else {
assert.fail('Expected a valid result');
}
}, {
client: GLOBAL.SERVERS.OPEN,
cluster: GLOBAL.CLUSTERS.OPEN
});
});
describe('compareWithPrecision', () => {
it('should match exact same numbers', () => {
assert.strictEqual(
compareWithPrecision('123.456789', '123.456789', 6),
true
);
});
it('should match when actual has more precision than needed', () => {
assert.strictEqual(
compareWithPrecision('123.456789123456', '123.456789', 6),
true
);
});
it('should match when expected has more precision than needed', () => {
assert.strictEqual(
compareWithPrecision('123.456789', '123.456789123456', 6),
true
);
});
it('should fail when decimals differ within precision', () => {
assert.strictEqual(
compareWithPrecision('123.456689', '123.456789', 6),
false
);
});
it('should handle negative numbers', () => {
assert.strictEqual(
compareWithPrecision('-122.06429868936538', '-122.06429868936539', 13),
true
);
});
it('should fail when integer parts differ', () => {
assert.strictEqual(
compareWithPrecision('124.456789', '123.456789', 6),
false
);
});
it('should handle zero decimal places', () => {
assert.strictEqual(
compareWithPrecision('123.456789', '123.456789', 0),
true
);
});
it('should handle numbers without decimal points', () => {
assert.strictEqual(
compareWithPrecision('123', '123', 6),
true
);
});
it('should handle one number without decimal point', () => {
assert.strictEqual(
compareWithPrecision('123', '123.000', 3),
true
);
});
it('should match Redis coordinates with different precision', () => {
assert.strictEqual(
compareWithPrecision(
'-122.06429868936538696',
'-122.06429868936539',
13
),
true
);
});
it('should match Redis latitude with different precision', () => {
assert.strictEqual(
compareWithPrecision(
'37.37749628831998194',
'37.37749628831998',
14
),
true
);
});
});
export const compareWithPrecision = (actual: string, expected: string, decimals: number): boolean => {
return Math.abs(Number(actual) - Number(expected)) < Math.pow(10, -decimals);
};