Skip to content
Permalink
Browse files

Fix JENKINS-16181

- Added a retry on SocketException occuring
- Added commented out main descriptor test, this will be used later
  • Loading branch information
slide committed Jan 31, 2013
1 parent 6a6bc84 commit 3af25cc2606cf0147376870d32de5930521e6a6f
@@ -45,6 +45,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.SecurityException;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
@@ -297,39 +298,54 @@ private boolean sendMail(EmailType mailType, AbstractBuild<?, ?> build, BuildLis
MimeMessage msg = createMail(mailType, build, listener);
debug(listener.getLogger(), "Successfully created MimeMessage");
Address[] allRecipients = msg.getAllRecipients();
int retries = 0;
if (allRecipients != null) {
StringBuilder buf = new StringBuilder("Sending email to:");
for (Address a : allRecipients) {
buf.append(' ').append(a);
}
listener.getLogger().println(buf);
if(executePresendScript(build, listener, msg)) {
try {
Transport.send(msg);
} catch (SendFailedException e) {
Address[] addresses = e.getValidSentAddresses();
if(addresses.length > 0) {
buf = new StringBuilder("Successfully sent to the following addresses:");
for (Address a : addresses) {
buf.append(' ').append(a);
while(true) {
try {
Transport.send(msg);
break;
} catch (SendFailedException e) {
if(e.getNextException() != null && e.getNextException() instanceof SocketException) {
listener.getLogger().println("Socket error sending email, retrying once more in 10 seconds...");
Thread.sleep(10000);
} else {
Address[] addresses = e.getValidSentAddresses();
if(addresses.length > 0) {
buf = new StringBuilder("Successfully sent to the following addresses:");
for (Address a : addresses) {
buf.append(' ').append(a);
}
listener.getLogger().println(buf);
}
addresses = e.getValidUnsentAddresses();
if(addresses.length > 0) {
buf = new StringBuilder("Error sending to the following VALID addresses:");
for (Address a : addresses) {
buf.append(' ').append(a);
}
listener.getLogger().println(buf);
}
addresses = e.getInvalidAddresses();
if(addresses.length > 0) {
buf = new StringBuilder("Error sending to the following INVALID addresses:");
for (Address a : addresses) {
buf.append(' ').append(a);
}
listener.getLogger().println(buf);
}
break;
}
listener.getLogger().println(buf);
}
addresses = e.getValidUnsentAddresses();
if(addresses.length > 0) {
buf = new StringBuilder("Error sending to the following VALID addresses:");
for (Address a : addresses) {
buf.append(' ').append(a);
}
listener.getLogger().println(buf);
}
addresses = e.getInvalidAddresses();
if(addresses.length > 0) {
buf = new StringBuilder("Error sending to the following INVALID addresses:");
for (Address a : addresses) {
buf.append(' ').append(a);
}
listener.getLogger().println(buf);
}
retries++;
if(retries > 1) {
listener.getLogger().println("Failed after second try sending email");
break;
}
}
if (build.getAction(MailMessageIdAction.class) == null) {
@@ -0,0 +1,108 @@
package hudson.plugins.emailext;

import hudson.Functions;
import jenkins.model.Jenkins;

//import com.thoughtworks.selenium.DefaultSelenium;

import org.apache.commons.lang.StringUtils;
import org.junit.BeforeClass;
import org.junit.AfterClass;
import org.jvnet.hudson.test.HudsonTestCase;

public class ExtendedEmailPublisherDescriptorTest extends HudsonTestCase {

// private DefaultSelenium selenium;

// protected DefaultSelenium createSeleniumClient(String url) throws Exception {
// String browserString = "*firefox";
// if(Functions.isWindows()) {
// browserString = "*iexplore";
// }
// return new DefaultSelenium("localhost", 4444, browserString, url);
// }

public void testGlobalConfigDefaultState() throws Exception {
// // windows pretty much always has internet explorer which we use on there

// //assumeTrue(Functions.isWindows())


// selenium = createSeleniumClient(getURL().toString());

// selenium.start();

// selenium.setTimeout("120000"); // wait up to 2 mins

// selenium.open("/configure");
// assertEquals("Should be at the Configure System page",
// "Configure System [Jenkins]", selenium.getTitle());

// // override global settings checkbox control
// assertTrue(selenium.isElementPresent("name=ext_mailer_override_global_settings"));
// assertFalse("Override global config should not be checked by default",
// selenium.isChecked("name=ext_mailer_override_global_settings"));

// // default content type select control
// assertTrue(selenium.isElementPresent("name=ext_mailer_default_content_type"));
// assertEquals("Plain text should be selected by default",
// "text/plain", selenium.getSelectedValue("name=ext_mailer_default_content_type"));

// assertTrue(selenium.isElementPresent("name=extmailer.useListID"));
// assertFalse("Use List ID should not be checked by default",
// selenium.isChecked("name=extmailer.useListID"));

// assertTrue(selenium.isElementPresent("name=extmailer.addPrecedenceBulk"));
// assertFalse("Add precedence bulk should not be checked by default",
// selenium.isChecked("name=extmailer.addPrecedenceBulk"));

// assertTrue(selenium.isElementPresent("name=ext_mailer_default_recipients"));
// assertEquals("Default recipients should be blank by default",
// "", selenium.getValue("name=ext_mailer_default_recipients"));

// assertTrue(selenium.isElementPresent("name=ext_mailer_default_replyto"));
// assertEquals("Default ReplyTo should be blank by default",
// "", selenium.getValue("name=ext_mailer_default_replyto"));

// assertTrue(selenium.isElementPresent("name=ext_mailer_emergency_reroute"));
// assertEquals("Emergency reroute should be blank by default",
// "", selenium.getValue("name=ext_mailer_emergency_reroute"));

// assertTrue(selenium.isElementPresent("name=ext_mailer_default_subject"));
// assertEquals("Default subject should be set by default",
// "$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!" ,
// selenium.getValue("name=ext_mailer_default_subject"));

// assertTrue(selenium.isElementPresent("name=ext_mailer_max_attachment_size"));
// assertEquals("Max attachment size should be blank by default",
// "", selenium.getValue("name=ext_mailer_max_attachment_size"));

// assertTrue(selenium.isElementPresent("name=ext_mailer_default_body"));
// assertEquals("Default content should be set by default",
// "$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:\n\nCheck console output at $BUILD_URL to view the results." ,
// selenium.getValue("name=ext_mailer_default_body"));

// assertTrue(selenium.isElementPresent("name=ext_mailer_debug_mode"));
// assertFalse("Debug mode should not be checked by default",
// selenium.isChecked("name=ext_mailer_debug_mode"));

// assertTrue(selenium.isElementPresent("name=ext_mailer_security_enabled"));
// assertFalse("Security mode should not be checked by default",
// selenium.isChecked("name=ext_mailer_security_enabled"));

// assertEquals("Content token help should be hidden by default",
// "display:none",
// StringUtils.replaceChars(selenium.getAttribute("id=contentTokenHelpConf@style"), " ;", ""));

// // assertTrue(selenium.isElementPresent("name=contentTokenAnchor"));

// // selenium.click("name=contentTokenAnchor");
// // assertEquals("Content token help should be shown when the help button is clicked",
// // "display:block",
// // StringUtils.replaceChars(selenium.getAttribute("id=contentTokenHelpConf@style"), " ;", ""));



// selenium.stop();
}
}

0 comments on commit 3af25cc

Please sign in to comment.
You can’t perform that action at this time.