提交 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 @@
*/
package hudson;
import edu.umd.cs.findbugs.annotations.SuppressWarnings;
import hudson.model.Hudson;
import jenkins.model.Jenkins;
import hudson.util.OneShotEvent;
......@@ -52,6 +53,7 @@ public class UDPBroadcastThread extends Thread {
public final OneShotEvent ready = new OneShotEvent();
private MulticastSocket mcs;
private boolean shutdown;
static boolean udpHandlingProblem; // for tests
/**
* @deprecated as of 1.416
......@@ -67,6 +69,7 @@ public class UDPBroadcastThread extends Thread {
mcs = new MulticastSocket(PORT);
}
@SuppressWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
@Override
public void run() {
try {
......@@ -106,6 +109,7 @@ public class UDPBroadcastThread extends Thread {
} catch (IOException e) {
if (shutdown) return; // forcibly closed
LOGGER.log(Level.WARNING, "UDP handling problem",e);
udpHandlingProblem = true;
}
}
......
package hudson;
import org.jvnet.hudson.test.HudsonTestCase;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
......@@ -12,30 +11,43 @@ import java.net.DatagramPacket;
import java.net.InetAddress;
import java.io.StringReader;
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
*/
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,
* as we haven't changed the port.
*/
public void testLegacy() throws Exception {
@Test public void legacy() throws Exception {
DatagramSocket s = new DatagramSocket();
sendQueryTo(s, InetAddress.getLocalHost());
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.
*/
public void testMulticast() throws Exception {
UDPBroadcastThread second = new UDPBroadcastThread(jenkins);
@Test public void multicast() throws Exception {
UDPBroadcastThread second = new UDPBroadcastThread(j.jenkins);
second.start();
UDPBroadcastThread third = new UDPBroadcastThread(jenkins);
UDPBroadcastThread third = new UDPBroadcastThread(j.jenkins);
third.start();
second.ready.block();
......@@ -47,8 +59,13 @@ public class UDPBroadcastThreadTest extends HudsonTestCase {
s.setSoTimeout(15000); // to prevent test hang
// we should at least get two replies since we run two broadcasts
receiveAndVerify(s);
receiveAndVerify(s);
try {
receiveAndVerify(s);
receiveAndVerify(s);
} catch (SocketTimeoutException x) {
Assume.assumeFalse(UDPBroadcastThread.udpHandlingProblem);
throw x;
}
} finally {
third.interrupt();
second.interrupt();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册