Skip to content

Commit 83f290e

Browse files
authored
Fix 32+ bits length numbers serialization in ResultSummary (#1141)
The driver was only considering the low 32 bits when driver configured for using BigInt or Integer.
1 parent 48f6af6 commit 83f290e

File tree

3 files changed

+208
-5
lines changed

3 files changed

+208
-5
lines changed

packages/core/src/result-summary.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,9 @@ class ServerInfo {
644644

645645
function intValue (value: NumberOrInteger): number {
646646
if (value instanceof Integer) {
647-
return value.toInt()
647+
return value.toNumber()
648648
} else if (typeof value === 'bigint') {
649-
return int(value).toInt()
649+
return int(value).toNumber()
650650
} else {
651651
return value
652652
}

packages/core/test/result-summary.test.ts

Lines changed: 204 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@
1717
* limitations under the License.
1818
*/
1919

20+
import { int } from '../src'
2021
import {
2122
ServerInfo,
2223
Notification,
2324
NotificationSeverityLevel,
2425
NotificationCategory,
2526
notificationSeverityLevel,
26-
notificationCategory
27+
notificationCategory,
28+
ProfiledPlan,
29+
QueryStatistics,
30+
Stats
2731
} from '../src/result-summary'
2832

33+
import fc from 'fast-check'
34+
2935
describe('ServerInfo', () => {
3036
it.each([
3137
[
@@ -158,6 +164,203 @@ describe('notificationCategory', () => {
158164
})
159165
})
160166

167+
describe('ProfilePlan', () => {
168+
describe.each([
169+
'dbHits',
170+
'rows',
171+
'pageCacheMisses',
172+
'pageCacheHits',
173+
'pageCacheHitRatio',
174+
'time'
175+
])('.%s', (field: keyof ProfiledPlan) => {
176+
it('should handle return arbitrary integer as it is', () => {
177+
return fc.assert(
178+
fc.property(
179+
fc.integer(),
180+
value => {
181+
const rawProfilePlan = {
182+
[field]: value
183+
}
184+
185+
const profilePlan = new ProfiledPlan(rawProfilePlan)
186+
187+
return profilePlan[field] === value
188+
}
189+
)
190+
)
191+
})
192+
193+
it('should handle Integer with maxSafeInteger', () => {
194+
return fc.assert(
195+
fc.property(
196+
fc.maxSafeInteger().map(value => [int(value), value]),
197+
([value, expectedValue]) => {
198+
const rawProfilePlan = {
199+
[field]: value
200+
}
201+
202+
const profilePlan = new ProfiledPlan(rawProfilePlan)
203+
204+
return profilePlan[field] === expectedValue
205+
}
206+
)
207+
)
208+
})
209+
210+
it('should handle Integer with arbitrary integer', () => {
211+
return fc.assert(
212+
fc.property(
213+
fc.integer().map(value => [int(value), value]),
214+
([value, expectedValue]) => {
215+
const rawProfilePlan = {
216+
[field]: value
217+
}
218+
219+
const profilePlan = new ProfiledPlan(rawProfilePlan)
220+
221+
return profilePlan[field] === expectedValue
222+
}
223+
)
224+
)
225+
})
226+
227+
it('should handle BigInt with maxSafeInteger', () => {
228+
return fc.assert(
229+
fc.property(
230+
fc.maxSafeInteger().map(value => [BigInt(value), value]),
231+
([value, expectedValue]) => {
232+
const rawProfilePlan = {
233+
[field]: value
234+
}
235+
236+
const profilePlan = new ProfiledPlan(rawProfilePlan)
237+
238+
return profilePlan[field] === expectedValue
239+
}
240+
)
241+
)
242+
})
243+
244+
it('should handle Integer with arbitrary integer', () => {
245+
return fc.assert(
246+
fc.property(
247+
fc.integer().map(value => [BigInt(value), value]),
248+
([value, expectedValue]) => {
249+
const rawProfilePlan = {
250+
[field]: value
251+
}
252+
253+
const profilePlan = new ProfiledPlan(rawProfilePlan)
254+
255+
return profilePlan[field] === expectedValue
256+
}
257+
)
258+
)
259+
})
260+
})
261+
})
262+
263+
describe('QueryStatistics', () => {
264+
describe.each([
265+
['nodesCreated', 'nodes-created'],
266+
['nodesDeleted', 'nodes-deleted'],
267+
['relationshipsCreated', 'relationships-created'],
268+
['relationshipsDeleted', 'relationships-deleted'],
269+
['propertiesSet', 'properties-set'],
270+
['labelsAdded', 'labels-added'],
271+
['labelsRemoved', 'labels-removed'],
272+
['indexesAdded', 'indexes-added'],
273+
['indexesRemoved', 'indexes-removed'],
274+
['constraintsAdded', 'constraints-added'],
275+
['constraintsRemoved', 'constraints-removed']
276+
])('.updates().%s', (field: keyof Stats, rawField: string) => {
277+
it('should handle return arbitrary integer as it is', () => {
278+
return fc.assert(
279+
fc.property(
280+
fc.integer(),
281+
value => {
282+
const stats = {
283+
[rawField]: value
284+
}
285+
286+
const queryStatistics = new QueryStatistics(stats)
287+
288+
return queryStatistics.updates()[field] === value
289+
}
290+
)
291+
)
292+
})
293+
294+
it('should handle Integer with maxSafeInteger', () => {
295+
return fc.assert(
296+
fc.property(
297+
fc.maxSafeInteger().map(value => [int(value), value]),
298+
([value, expectedValue]) => {
299+
const stats = {
300+
[rawField]: value
301+
}
302+
303+
const queryStatistics = new QueryStatistics(stats)
304+
305+
return queryStatistics.updates()[field] === expectedValue
306+
}
307+
)
308+
)
309+
})
310+
311+
it('should handle Integer with arbitrary integer', () => {
312+
return fc.assert(
313+
fc.property(
314+
fc.integer().map(value => [int(value), value]),
315+
([value, expectedValue]) => {
316+
const stats = {
317+
[rawField]: value
318+
}
319+
320+
const queryStatistics = new QueryStatistics(stats)
321+
322+
return queryStatistics.updates()[field] === expectedValue
323+
}
324+
)
325+
)
326+
})
327+
328+
it('should handle BigInt with maxSafeInteger', () => {
329+
return fc.assert(
330+
fc.property(
331+
fc.maxSafeInteger().map(value => [BigInt(value), value]),
332+
([value, expectedValue]) => {
333+
const stats = {
334+
[rawField]: value
335+
}
336+
337+
const queryStatistics = new QueryStatistics(stats)
338+
339+
return queryStatistics.updates()[field] === expectedValue
340+
}
341+
)
342+
)
343+
})
344+
345+
it('should handle Integer with arbitrary integer', () => {
346+
return fc.assert(
347+
fc.property(
348+
fc.integer().map(value => [BigInt(value), value]),
349+
([value, expectedValue]) => {
350+
const stats = {
351+
[rawField]: value
352+
}
353+
354+
const queryStatistics = new QueryStatistics(stats)
355+
356+
return queryStatistics.updates()[field] === expectedValue
357+
}
358+
)
359+
)
360+
})
361+
})
362+
})
363+
161364
function getValidSeverityLevels (): NotificationSeverityLevel[] {
162365
return [
163366
'WARNING',

packages/neo4j-driver-deno/lib/core/result-summary.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,9 @@ class ServerInfo {
644644

645645
function intValue (value: NumberOrInteger): number {
646646
if (value instanceof Integer) {
647-
return value.toInt()
647+
return value.toNumber()
648648
} else if (typeof value === 'bigint') {
649-
return int(value).toInt()
649+
return int(value).toNumber()
650650
} else {
651651
return value
652652
}

0 commit comments

Comments
 (0)