Skip to content

Commit

Permalink
SQL: [Test] Fix issues with timezone between JDKs (#56493)
Browse files Browse the repository at this point in the history
What basically happens is that the server runs on a java version
where a certain timezone has a set of offset rules, while the test
itself runs on a java version where the same timezone has changed
offset rules (think about a country deciding to use utc+x instead
of utc+y).

With this change the timezone used in testGettingTimeWithoutCalendar
is randomly generated by creating a fixed offset timezone
(ie GMT+X or Z instead of Australia/West timezone) so that the offset
is always fixed, thus avoiding the described issue.

Similar fix to #51592

Fixes: #52650
  • Loading branch information
matriv committed May 12, 2020
1 parent 075287c commit e6cbb42
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -960,10 +960,23 @@ public void testGettingTimeWithoutCalendar() throws Exception {
Long randomLongDate = randomNonNegativeLong();
indexSimpleDocumentWithTrueValues(randomLongDate);

doWithQuery(SELECT_ALL_FIELDS, (results) -> {
/*
* Create simple timezones (in the form of Z/GMT+/-x so that timezones offsets differences between Java versions (the one
* server runs on and the one the test runs on) will not skew the tests' results.
* -18/+18 is the maximum range of offsets accepted by ZoneOffset, even if in reality this range is more like [-12, +14].
*/
int hoursOffset = randomIntBetween(0, 18);
int subHours = hoursOffset != 18 ? randomFrom(0, 15, 30, 45) : 0;
int plusMinus = randomBoolean() ? 1 : -1;
int totalSeconds = (hoursOffset * 3600 + subHours * 60) * plusMinus;

ZoneOffset randomFixedZone = ZoneOffset.ofTotalSeconds(totalSeconds);
String zoneString = (hoursOffset == 0 && subHours == 0) ? "Z" : "GMT" + randomFixedZone.getId();

doWithQueryAndTimezone(SELECT_ALL_FIELDS, zoneString, (results) -> {
results.next();

java.sql.Time expectedTime = asTime(randomLongDate, getZoneFromOffset(randomLongDate));
java.sql.Time expectedTime = asTime(randomLongDate, ZoneId.of(zoneString));

assertEquals(expectedTime, results.getTime("test_date"));
assertEquals(expectedTime, results.getTime(9));
Expand Down

0 comments on commit e6cbb42

Please sign in to comment.