Copilot commented on code in PR #15612:
URL: https://github.com/apache/grails-core/pull/15612#discussion_r3169708579
##########
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:
When `date == null`, the test now passes an explicit `value` to `datePicker`
(`resolvedDate = calendar.getTime()`), which changes the exercised code path:
`datePicker` no longer runs its `!value -> value = xdefault` defaulting logic.
To keep the original behavior ("no value provided" defaults to now) while still
removing the race, consider leaving `value` unset and instead passing the
captured instant via the tag's `default` attribute (i.e., call
`getDatePickerOutput(null, precision, calendar.getTime())` when `date` is null,
and use `calendar` for assertions).
--
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]