Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-31516] Run re-index on children on organization re-index #20

Merged
merged 4 commits into from Dec 9, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -162,6 +162,7 @@ public void complete() throws IllegalStateException, InterruptedException {
PersistedList<BranchSource> sourcesList = existing.getSourcesList();
sourcesList.clear();
sourcesList.addAll(createBranchSources());
existing.scheduleBuild();
return;
}
if (!observer.mayCreate(projectName)) {
@@ -26,18 +26,29 @@

import hudson.model.ItemGroup;
import hudson.model.TaskListener;
import jenkins.branch.harness.MultiBranchImpl;
import jenkins.scm.api.SCMNavigator;
import jenkins.scm.impl.SingleSCMNavigator;
import hudson.scm.NullSCM;
import hudson.util.RingBufferLogHandler;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import jenkins.scm.api.SCMSource;
import jenkins.scm.impl.SingleSCMSource;
import org.junit.Test;
import static org.junit.Assert.*;

import org.junit.Assert;
import org.junit.Rule;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.kohsuke.stapler.DataBoundConstructor;
@@ -65,15 +76,32 @@ public void configRoundTrip() throws Exception {
assertEquals(MockFactory.class, projectFactories.get(0).getClass());
assertEquals(MockFactory.class, projectFactories.get(1).getClass());
}
@TestExtension("configRoundTrip")

@Test

This comment has been minimized.

Copy link
@jglick

jglick Dec 4, 2015

Member

🐜 missing @Issue

@Issue("JENKINS-31516")
public void indexChildrenOnOrganizationFolderIndex() throws Exception {
OrganizationFolder top = r.jenkins.createProject(OrganizationFolder.class, "top");
List<MultiBranchProjectFactory> projectFactories = top.getProjectFactories();
projectFactories.add(new MockFactory());
top.getNavigators().add(new SingleSCMNavigator("stuff", Collections.<SCMSource>singletonList(new SingleSCMSource("id", "stuffy", new NullSCM()))));
top = r.configRoundtrip(top);

RingBufferLogHandler logs = createJULTestHandler(); // switch to the mock log handler

top.setDescription("Org folder test");
top = r.configRoundtrip(top);
waitForLogFileMessage("Indexing multibranch project: stuff", logs);

This comment has been minimized.

Copy link
@jglick

jglick Dec 4, 2015

Member

🐜 I think rather than waiting for log messages, you can call getIndexing().getTimestamp() and compare to the original.

This comment has been minimized.

Copy link
@amuniz

amuniz Dec 4, 2015

Author Member

I think it is worth to keep it as I found this pattern useful in other tests when there was no other way to check for something happening.

}

@TestExtension
public static class ConfigRoundTripDescriptor extends MockFactoryDescriptor {}

public static class MockFactory extends MultiBranchProjectFactory {
@DataBoundConstructor
public MockFactory() {}
@Override
public MultiBranchProject<?, ?> createProject(ItemGroup<?> parent, String name, List<? extends SCMSource> scmSources, Map<String,Object> attributes, TaskListener listener) throws IOException, InterruptedException {
return null;
return new MultiBranchImpl(parent, name);
}
}
static abstract class MockFactoryDescriptor extends MultiBranchProjectFactoryDescriptor {
@@ -90,4 +118,30 @@ public String getDisplayName() {
}
}

private RingBufferLogHandler createJULTestHandler() throws SecurityException, IOException {
RingBufferLogHandler handler = new RingBufferLogHandler();
SimpleFormatter formatter = new SimpleFormatter();
handler.setFormatter(formatter);
Logger logger = Logger.getLogger(MultiBranchImpl.class.getName());
logger.addHandler(handler);
return handler;
}

private void waitForLogFileMessage(String string, RingBufferLogHandler logs) throws IOException, InterruptedException {
File rootDir = r.jenkins.getRootDir();
synchronized (rootDir) {
int limit = 0;
while (limit < 5) {
rootDir.wait(1000);

This comment has been minimized.

Copy link
@jglick

jglick Dec 4, 2015

Member

Huh?? Who is notifying a File?

This comment has been minimized.

Copy link
@amuniz

amuniz Dec 4, 2015

Author Member

Nobody, it just waits for 1 second (5 in total) for the message to appear, then returns or assert unconditionally.

This comment has been minimized.

Copy link
@jglick

jglick Dec 4, 2015

Member

🐜 So why not use Thread.sleep?

for (LogRecord r : logs.getView()) {
if (r.getMessage().contains(string)) {
return;
}
}
limit++;
}
}
Assert.assertTrue("Expected log not found: " + string, false);
}

}
@@ -29,6 +29,7 @@

import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;

import hudson.Extension;
import hudson.model.FreeStyleBuild;
@@ -45,8 +46,9 @@

public class MultiBranchImpl extends MultiBranchProject<FreeStyleProject, FreeStyleBuild> {

private static final Logger LOGGER = Logger.getLogger(MultiBranchImpl.class.getName());

protected MultiBranchImpl(ItemGroup parent, String name) {
public MultiBranchImpl(ItemGroup parent, String name) {
super(parent, name);
}

@@ -55,16 +57,19 @@ protected MultiBranchImpl(ItemGroup parent, String name) {
return new BranchProjectFactoryImpl();
}

@Override
public boolean scheduleBuild() {
LOGGER.info("Indexing multibranch project: " + getDisplayName());
return super.scheduleBuild();
}

public static class BranchProjectFactoryImpl extends BranchProjectFactory<FreeStyleProject, FreeStyleBuild> {

@Override
public FreeStyleProject newInstance(Branch branch) {
FreeStyleProject job = new FreeStyleProject(getOwner(), branch.getName());
FreeStyleProject spied = spy(job);
// Do nothing.. Running the actual build is not desired/required (and not possible) in this tests.
when(spied.scheduleBuild()).thenReturn(false);
setBranch(spied, branch);
return spied;
setBranch(job, branch);
return job;
}

@Override
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.