jamesfredley commented on code in PR #15612:
URL: https://github.com/apache/grails-core/pull/15612#discussion_r3176534325
##########
grails-gsp/plugin/src/test/groovy/org/grails/web/taglib/FormTagLib2Tests.groovy:
##########
@@ -171,32 +171,39 @@ class FormTagLib2Tests extends AbstractGrailsTagTests {
}
private void testDatePickerTag(Object date, String precision) {
- Document document = getDatePickerOutput(date, precision, null)
+ // Capture a single "now" instant up-front so that the picker output
+ // and the calendar used for assertions agree on the same point in
+ // time. Previously the picker rendered with one
System.currentTimeMillis()
+ // and the calendar was constructed afterwards, which made the test
+ // flaky on slow runners (e.g. Windows CI) when the two calls fell
+ // on opposite sides of a minute (or hour/day/year) boundary -
+ // see testDatePickerTagWithMinutePrecision().
+ Calendar calendar = new GregorianCalendar()
+ Object resolvedDate = date
+ if (date == null) {
+ resolvedDate = calendar.getTime()
+ } else if (date instanceof Date) {
+ calendar.setTime(date)
+ } /*else if (date instanceof TemporalAccessor) {
+ ZonedDateTime zonedDateTime
+ if (date instanceof LocalDateTime) {
+ zonedDateTime = ZonedDateTime.of(date, ZoneId.systemDefault())
+ } else if (date instanceof LocalDate) {
+ zonedDateTime = ZonedDateTime.of(date, LocalTime.MIN,
ZoneId.systemDefault())
+ } else {
+ zonedDateTime = ZonedDateTime.from(date)
+ }
+ calendar = GregorianCalendar.from(zonedDateTime)
+ }*/
+
+ Document document = getDatePickerOutput(resolvedDate, precision, null)
assertNotNull(document)
Review Comment:
Good catch. Applied in a3babf3dea: now pass the captured instant via the
tag's `default` attribute (and keep `value` unset) so `datePicker`'s `if
(!value) { value = xdefault }` defaulting branch is still exercised. The race
is closed because both the assertion calendar and the value the tag falls back
to are derived from the same `new GregorianCalendar()` instant.
Verified: all 11 `FormTagLib2Tests` pass, including
`testDatePickerTagWithMinutePrecision`.
##########
grails-gsp/plugin/src/test/groovy/org/grails/web/taglib/FormTagLib2Tests.groovy:
##########
@@ -171,32 +171,39 @@ class FormTagLib2Tests extends AbstractGrailsTagTests {
}
private void testDatePickerTag(Object date, String precision) {
- Document document = getDatePickerOutput(date, precision, null)
+ // Capture a single "now" instant up-front so that the picker output
Review Comment:
Done in a3babf3dea - shortened to a single line: `// Capture "now" upfront
to prevent test pollution at minute/hour/day boundaries.`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]