Skip to content

Commit 4bc2f3c

Browse files
authored
Fix timeout values in test (#99)
* - New functions to quickly reset the API timeout values - Reset timeouts after timeout test so as to not interfere with other tests * Revert "- New functions to quickly reset the API timeout values" This reverts commit 86e4976. * - Remove reset functions - Instead, default values are public (but immutable), so can be referenced if needed - Fix test to use public reference rather than helper methods to reset timeouts
1 parent 6d3f2fc commit 4bc2f3c

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/main/java/com/easypost/net/EasyPostResource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public abstract class EasyPostResource {
5757
public static final String CHARSET = "UTF-8";
5858
public static final ArrayList<String> GLOBAL_FIELD_ACCESSORS =
5959
new ArrayList<>(Arrays.asList("getCreatedAt", "getUpdatedAt", "getFees"));
60-
private static final int DEFAULT_CONNECT_TIMEOUT_MILLISECONDS = 30000;
61-
private static final int DEFAULT_READ_TIMEOUT_MILLISECONDS = 60000;
62-
private static final double DEFAULT_APP_ENGINE_TIMEOUT_SECONDS = 20.0;
60+
public static final int DEFAULT_CONNECT_TIMEOUT_MILLISECONDS = 30000;
61+
public static final int DEFAULT_READ_TIMEOUT_MILLISECONDS = 60000;
62+
public static final double DEFAULT_APP_ENGINE_TIMEOUT_SECONDS = 20.0;
6363
private static final String DNS_CACHE_TTL_PROPERTY_NAME = "networkaddress.cache.ttl";
6464
private static final String CUSTOM_URL_STREAM_HANDLER_PROPERTY_NAME = "com.easypost.net.customURLStreamHandler";
6565
private static int connectTimeoutMilliseconds = DEFAULT_CONNECT_TIMEOUT_MILLISECONDS;

src/test/java/com/easypost/EasyPostTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.easypost.model.TrackingLocation;
2626
import com.easypost.model.Webhook;
2727
import com.easypost.model.WebhookCollection;
28+
import com.easypost.net.EasyPostResource;
2829
import org.junit.BeforeClass;
2930
import org.junit.Ignore;
3031
import org.junit.Rule;
@@ -355,7 +356,7 @@ public void testTrackerCreateAndRetrieve() throws EasyPostException, ParseExcept
355356
@Test
356357
public void testBatchTrackerCreate() throws EasyPostException {
357358

358-
String[] trackingCodes = new String[]{"EZ1000000001", "EZ1000000002", "EZ1000000003"};
359+
String[] trackingCodes = new String[] { "EZ1000000001", "EZ1000000002", "EZ1000000003" };
359360
HashMap<String, Object> trackingCodeParams = new HashMap<String, Object>();
360361

361362
for (int i = 0; i < trackingCodes.length; i++) {
@@ -1072,6 +1073,10 @@ public void testClientTimeout() throws EasyPostException {
10721073
assertEquals(Order.getConnectTimeoutMilliseconds(), timeout);
10731074
assertEquals(Order.getReadTimeoutMilliseconds(), timeout);
10741075
assertEquals(Order.getAppEngineTimeoutSeconds(), timeout, 0.001);
1076+
// Need to reset these timeouts to default values for other tests to run correctly
1077+
Order.setConnectTimeoutMilliseconds(EasyPostResource.DEFAULT_CONNECT_TIMEOUT_MILLISECONDS);
1078+
Order.setReadTimeoutMilliseconds(EasyPostResource.DEFAULT_READ_TIMEOUT_MILLISECONDS);
1079+
Order.setAppEngineTimeoutSeconds(EasyPostResource.DEFAULT_APP_ENGINE_TIMEOUT_SECONDS);
10751080
}
10761081

10771082

0 commit comments

Comments
 (0)