Skip to content

Commit 2712db5

Browse files
committed
Fix temporal ITs to only generate DST-safe time
Randomized tests for `DateTime` Cypher type generate random date-time values with time zone (either offset or id). They used to be flaky because sometimes generated instant was invalid. Such instant pointed to a non-existing time during a Daylight Saving Time adjustment/jump. Such time values are adjusted to the nearest valid value by the database. This made tests fail because received value was different from the sent value. This commit fixes the problem by making random `DateTime` generator never generate hour of the day that is in the DST adjustment range. It also reduces the number of test time zones to couple popular ones. This is done to make sure all tested time zones are supported by the JVM, neo4j database is running on.
1 parent 0238704 commit 2712db5

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

test/v1/temporal-types.test.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,7 @@ const MIN_TIME_ZONE_OFFSET = -MAX_TIME_ZONE_OFFSET;
3232
const SECONDS_PER_MINUTE = 60;
3333
const MIN_ZONE_ID = 'Etc/GMT+12';
3434
const MAX_ZONE_ID = 'Etc/GMT-14';
35-
const ZONE_IDS = ['Europe/Zaporozhye', 'America/Argentina/Mendoza', 'Etc/GMT-12', 'Asia/Jayapura', 'Pacific/Auckland', 'America/Argentina/Rio_Gallegos',
36-
'America/Tegucigalpa', 'Europe/Skopje', 'Africa/Lome', 'America/Eirunepe', 'Pacific/Port_Moresby', 'America/Merida', 'Asia/Qyzylorda', 'Hongkong',
37-
'America/Paramaribo', 'Pacific/Wallis', 'Antarctica/Mawson', 'America/Metlakatla', 'Indian/Reunion', 'Asia/Chungking', 'Canada/Central', 'Etc/GMT-6',
38-
'UCT', 'America/Belem', 'Europe/Belgrade', 'Singapore', 'Israel', 'Europe/London', 'America/Yellowknife', 'Europe/Uzhgorod', 'Etc/GMT+7',
39-
'America/Indiana/Winamac', 'Asia/Kuala_Lumpur', 'America/Cuiaba', 'Europe/Sofia', 'Asia/Kuching', 'Australia/Lord_Howe', 'America/Porto_Acre',
40-
'America/Indiana/Indianapolis', 'Africa/Windhoek', 'Atlantic/Cape_Verde', 'Asia/Kuwait', 'America/Barbados', 'Egypt', 'GB-Eire', 'Antarctica/South_Pole',
41-
'America/Kentucky/Louisville', 'Asia/Yangon', 'CET', 'Etc/GMT+11', 'Asia/Dubai', 'Europe/Stockholm'];
35+
const ZONE_IDS = ['Europe/Zaporozhye', 'Europe/London', 'UTC', 'Africa/Cairo'];
4236

4337
describe('temporal-types', () => {
4438

@@ -434,18 +428,22 @@ describe('temporal-types', () => {
434428

435429
function randomDateTimeWithZoneOffset() {
436430
return new neo4j.DateTimeWithZoneOffset(
437-
randomLocalDateTime(),
431+
randomDstSafeLocalDateTime(),
438432
randomZoneOffsetSeconds()
439433
);
440434
}
441435

442436
function randomDateTimeWithZoneId() {
443437
return new neo4j.DateTimeWithZoneId(
444-
randomLocalDateTime(),
438+
randomDstSafeLocalDateTime(),
445439
randomZoneId()
446440
);
447441
}
448442

443+
function randomDstSafeLocalDateTime() {
444+
return new neo4j.LocalDateTime(randomDate(), randomDstSafeLocalTime());
445+
}
446+
449447
function randomLocalDateTime() {
450448
return new neo4j.LocalDateTime(randomDate(), randomLocalTime());
451449
}
@@ -474,6 +472,15 @@ describe('temporal-types', () => {
474472
);
475473
}
476474

475+
function randomDstSafeLocalTime() {
476+
return new neo4j.LocalTime(
477+
randomInt(4, 23), // do not generate hours in range where DST adjustment happens
478+
randomInt(0, 59),
479+
randomInt(0, 59),
480+
randomInt(0, MAX_NANO_OF_SECOND)
481+
);
482+
}
483+
477484
function randomZoneOffsetSeconds() {
478485
const randomOffsetWithSeconds = neo4j.int(randomInt(MIN_TIME_ZONE_OFFSET, MAX_TIME_ZONE_OFFSET));
479486
return randomOffsetWithSeconds.div(SECONDS_PER_MINUTE).multiply(SECONDS_PER_MINUTE); // truncate seconds

0 commit comments

Comments
 (0)