From 08e21f02a10c596bb6489ed7634f82a822a574e8 Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Tue, 19 Sep 2023 14:40:13 +0200 Subject: [PATCH 1/3] Fix 32+ bits lenght number in ResultSummary The driver was only considering the low 32 bits when driver configured for using BigInt or Integer. --- packages/core/src/result-summary.ts | 4 +- packages/core/test/result-summary.test.ts | 205 +++++++++++++++++- .../lib/core/result-summary.ts | 4 +- 3 files changed, 208 insertions(+), 5 deletions(-) diff --git a/packages/core/src/result-summary.ts b/packages/core/src/result-summary.ts index 55e34c874..5f43d1d46 100644 --- a/packages/core/src/result-summary.ts +++ b/packages/core/src/result-summary.ts @@ -644,9 +644,9 @@ class ServerInfo { function intValue (value: NumberOrInteger): number { if (value instanceof Integer) { - return value.toInt() + return value.toNumber() } else if (typeof value === 'bigint') { - return int(value).toInt() + return int(value).toNumber() } else { return value } diff --git a/packages/core/test/result-summary.test.ts b/packages/core/test/result-summary.test.ts index 20b6fd77a..f5ac823cb 100644 --- a/packages/core/test/result-summary.test.ts +++ b/packages/core/test/result-summary.test.ts @@ -17,15 +17,21 @@ * limitations under the License. */ +import { int } from '../src' import { ServerInfo, Notification, NotificationSeverityLevel, NotificationCategory, notificationSeverityLevel, - notificationCategory + notificationCategory, + ProfiledPlan, + QueryStatistics, + Stats } from '../src/result-summary' +import fc from 'fast-check' + describe('ServerInfo', () => { it.each([ [ @@ -158,6 +164,203 @@ describe('notificationCategory', () => { }) }) +describe('ProfilePlan', () => { + describe.each([ + 'dbHits', + 'rows', + 'pageCacheMisses', + 'pageCacheHits', + 'pageCacheHitRatio', + 'time' + ])('.%s', (field: keyof ProfiledPlan) => { + it('should handle return arbitrary integer as it is', () => { + return fc.assert( + fc.property( + fc.integer(), + value => { + const rawProfilePlan = { + [field]: value + } + + const profilePlan = new ProfiledPlan(rawProfilePlan) + + return profilePlan[field] === value + } + ) + ) + }) + + it('should handle Integer with maxSafeInteger', () => { + return fc.assert( + fc.property( + fc.maxSafeInteger().map(value => [int(value), value]), + ([value, expectedValue]) => { + const rawProfilePlan = { + [field]: value + } + + const profilePlan = new ProfiledPlan(rawProfilePlan) + + return profilePlan[field] === expectedValue + } + ) + ) + }) + + it('should handle Integer with arbitrary integer', () => { + return fc.assert( + fc.property( + fc.integer().map(value => [int(value), value]), + ([value, expectedValue]) => { + const rawProfilePlan = { + [field]: value + } + + const profilePlan = new ProfiledPlan(rawProfilePlan) + + return profilePlan[field] === expectedValue + } + ) + ) + }) + + it('should handle BigInt with maxSafeInteger', () => { + return fc.assert( + fc.property( + fc.maxSafeInteger().map(value => [BigInt(value), value]), + ([value, expectedValue]) => { + const rawProfilePlan = { + [field]: value + } + + const profilePlan = new ProfiledPlan(rawProfilePlan) + + return profilePlan[field] === expectedValue + } + ) + ) + }) + + it('should handle Integer with arbitrary integer', () => { + return fc.assert( + fc.property( + fc.integer().map(value => [BigInt(value), value]), + ([value, expectedValue]) => { + const rawProfilePlan = { + [field]: value + } + + const profilePlan = new ProfiledPlan(rawProfilePlan) + + return profilePlan[field] === expectedValue + } + ) + ) + }) + }) +}) + +describe('QueryStatistics', () => { + describe.each([ + 'nodesCreated', + 'nodesDeleted', + 'relationshipsCreated', + 'relationshipsDeleted', + 'propertiesSet', + 'labelsAdded', + 'labelsRemoved', + 'indexesAdded', + 'indexesRemoved', + 'constraintsAdded', + 'constraintsRemoved' + ])('.%s', (field: keyof Stats) => { + it('should handle return arbitrary integer as it is', () => { + return fc.assert( + fc.property( + fc.integer(), + value => { + const stats = { + [field]: value + } + + const queryStatistics = new QueryStatistics(stats) + + return queryStatistics.updates()[field] === value + } + ) + ) + }) + + it('should handle Integer with maxSafeInteger', () => { + return fc.assert( + fc.property( + fc.maxSafeInteger().map(value => [int(value), value]), + ([value, expectedValue]) => { + const stats = { + [field]: value + } + + const queryStatistics = new QueryStatistics(stats) + + return queryStatistics.updates()[field] === expectedValue + } + ) + ) + }) + + it('should handle Integer with arbitrary integer', () => { + return fc.assert( + fc.property( + fc.integer().map(value => [int(value), value]), + ([value, expectedValue]) => { + const stats = { + [field]: value + } + + const queryStatistics = new QueryStatistics(stats) + + return queryStatistics.updates()[field] === expectedValue + } + ) + ) + }) + + it('should handle BigInt with maxSafeInteger', () => { + return fc.assert( + fc.property( + fc.maxSafeInteger().map(value => [BigInt(value), value]), + ([value, expectedValue]) => { + const stats = { + [field]: value + } + + const queryStatistics = new QueryStatistics(stats) + + return queryStatistics.updates()[field] === expectedValue + } + ) + ) + }) + + it('should handle Integer with arbitrary integer', () => { + return fc.assert( + fc.property( + fc.integer().map(value => [BigInt(value), value]), + ([value, expectedValue]) => { + const stats = { + [field]: value + } + + const queryStatistics = new QueryStatistics(stats) + + return queryStatistics.updates()[field] === expectedValue + } + ) + ) + }) + }) +}) + function getValidSeverityLevels (): NotificationSeverityLevel[] { return [ 'WARNING', diff --git a/packages/neo4j-driver-deno/lib/core/result-summary.ts b/packages/neo4j-driver-deno/lib/core/result-summary.ts index 8dc76506e..58a816d04 100644 --- a/packages/neo4j-driver-deno/lib/core/result-summary.ts +++ b/packages/neo4j-driver-deno/lib/core/result-summary.ts @@ -644,9 +644,9 @@ class ServerInfo { function intValue (value: NumberOrInteger): number { if (value instanceof Integer) { - return value.toInt() + return value.toNumber() } else if (typeof value === 'bigint') { - return int(value).toInt() + return int(value).toNumber() } else { return value } From 22f7f433f1cbe790f6a5aecb8db234d3df1a91ea Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Tue, 19 Sep 2023 15:52:50 +0200 Subject: [PATCH 2/3] Adjust the name test case name --- packages/core/test/result-summary.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/test/result-summary.test.ts b/packages/core/test/result-summary.test.ts index f5ac823cb..b3906aefc 100644 --- a/packages/core/test/result-summary.test.ts +++ b/packages/core/test/result-summary.test.ts @@ -273,7 +273,7 @@ describe('QueryStatistics', () => { 'indexesRemoved', 'constraintsAdded', 'constraintsRemoved' - ])('.%s', (field: keyof Stats) => { + ])('.updates().%s', (field: keyof Stats) => { it('should handle return arbitrary integer as it is', () => { return fc.assert( fc.property( From 99279fa867ec4eb9c989c7d56877a0a33aecd4cc Mon Sep 17 00:00:00 2001 From: Antonio Barcelos Date: Tue, 19 Sep 2023 16:40:17 +0200 Subject: [PATCH 3/3] Some tests improvments --- packages/core/test/result-summary.test.ts | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/core/test/result-summary.test.ts b/packages/core/test/result-summary.test.ts index b3906aefc..43064a532 100644 --- a/packages/core/test/result-summary.test.ts +++ b/packages/core/test/result-summary.test.ts @@ -262,25 +262,25 @@ describe('ProfilePlan', () => { describe('QueryStatistics', () => { describe.each([ - 'nodesCreated', - 'nodesDeleted', - 'relationshipsCreated', - 'relationshipsDeleted', - 'propertiesSet', - 'labelsAdded', - 'labelsRemoved', - 'indexesAdded', - 'indexesRemoved', - 'constraintsAdded', - 'constraintsRemoved' - ])('.updates().%s', (field: keyof Stats) => { + ['nodesCreated', 'nodes-created'], + ['nodesDeleted', 'nodes-deleted'], + ['relationshipsCreated', 'relationships-created'], + ['relationshipsDeleted', 'relationships-deleted'], + ['propertiesSet', 'properties-set'], + ['labelsAdded', 'labels-added'], + ['labelsRemoved', 'labels-removed'], + ['indexesAdded', 'indexes-added'], + ['indexesRemoved', 'indexes-removed'], + ['constraintsAdded', 'constraints-added'], + ['constraintsRemoved', 'constraints-removed'] + ])('.updates().%s', (field: keyof Stats, rawField: string) => { it('should handle return arbitrary integer as it is', () => { return fc.assert( fc.property( fc.integer(), value => { const stats = { - [field]: value + [rawField]: value } const queryStatistics = new QueryStatistics(stats) @@ -297,7 +297,7 @@ describe('QueryStatistics', () => { fc.maxSafeInteger().map(value => [int(value), value]), ([value, expectedValue]) => { const stats = { - [field]: value + [rawField]: value } const queryStatistics = new QueryStatistics(stats) @@ -314,7 +314,7 @@ describe('QueryStatistics', () => { fc.integer().map(value => [int(value), value]), ([value, expectedValue]) => { const stats = { - [field]: value + [rawField]: value } const queryStatistics = new QueryStatistics(stats) @@ -331,7 +331,7 @@ describe('QueryStatistics', () => { fc.maxSafeInteger().map(value => [BigInt(value), value]), ([value, expectedValue]) => { const stats = { - [field]: value + [rawField]: value } const queryStatistics = new QueryStatistics(stats) @@ -348,7 +348,7 @@ describe('QueryStatistics', () => { fc.integer().map(value => [BigInt(value), value]), ([value, expectedValue]) => { const stats = { - [field]: value + [rawField]: value } const queryStatistics = new QueryStatistics(stats)