Skip to content

Fix 32+ bits length numbers serialization in ResultSummary #1141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/result-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
205 changes: 204 additions & 1 deletion packages/core/test/result-summary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
[
Expand Down Expand Up @@ -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', '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 = {
[rawField]: 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 = {
[rawField]: 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 = {
[rawField]: 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 = {
[rawField]: 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 = {
[rawField]: value
}

const queryStatistics = new QueryStatistics(stats)

return queryStatistics.updates()[field] === expectedValue
}
)
)
})
})
})

function getValidSeverityLevels (): NotificationSeverityLevel[] {
return [
'WARNING',
Expand Down
4 changes: 2 additions & 2 deletions packages/neo4j-driver-deno/lib/core/result-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down