Skip to content

Commit

Permalink
Ignore unreachable/unknown URL tests when fallback exists
Browse files Browse the repository at this point in the history
  • Loading branch information
tony19 committed Feb 27, 2019
1 parent 56ba37a commit 3668f6e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusChecker;
import ch.qos.logback.core.testUtil.FileTestUtil;
import ch.qos.logback.core.testUtil.NetworkTestUtil;
import ch.qos.logback.core.util.CoreTestConstants;

@RunWith(RobolectricTestRunner.class)
Expand Down Expand Up @@ -281,11 +282,7 @@ public void includesUrl() throws JoranException {

@Test
public void ignoresUnknownUrl() throws JoranException {
// FIXME: This test fails when the ISP does not return 404 for
// unknown URLs (required to cause an exception upon opening
// the URL request). This was observed when running tests
// while tethered to bluetooth mobile hotspot. The fix would
// be to refactor AbstractIncludeAction to inject a URL opener.
new NetworkTestUtil().assumeNoUnresolvedUrlFallback();

final String xml =
"<x>" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import ch.qos.logback.core.net.SocketConnector;
import ch.qos.logback.core.net.server.ServerSocketUtil;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.testUtil.NetworkTestUtil;

/**
* Unit tests for {@link SocketReceiver}.
Expand Down Expand Up @@ -117,6 +118,7 @@ public void testStartNoPort() throws Exception {

@Test
public void testStartUnknownHost() throws Exception {
new NetworkTestUtil().assumeNoUnresolvedUrlFallback();
receiver.setPort(6000);
receiver.setRemoteHost(TEST_HOST_NAME);
receiver.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import ch.qos.logback.core.joran.spi.ElementSelector;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusChecker;
import ch.qos.logback.core.testUtil.NetworkTestUtil;
import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.util.CoreTestConstants;
import ch.qos.logback.core.util.StatusPrinter;
Expand Down Expand Up @@ -199,12 +200,7 @@ public void malformedURL() throws JoranException {

@Test
public void unknownURL() throws JoranException {
// FIXME: This test fails when the ISP does not return 404 for
// unknown URLs (required to cause an exception upon opening
// the URL request). This was observed when running tests
// while tethered to bluetooth mobile hotspot. The fix would
// be to refactor AbstractIncludeAction to inject a URL opener.

new NetworkTestUtil().assumeNoUnresolvedUrlFallback();
System.setProperty(INCLUDE_KEY, "http://logback2345.qos.ch");
tc.doConfigure(TOP_BY_URL);
assertEquals(Status.WARN, statusChecker.getHighestLevel(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import ch.qos.logback.core.net.mock.MockContext;
import ch.qos.logback.core.spi.PreSerializationTransformer;
import ch.qos.logback.core.testUtil.NetworkTestUtil;
import ch.qos.logback.core.util.Duration;
import ch.qos.logback.core.util.ExecutorServiceUtil;

Expand Down Expand Up @@ -153,6 +154,8 @@ public void failsToStartWithNegativeQueueSize() throws Exception {
@Test
public void failsToStartWithUnresolvableRemoteHost() throws Exception {

new NetworkTestUtil().assumeNoUnresolvedUrlFallback();

// given
appender.setRemoteHost("NOT.A.VALID.REMOTE.HOST.NAME");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ch.qos.logback.core.testUtil;

import java.net.InetAddress;
import java.net.UnknownHostException;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNull.nullValue;
import static org.hamcrest.junit.MatcherAssume.assumeThat;

public class NetworkTestUtil {
public void assumeNoUnresolvedUrlFallback() {
// FIXME: This test fails when the ISP does not return 404 for
// unknown URLs (required to cause an exception upon opening
// the URL request). This was observed when running tests
// while tethered to bluetooth mobile hotspot. The fix would
// be to refactor AbstractIncludeAction to inject a URL opener.
InetAddress addr;
try {
addr = InetAddress.getByName("not.a.valid.domain.name");
} catch (UnknownHostException ex) {
addr = null;
}
assumeThat(addr, is(nullValue()));
}
}

0 comments on commit 3668f6e

Please sign in to comment.