-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Shortlog strip console notes #4905
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
Changes from all commits
8cd5ae9
857a2ac
f15c856
4a1f969
bd4d86e
be6cd7a
db7f231
014b187
7c79230
2e71002
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -65,6 +65,7 @@ | |||||
| import hudson.util.ProcessTree; | ||||||
| import hudson.util.XStream2; | ||||||
|
|
||||||
| import java.io.BufferedInputStream; | ||||||
| import java.io.ByteArrayInputStream; | ||||||
| import java.io.File; | ||||||
| import java.io.IOException; | ||||||
|
|
@@ -1538,7 +1539,19 @@ public Collection<Fingerprint> getBuildFingerprints() { | |||||
| * @since 1.349 | ||||||
| */ | ||||||
| public void writeLogTo(long offset, @NonNull XMLOutput out) throws IOException { | ||||||
| getLogText().writeHtmlTo(offset, out.asWriter()); | ||||||
| long start = offset; | ||||||
| if (offset > 0) { | ||||||
| try (BufferedInputStream bufferedInputStream = new BufferedInputStream(getLogInputStream())) { | ||||||
| if (offset == bufferedInputStream.skip(offset)) { | ||||||
| int r; | ||||||
| do { | ||||||
| r = bufferedInputStream.read(); | ||||||
| start = (r == -1)? 0 : start + 1; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it will print the entire log if we hit the end of the stream, which defeats purpose of
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code change is not clear to me. My idea was to advance the This immediately breaks 2 tests which I think are valid use cases. |
||||||
| } while (r != -1 && r != '\n'); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| getLogText().writeHtmlTo(start, out.asWriter()); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,9 +24,8 @@ | |
|
|
||
| package hudson.model; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.File; | ||
| import java.io.PrintWriter; | ||
| import java.io.*; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Set; | ||
|
|
@@ -40,16 +39,21 @@ | |
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
| import hudson.console.AnnotatedLargeText; | ||
| import jenkins.model.Jenkins; | ||
| import org.apache.commons.jelly.XMLOutput; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.rules.TemporaryFolder; | ||
| import org.jvnet.hudson.test.Issue; | ||
| import org.jvnet.localizer.LocaleProvider; | ||
| import org.kohsuke.stapler.framework.io.ByteBuffer; | ||
| import org.mockito.Mockito; | ||
|
|
||
|
|
||
| public class RunTest { | ||
| private static final String SAMPLE_BUILD_OUTPUT = "Sample build output abc123.\n"; | ||
|
|
||
| @Rule public TemporaryFolder tmp = new TemporaryFolder(); | ||
|
|
||
|
|
@@ -95,7 +99,7 @@ public String call() throws Exception { | |
| TimeZone.setDefault(origTZ); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| private List<? extends Run<?, ?>.Artifact> createArtifactList(String... paths) throws Exception { | ||
| Run r = new Run(new StubJob(), 0) {}; | ||
|
|
@@ -143,7 +147,7 @@ public Locale get() { | |
| return Locale.ENGLISH; | ||
| } | ||
| }); | ||
|
|
||
| Run r = new Run(new StubJob(), 0) {}; | ||
| assertEquals("Not started yet", r.getDurationString()); | ||
| r.onStartBuilding(); | ||
|
|
@@ -262,4 +266,50 @@ public void compareRunsFromDifferentParentsWithSameNumber() throws Exception { | |
| assertTrue(r1.compareTo(r2) != 0); | ||
| assertTrue(treeSet.size() == 2); | ||
| } | ||
|
|
||
| @Test | ||
| public void willTriggerLogToStartWithNextFullLine() throws Exception { | ||
| assertWriteLogToEquals(new String(new char[2]).replace("\0", SAMPLE_BUILD_OUTPUT) + "Finished: SUCCESS.\n", 2 * SAMPLE_BUILD_OUTPUT.length() + 10); | ||
| } | ||
|
|
||
| @Test | ||
| public void wontPushOffsetOnRenderingFromBeginning() throws Exception { | ||
| assertWriteLogToEquals(new String(new char[5]).replace("\0", SAMPLE_BUILD_OUTPUT) + "Finished: SUCCESS.\n", 0); | ||
| } | ||
|
Comment on lines
+275
to
+278
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that @Test
public void wontPushOffsetOnRenderingFromBeginningOfLine() throws Exception {
assertWriteLogToEquals(new String(new char[3]).replace("\0", SAMPLE_BUILD_OUTPUT) + "Finished: SUCCESS.\n", 2 * SAMPLE_BUILD_OUTPUT.length());
}fails: it prints 2 copies, not 3 like you might expect. This is because of a “fencepost error”: when the If this method with |
||
|
|
||
| @Test | ||
| public void willRenderNothingIfOffsetSetOnLastLine() throws Exception { | ||
| assertWriteLogToEquals("", 5 * SAMPLE_BUILD_OUTPUT.length() + 6); | ||
| } | ||
|
|
||
| private void assertWriteLogToEquals(String expectedOutput, long offset) throws Exception { | ||
| try ( | ||
| ByteBuffer buf = new ByteBuffer(); | ||
| PrintStream ps = new PrintStream(buf, true); | ||
| StringWriter writer = new StringWriter() | ||
| ) { | ||
| for (int i = 0; i < 5; i++) { | ||
| ps.print(SAMPLE_BUILD_OUTPUT); | ||
| } | ||
| ps.print("Finished: SUCCESS.\n"); | ||
|
|
||
| final Run<? extends Job<?, ?>, ? extends Run<?, ?>> r = new Run(Mockito.mock(Job.class)) { | ||
| @NonNull | ||
| @Override | ||
| public AnnotatedLargeText<?> getLogText() { | ||
| return new AnnotatedLargeText<>(buf, StandardCharsets.UTF_8, true, null); | ||
| } | ||
|
|
||
| @NonNull | ||
| @Override | ||
| public InputStream getLogInputStream() throws IOException { | ||
| return buf.newInputStream(); | ||
| } | ||
| }; | ||
| final XMLOutput xmlOutput = Mockito.mock(XMLOutput.class); | ||
| Mockito.when(xmlOutput.asWriter()).thenReturn(writer); | ||
| r.writeLogTo(offset, xmlOutput); | ||
| assertEquals(expectedOutput, writer.toString()); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a serious performance regression for Pipeline as discovered in #10515: as of jenkinsci/workflow-job-plugin#27 this method is not intended to scale well (jenkinsci/workflow-job-plugin#27 (comment)).