Skip to content

Commit

Permalink
minor updates to integration tests and failsafe timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
gbhat618 committed Dec 23, 2024
1 parent 35a9f74 commit 79b8ffd
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 21 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
<hudson.agents.NodeProvisioner.MARGIN0>1.0</hudson.agents.NodeProvisioner.MARGIN0>
<hudson.remoting.Launcher.pingIntervalSec>-1</hudson.remoting.Launcher.pingIntervalSec>
<com.google.jenkins.plugins.computeengine.integration.ITUtil.windows>${it.windows}</com.google.jenkins.plugins.computeengine.integration.ITUtil.windows>
<jenkins.test.timeout>600</jenkins.test.timeout>
</systemPropertyVariables>
<excludes>
<exclude>**/ITUtil.java</exclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

/** Integration test suite for {@link ComputeClient}. */
public class ComputeClientIT {
private static Logger log = Logger.getLogger(ComputeClientIT.class.getName());
private static final Logger log = Logger.getLogger(ComputeClientIT.class.getName());

private static Map<String, String> label = getLabel(ComputeClientIT.class);
private static ComputeClient client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.NULL_TEMPLATE;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.PROJECT_ID;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.TEST_TIMEOUT_MULTIPLIER;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.ZONE;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.getLabel;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.initClient;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.initCloud;
Expand All @@ -30,15 +31,17 @@
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;

import com.google.api.services.compute.model.Instance;
import com.google.cloud.graphite.platforms.plugin.client.ComputeClient;
import com.google.common.collect.ImmutableList;
import com.google.jenkins.plugins.computeengine.ComputeEngineCloud;
import hudson.model.labels.LabelAtom;
import hudson.slaves.NodeProvisioner.PlannedNode;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import org.junit.AfterClass;
Expand All @@ -65,13 +68,14 @@ public class ComputeEngineCloud1WorkerCreatedFor2ExecutorsIT {

private static ComputeClient client;
private static Map<String, String> label = getLabel(ComputeEngineCloud1WorkerCreatedFor2ExecutorsIT.class);
private static ComputeEngineCloud cloud;
private static Collection<PlannedNode> planned;
private static Instance instance;

@BeforeClass
public static void init() throws Exception {
log.info("init");
initCredentials(jenkinsRule);
cloud = initCloud(jenkinsRule);
ComputeEngineCloud cloud = initCloud(jenkinsRule);
client = initClient(jenkinsRule, label, log);

cloud.setConfigurations(ImmutableList.of(instanceConfigurationBuilder()
Expand All @@ -82,6 +86,11 @@ public static void init() throws Exception {
.template(NULL_TEMPLATE)
.googleLabels(label)
.build()));

planned = cloud.provision(new LabelAtom(LABEL), 2);
planned.iterator().next().future.get();

instance = client.getInstance(PROJECT_ID, ZONE, planned.iterator().next().displayName);
}

@AfterClass
Expand All @@ -90,13 +99,7 @@ public static void teardown() throws IOException {
}

@Test
public void test1WorkerCreatedFor2ExecutorsStatusRunning()
throws ExecutionException, InterruptedException, IOException {
var planned = cloud.provision(new LabelAtom(LABEL), 2);
assertEquals(1, planned.size());

planned.iterator().next().future.get();

public void test1WorkerCreatedFor2ExecutorsStatusRunning() throws IOException {
// assert on jenkins side
assertEquals(1, jenkinsRule.jenkins.getNodes().size());
assertEquals(2, jenkinsRule.jenkins.getNodes().get(0).getNumExecutors());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class ComputeEngineCloudNonStandardJavaIT {
public static JenkinsRule jenkinsRule = new JenkinsRule();

private static ComputeClient client;
private static Map<String, String> label = getLabel(ComputeEngineCloudNonStandardJavaIT.class);
private static final Map<String, String> label = getLabel(ComputeEngineCloudNonStandardJavaIT.class);

@BeforeClass
public static void init() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.PROJECT_ID;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.SNAPSHOT_LABEL;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.SNAPSHOT_TIMEOUT;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.TEST_TIMEOUT_MULTIPLIER;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.execute;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.getLabel;
import static com.google.jenkins.plugins.computeengine.integration.ITUtil.initClient;
Expand Down Expand Up @@ -52,16 +53,19 @@
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.WithTimeout;

/**
* Integration test suite for {@link ComputeEngineCloud}. Verifies that when configured to use one
* shot instances and create snapshots, a snapshot will be created upon instance termination when a
* build fails.
*/
public class ComputeEngineCloudSnapshotCreatedIT {
private static Logger log = Logger.getLogger(ComputeEngineCloudSnapshotCreatedIT.class.getName());
private static final Logger log = Logger.getLogger(ComputeEngineCloudSnapshotCreatedIT.class.getName());

@ClassRule
public static Timeout timeout = new Timeout(15L * TEST_TIMEOUT_MULTIPLIER, TimeUnit.MINUTES);

@ClassRule
public static JenkinsRule jenkinsRule = new JenkinsRule();
Expand Down Expand Up @@ -117,19 +121,16 @@ public static void teardown() throws IOException {
}

/** Tests snapshot is created when we have failure builds for given node */
@WithTimeout(1200)
@Test
public void testSnapshotCreatedNotNull() {
assertNotNull(createdSnapshot);
}

@WithTimeout(1200)
@Test
public void testSnapshotCreatedStatusReady() {
assertEquals("READY", createdSnapshot.getStatus());
}

@WithTimeout(1200)
@Test
public void testSnapshotCreatedOneShotInstanceDeleted() {
Awaitility.await()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
* are provisioned properly.
*/
public class ComputeEngineCloudWorkerCreatedIT {
private static Logger log = Logger.getLogger(ComputeEngineCloudWorkerCreatedIT.class.getName());
private static final Logger log = Logger.getLogger(ComputeEngineCloudWorkerCreatedIT.class.getName());

@ClassRule
public static Timeout timeout = new Timeout(10L * TEST_TIMEOUT_MULTIPLIER, TimeUnit.MINUTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* worker fails upon creation when Java is not installed.
*/
public class ComputeEngineCloudWorkerFailedIT {
private static Logger log = Logger.getLogger(ComputeEngineCloudWorkerFailedIT.class.getName());
private static final Logger log = Logger.getLogger(ComputeEngineCloudWorkerFailedIT.class.getName());

@ClassRule
public static Timeout timeout = new Timeout(7L * TEST_TIMEOUT_MULTIPLIER, TimeUnit.MINUTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* java path.
*/
public class ConfigAsCodeNonStandardJavaIT {
private static Logger log = Logger.getLogger(ConfigAsCodeNonStandardJavaIT.class.getName());
private static final Logger log = Logger.getLogger(ConfigAsCodeNonStandardJavaIT.class.getName());

@ClassRule
public static JenkinsRule jenkinsRule = new JenkinsRule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.jvnet.hudson.test.JenkinsRule;

public class ConfigAsCodeTestIT {
private static Logger log = Logger.getLogger(ConfigAsCodeTestIT.class.getName());
private static final Logger log = Logger.getLogger(ConfigAsCodeTestIT.class.getName());

@ClassRule
public static JenkinsRule jenkinsRule = new JenkinsRule();
Expand Down

0 comments on commit 79b8ffd

Please sign in to comment.