Skip to content

SQL: improve timezone sensitive JDBC tests to account for offset differences #51592

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 2 commits into from
Jan 29, 2020

Conversation

astefan
Copy link
Contributor

@astefan astefan commented Jan 29, 2020

Original PR: #51290
Based on the discussion here decision has been made to merge this PR in 6.8 only.

This PR addresses CI failures reported in #45035 and #48234, but also other even more rare CI failures looking like

java.lang.AssertionError: expected: java.sql.Date<�033-11-02> but was: java.sql.Date<�033-11-02>
	at __randomizedtesting.SeedInfo.seed([C0FA1CD0C3242A0C:F993B3EB81DCB7CD]:0)
	at org.junit.Assert.fail(Assert.java:88)
	at org.junit.Assert.failNotEquals(Assert.java:834)
	at org.junit.Assert.assertEquals(Assert.java:118)
	at org.junit.Assert.assertEquals(Assert.java:144)
	at org.elasticsearch.xpack.sql.qa.jdbc.ResultSetTestCase.lambda$testGettingDateWithoutCalendar$134(ResultSetTestCase.java:886)

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).

This PR changed several tests to compare only the relevant parts of the conversion failure error message and ignore the actual datetime String from the error message itself (thus, ignoring the value of the datetime itself that's part of the error message).

Also, there is another change fixing the second issue mentioned above where a timezone in testGettingDateWithoutCalendar 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.

* Changed several tests to compare only the relevant parts of the
conversion failure error message and ignore the actual datetime String
from the error message itself
@astefan astefan added >bug >test Issues or PRs that are addressing/adding tests :Analytics/SQL SQL querying v6.8.7 labels Jan 29, 2020
@astefan astefan requested review from costin, bpintea and matriv January 29, 2020 07:40
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/SQL)

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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
int hoursOffset = randomIntBetween(0, 18);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a comment here, for the 18 (maximum offset)?

int totalSeconds = (hoursOffset * 3600 + subHours * 60) * plusMinus;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: while GMT and UTC are identical in this timezones context, my impression is that there is a shift towards using the UTC for references.

Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@astefan astefan merged commit fe254a2 into elastic:6.8 Jan 29, 2020
@astefan astefan deleted the 45035_fix_6.8 branch January 29, 2020 14:55
matriv added a commit that referenced this pull request May 12, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/SQL SQL querying >bug >test Issues or PRs that are addressing/adding tests v6.8.7
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants