Skip to content

Commit 5e845fe

Browse files
committed
Figured out how to make test reliably fail unless running with remoting patch.
1 parent 8ee0788 commit 5e845fe

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/main/java/org/jenkinsci/plugins/workflow/log/DelayBufferedOutputStream.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ void flushAndReschedule() {
9898
@SuppressWarnings("FinalizeDeclaration") // not ideal, but PhantomReference is more of a hassle
9999
@Override protected void finalize() throws Throwable {
100100
super.finalize();
101+
Thread.sleep(100); // TODO for FileLogStorageTest#remoting
101102
// Odd that this is not the default behavior for BufferedOutputStream.
102103
flush();
103104
}

src/test/java/org/jenkinsci/plugins/workflow/log/LogStorageTestBase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import hudson.console.AnnotatedLargeText;
2828
import hudson.console.HyperlinkNote;
2929
import hudson.model.TaskListener;
30+
import hudson.remoting.Channel;
3031
import hudson.remoting.VirtualChannel;
3132
import java.io.EOFException;
3233
import java.io.PrintWriter;
@@ -37,11 +38,13 @@
3738
import java.util.Random;
3839
import java.util.concurrent.Callable;
3940
import java.util.function.BiFunction;
41+
import java.util.logging.Level;
4042
import jenkins.security.MasterToSlaveCallable;
4143
import org.apache.commons.io.FileUtils;
4244
import org.apache.commons.io.output.NullOutputStream;
4345
import org.apache.commons.io.output.NullWriter;
4446
import org.apache.commons.io.output.WriterOutputStream;
47+
import static org.hamcrest.Matchers.*;
4548
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
4649
import org.jenkinsci.plugins.workflow.graph.FlowNode;
4750
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
@@ -51,6 +54,7 @@
5154
import org.junit.ClassRule;
5255
import org.junit.Test;
5356
import org.jvnet.hudson.test.JenkinsRule;
57+
import org.jvnet.hudson.test.LoggerRule;
5458

5559
/**
5660
* Foundation for compliance tests of {@link LogStorage} implementations.
@@ -63,6 +67,8 @@ public abstract class LogStorageTestBase {
6367

6468
@ClassRule public static JenkinsRule r = new JenkinsRule();
6569

70+
@ClassRule public static LoggerRule logging = new LoggerRule();
71+
6672
/** Create a new storage implementation, but potentially reusing any data initialized in the last {@link Before} setup. */
6773
protected abstract LogStorage createStorage() throws Exception;
6874

@@ -142,6 +148,7 @@ protected static void close(TaskListener listener) throws Exception {
142148
}
143149

144150
@Test public void remoting() throws Exception {
151+
logging.capture(100).record(Channel.class, Level.WARNING);
145152
LogStorage ls = createStorage();
146153
TaskListener overall = ls.overallListener();
147154
overall.getLogger().println("overall from master");
@@ -157,6 +164,7 @@ protected static void close(TaskListener listener) throws Exception {
157164
stepPos = assertStepLog("1", stepPos, "step from agent\n", true);
158165
assertEquals(overallPos, assertOverallLog(overallPos, "", true));
159166
assertEquals(stepPos, assertStepLog("1", stepPos, "", true));
167+
assertThat(logging.getMessages(), empty());
160168
}
161169
private static final class RemotePrint extends MasterToSlaveCallable<Void, Exception> {
162170
static {

0 commit comments

Comments
 (0)