Skip to content

Commit c21f07b

Browse files
committed
Limit random durations in tests to avoid overflow
1 parent 62800ed commit c21f07b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

test/v1/temporal-types.test.js

+11-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ import _ from 'lodash';
2727
const RANDOM_VALUES_TO_TEST = 2000;
2828
const MIN_TEMPORAL_ARRAY_LENGTH = 20;
2929
const MAX_TEMPORAL_ARRAY_LENGTH = 1000;
30+
/**
31+
* Duration in neo4j is limited to `Long.MAX_VALUE` when converted to seconds.
32+
* This bound should be used for all components of duration, except nanoseconds.
33+
* It's a fairly random large value that allows created duration to not overflow.
34+
* @type {number}
35+
*/
36+
const MAX_DURATION_COMPONENT = 3000000000000;
3037
const MAX_NANO_OF_SECOND = 999999999;
3138
const MAX_YEAR = 999999999;
3239
const MIN_YEAR = -MAX_YEAR;
@@ -993,11 +1000,11 @@ describe('temporal-types', () => {
9931000
}
9941001

9951002
function randomDuration() {
996-
const sign = _.sample([true, false]) ? 1 : -1; // duration can be negative
1003+
const sign = _.sample([-1, 1]); // duration can be negative
9971004
return duration(
998-
sign * _.random(0, Number.MAX_SAFE_INTEGER),
999-
sign * _.random(0, Number.MAX_SAFE_INTEGER),
1000-
sign * _.random(0, Number.MAX_SAFE_INTEGER),
1005+
sign * _.random(0, MAX_DURATION_COMPONENT),
1006+
sign * _.random(0, MAX_DURATION_COMPONENT),
1007+
sign * _.random(0, MAX_DURATION_COMPONENT),
10011008
_.random(0, MAX_NANO_OF_SECOND),
10021009
);
10031010
}

0 commit comments

Comments
 (0)