Skip to content

Commit

Permalink
added unit test for JENKINS-34389
Browse files Browse the repository at this point in the history
  • Loading branch information
bboehmke committed Mar 24, 2017
1 parent f47f9c7 commit a0c1223
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/test/java/hudson/matrix/MatrixTest.java
Expand Up @@ -28,11 +28,16 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertArrayEquals;

import hudson.matrix.helper.DynamicTestAxis;

import hudson.model.Item;
import hudson.model.queue.QueueTaskFuture;
import hudson.security.AuthorizationMatrixProperty;
import hudson.security.ProjectMatrixAuthorizationStrategy;

import java.util.Arrays;
import java.util.Collections;

import org.acegisecurity.context.SecurityContextHolder;
Expand All @@ -44,6 +49,7 @@
import java.io.IOException;
import java.util.Set;

import org.apache.commons.lang.reflect.FieldUtils;
import org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.junit.Rule;
Expand Down Expand Up @@ -135,4 +141,32 @@ private static void expectRejection(MatrixProject project, String combinationFil
scriptApproval.approveSignature(signature);
assertEquals(Collections.emptySet(), scriptApproval.getPendingSignatures());
}


@Issue("JENKINS-34389")
@Test public void axisValuesChanged() throws Exception {
// create project with dynamic axis
MatrixProject project = j.createMatrixProject();
project.setAxes(new AxisList(
new DynamicTestAxis("axis")
));
project.setConcurrentBuild(true);

// build project
QueueTaskFuture<MatrixBuild> matrixBuildQueue = project.scheduleBuild2(0);
matrixBuildQueue.waitForStart();

QueueTaskFuture<MatrixBuild> matrixBuildQueue2 = project.scheduleBuild2(0);

MatrixBuild build = matrixBuildQueue.get();
MatrixBuild build2 = matrixBuildQueue2.get();

// get axes from build
AxisList axes = (AxisList) FieldUtils.readField(build, "axes", true);
AxisList axes2 = (AxisList) FieldUtils.readField(build2, "axes", true);

// check if axes are valid
assertArrayEquals(axes.get(0).getValues().toArray(), Arrays.asList("1", "10").toArray());
assertArrayEquals(axes2.get(0).getValues().toArray(), Arrays.asList("2", "20").toArray());
}
}
32 changes: 32 additions & 0 deletions src/test/java/hudson/matrix/helper/DynamicTestAxis.java
@@ -0,0 +1,32 @@
package hudson.matrix.helper;

import com.google.common.collect.Lists;
import hudson.matrix.Axis;
import hudson.matrix.MatrixBuild;

import java.util.Arrays;
import java.util.List;


public class DynamicTestAxis extends Axis {
private final List<String> axisValues = Lists.newArrayList();

public DynamicTestAxis(String name) {
super(name, "");
}

@Override
public synchronized List<String> getValues() {
return axisValues;
}

@Override
public synchronized List<String> rebuild(MatrixBuild.MatrixBuildExecution context) {
// each axis has 2 values: 1. = build number & 2. = build number * 10
axisValues.clear();
axisValues.addAll(Arrays.asList(
Integer.toString(context.getBuild().getNumber()),
Integer.toString(context.getBuild().getNumber()*10)));
return axisValues;
}
}

0 comments on commit a0c1223

Please sign in to comment.