Skip to content
Permalink
Browse files

[JENKINS-42150] Fix locks when applying latency

- Also fix locks when applying faults
- Also fix includes check in mock impl
  • Loading branch information...
stephenc committed Feb 20, 2017
1 parent 48fc047 commit ec8b944bd3e9baaff342d2cec3964c6301123a63
@@ -184,10 +184,21 @@ public synchronized void clearFaults() {
this.faults.clear();
}

public synchronized void checkFaults(@CheckForNull String repository, @CheckForNull String branch,
public void applyLatency() throws InterruptedException {
MockLatency latency;
synchronized (this) {
latency = this.latency;
}
latency.apply();
}

public void checkFaults(@CheckForNull String repository, @CheckForNull String branch,
@CheckForNull String revision, boolean actions)
throws IOException, InterruptedException {
latency.apply();
List<MockFailure> faults;
synchronized (this) {
faults = new ArrayList<MockFailure>(this.faults);
}
for (MockFailure fault: faults) {
fault.check(repository, branch, revision, actions);
}
@@ -34,7 +34,9 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMNavigator;
import jenkins.scm.api.SCMNavigatorDescriptor;
import jenkins.scm.api.SCMNavigatorEvent;
@@ -99,12 +101,18 @@ protected String id() {

@Override
public void visitSources(@NonNull SCMSourceObserver observer) throws IOException, InterruptedException {
controller().applyLatency();
controller().checkFaults(null, null, null, false);
Set<String> includes = observer.getIncludes();
for (String name : controller().listRepositories()) {
if (!observer.isObserving()) {
return;
}
checkInterrupt();
if (includes != null && !includes.contains(name)) {
continue;
}
controller().applyLatency();
controller().checkFaults(name, null, null, false);
SCMSourceObserver.ProjectObserver po = observer.observe(name);
po.addSource(new MockSCMSource(getId() + "::" + name,
@@ -119,6 +127,7 @@ public void visitSources(@NonNull SCMSourceObserver observer) throws IOException
@CheckForNull SCMNavigatorEvent event,
@NonNull TaskListener listener)
throws IOException, InterruptedException {
controller().applyLatency();
controller().checkFaults(null, null, null, true);
List<Action> result = new ArrayList<Action>();
result.add(new MockSCMLink("organization"));
@@ -118,18 +118,21 @@ public boolean isIncludeChangeRequests() {
protected void retrieve(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHeadObserver observer,
@CheckForNull SCMHeadEvent<?> event, @NonNull TaskListener listener)
throws IOException, InterruptedException {
controller().applyLatency();
controller().checkFaults(repository, null, null, false);
Set<SCMHead> includes = observer.getIncludes();
if (includeBranches) {
for (final String branch : controller().listBranches(repository)) {
checkInterrupt();
String revision = controller().getRevision(repository, branch);
MockSCMHead head = new MockSCMHead(branch);
controller().checkFaults(repository, head.getName(), null, false);
if (includes != null && !includes.contains(head)) {
continue;
}
controller().applyLatency();
controller().checkFaults(repository, head.getName(), null, false);
if (criteria == null || criteria.isHead(new MockSCMProbe(head, revision), listener)) {
controller().applyLatency();
controller().checkFaults(repository, head.getName(), revision, false);
observer.observe(head, new MockSCMRevision(head, revision));
}
@@ -140,11 +143,13 @@ protected void retrieve(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHe
checkInterrupt();
String revision = controller().getRevision(repository, tag);
MockSCMHead head = new MockTagSCMHead(tag, controller().getTagTimestamp(repository, tag));
controller().checkFaults(repository, head.getName(), null, false);
if (includes != null && !includes.contains(head)) {
continue;
}
controller().applyLatency();
controller().checkFaults(repository, head.getName(), null, false);
if (criteria == null || criteria.isHead(new MockSCMProbe(head, revision), listener)) {
controller().applyLatency();
controller().checkFaults(repository, head.getName(), revision, false);
observer.observe(head, new MockSCMRevision(head, revision));
}
@@ -156,11 +161,13 @@ protected void retrieve(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHe
String revision = controller().getRevision(repository, "change-request/" + number);
String target = controller().getTarget(repository, number);
MockChangeRequestSCMHead head = new MockChangeRequestSCMHead(number, target);
controller().checkFaults(repository, head.getName(), null, false);
if (includes != null && !includes.contains(head)) {
continue;
}
controller().applyLatency();
controller().checkFaults(repository, head.getName(), null, false);
if (criteria == null || criteria.isHead(new MockSCMProbe(head, revision), listener)) {
controller().applyLatency();
controller().checkFaults(repository, head.getName(), revision, false);
observer.observe(head, new MockSCMRevision(head, revision));
}
@@ -179,6 +186,7 @@ public SCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) {
@Override
protected List<Action> retrieveActions(@CheckForNull SCMSourceEvent event, @NonNull TaskListener listener)
throws IOException, InterruptedException {
controller().applyLatency();
controller().checkFaults(repository, null, null, true);
List<Action> result = new ArrayList<Action>();
result.add(new MockSCMLink("source"));
@@ -201,6 +209,7 @@ public SCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) {
@CheckForNull SCMHeadEvent event,
@NonNull TaskListener listener)
throws IOException, InterruptedException {
controller().applyLatency();
controller().checkFaults(repository, revision.getHead().getName(), ((MockSCMRevision)revision).getHash(), true);
return Collections.<Action>singletonList(new MockSCMLink("revision"));
}
@@ -211,6 +220,7 @@ public SCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) {
@CheckForNull SCMHeadEvent event,
@NonNull TaskListener listener)
throws IOException, InterruptedException {
controller().applyLatency();
controller().checkFaults(repository, head.getName(), null, true);
List<Action> result = new ArrayList<Action>();
if (head instanceof MockChangeRequestSCMHead) {

0 comments on commit ec8b944

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