From d5b82412d8729a6bfa8056e7000a5a7be0b9b86e Mon Sep 17 00:00:00 2001 From: Ishan Chattopadhyaya Date: Tue, 7 May 2024 01:33:18 +0530 Subject: [PATCH] SOLR-17278: Skip broken timezones in the test --- .../apache/solr/util/TimeZoneUtilsTest.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/solr/core/src/test/org/apache/solr/util/TimeZoneUtilsTest.java b/solr/core/src/test/org/apache/solr/util/TimeZoneUtilsTest.java index 11c87f55813..4b102a4bdda 100644 --- a/solr/core/src/test/org/apache/solr/util/TimeZoneUtilsTest.java +++ b/solr/core/src/test/org/apache/solr/util/TimeZoneUtilsTest.java @@ -16,6 +16,7 @@ */ package org.apache.solr.util; +import java.lang.invoke.MethodHandles; import java.util.HashSet; import java.util.Locale; import java.util.Random; @@ -23,9 +24,14 @@ import java.util.TimeZone; import org.apache.lucene.tests.util.TestUtil; import org.apache.solr.SolrTestCase; +import org.apache.solr.common.util.SuppressForbidden; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class TimeZoneUtilsTest extends SolrTestCase { + private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); + private static void assertSameRules( final String label, final TimeZone expected, final TimeZone actual) { @@ -39,10 +45,12 @@ private static void assertSameRules( assertTrue(label + ": " + expected + " [[NOT SAME RULES]] " + actual, same); } + @SuppressForbidden(reason = "Using TimeZone.getDisplayName() just for warning purpose in a test") public void testValidIds() { final Set idsTested = new HashSet<>(); + int skipped = 0; // brain dead: anything the JVM supports, should work for (String validId : TimeZone.getAvailableIDs()) { assertTrue( @@ -51,6 +59,20 @@ public void testValidIds() { final TimeZone expected = TimeZone.getTimeZone(validId); final TimeZone actual = TimeZoneUtils.getTimeZone(validId); + + // Hack: Why do some timezones have useDaylightTime() as true, but DST as 0? + // It causes an exception during String.valueOf(actual/expected) + if (expected.useDaylightTime() && expected.getDSTSavings() == 0 + || actual.useDaylightTime() && actual.getDSTSavings() == 0) { + if (log.isWarnEnabled()) { + log.warn( + "Not expecting DST to be 0 for {} " + " (actual: {})", + expected.getDisplayName(), + actual.getDisplayName()); + } + skipped++; + continue; + } assertSameRules(validId, expected, actual); idsTested.add(validId); @@ -58,7 +80,7 @@ public void testValidIds() { assertEquals( "TimeZone.getAvailableIDs vs TimeZoneUtils.KNOWN_TIMEZONE_IDS", - TimeZoneUtils.KNOWN_TIMEZONE_IDS.size(), + TimeZoneUtils.KNOWN_TIMEZONE_IDS.size() - skipped, idsTested.size()); }