提交 90ab8956 编写于 作者: J Jesse Glick

UDPBroadcastThreadTest was often failing on ci.jenkins-ci.org; making more lenient.

Mar 4, 2013 10:55:46 PM hudson.UDPBroadcastThread run
WARNING: UDP handling problem
java.io.IOException: Operation not permitted
	at java.net.PlainDatagramSocketImpl.send(Native Method)
	at java.net.DatagramSocket.send(DatagramSocket.java:625)
	at hudson.UDPBroadcastThread.run(UDPBroadcastThread.java:98)
→
java.net.SocketTimeoutException: Receive timed out
	at java.net.PlainDatagramSocketImpl.receive0(Native Method)
	at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:145)
	at java.net.DatagramSocket.receive(DatagramSocket.java:725)
	at hudson.UDPBroadcastThreadTest.receiveAndVerify(UDPBroadcastThreadTest.java:70)
	at hudson.UDPBroadcastThreadTest.testMulticast(UDPBroadcastThreadTest.java:51)
上级 1e6454a7
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*/ */
package hudson; package hudson;
import edu.umd.cs.findbugs.annotations.SuppressWarnings;
import hudson.model.Hudson; import hudson.model.Hudson;
import jenkins.model.Jenkins; import jenkins.model.Jenkins;
import hudson.util.OneShotEvent; import hudson.util.OneShotEvent;
...@@ -52,6 +53,7 @@ public class UDPBroadcastThread extends Thread { ...@@ -52,6 +53,7 @@ public class UDPBroadcastThread extends Thread {
public final OneShotEvent ready = new OneShotEvent(); public final OneShotEvent ready = new OneShotEvent();
private MulticastSocket mcs; private MulticastSocket mcs;
private boolean shutdown; private boolean shutdown;
static boolean udpHandlingProblem; // for tests
/** /**
* @deprecated as of 1.416 * @deprecated as of 1.416
...@@ -67,6 +69,7 @@ public class UDPBroadcastThread extends Thread { ...@@ -67,6 +69,7 @@ public class UDPBroadcastThread extends Thread {
mcs = new MulticastSocket(PORT); mcs = new MulticastSocket(PORT);
} }
@SuppressWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
@Override @Override
public void run() { public void run() {
try { try {
...@@ -106,6 +109,7 @@ public class UDPBroadcastThread extends Thread { ...@@ -106,6 +109,7 @@ public class UDPBroadcastThread extends Thread {
} catch (IOException e) { } catch (IOException e) {
if (shutdown) return; // forcibly closed if (shutdown) return; // forcibly closed
LOGGER.log(Level.WARNING, "UDP handling problem",e); LOGGER.log(Level.WARNING, "UDP handling problem",e);
udpHandlingProblem = true;
} }
} }
......
package hudson; package hudson;
import org.jvnet.hudson.test.HudsonTestCase;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
...@@ -12,30 +11,43 @@ import java.net.DatagramPacket; ...@@ -12,30 +11,43 @@ import java.net.DatagramPacket;
import java.net.InetAddress; import java.net.InetAddress;
import java.io.StringReader; import java.io.StringReader;
import java.io.IOException; import java.io.IOException;
import java.net.SocketTimeoutException;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
/** /**
* @author Kohsuke Kawaguchi * @author Kohsuke Kawaguchi
*/ */
public class UDPBroadcastThreadTest extends HudsonTestCase { public class UDPBroadcastThreadTest {
@Rule public JenkinsRule j = new JenkinsRule();
/** /**
* Old unicast based clients should still be able to receive some reply, * Old unicast based clients should still be able to receive some reply,
* as we haven't changed the port. * as we haven't changed the port.
*/ */
public void testLegacy() throws Exception { @Test public void legacy() throws Exception {
DatagramSocket s = new DatagramSocket(); DatagramSocket s = new DatagramSocket();
sendQueryTo(s, InetAddress.getLocalHost()); sendQueryTo(s, InetAddress.getLocalHost());
s.setSoTimeout(15000); // to prevent test hang s.setSoTimeout(15000); // to prevent test hang
receiveAndVerify(s); try {
receiveAndVerify(s);
} catch (SocketTimeoutException x) {
Assume.assumeFalse(UDPBroadcastThread.udpHandlingProblem);
throw x;
}
} }
/** /**
* Multicast based clients should be able to receive multiple replies. * Multicast based clients should be able to receive multiple replies.
*/ */
public void testMulticast() throws Exception { @Test public void multicast() throws Exception {
UDPBroadcastThread second = new UDPBroadcastThread(jenkins); UDPBroadcastThread second = new UDPBroadcastThread(j.jenkins);
second.start(); second.start();
UDPBroadcastThread third = new UDPBroadcastThread(jenkins); UDPBroadcastThread third = new UDPBroadcastThread(j.jenkins);
third.start(); third.start();
second.ready.block(); second.ready.block();
...@@ -47,8 +59,13 @@ public class UDPBroadcastThreadTest extends HudsonTestCase { ...@@ -47,8 +59,13 @@ public class UDPBroadcastThreadTest extends HudsonTestCase {
s.setSoTimeout(15000); // to prevent test hang s.setSoTimeout(15000); // to prevent test hang
// we should at least get two replies since we run two broadcasts // we should at least get two replies since we run two broadcasts
receiveAndVerify(s); try {
receiveAndVerify(s); receiveAndVerify(s);
receiveAndVerify(s);
} catch (SocketTimeoutException x) {
Assume.assumeFalse(UDPBroadcastThread.udpHandlingProblem);
throw x;
}
} finally { } finally {
third.interrupt(); third.interrupt();
second.interrupt(); second.interrupt();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册