Message ID | e4ba96358b7c5d2b4148c5529a3c253dc0d1f358.1603136143.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Work around flakiness in t5500.43 | expand |
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Johannes Schindelin <johannes.schindelin@gmx.de> > > In 2b695ecd74d (t5500: count objects through stderr, not trace, > 2020-05-06) we tried to ensure that the "Total 3" message could be > grepped in Git's output, even if it sometimes got chopped up into > multiple lines in the trace machinery. > ... > The correct way to fix this is to return from `demultiplex_sideband()` > early. The caller will then write out the contents of the primary packet > and continue looping. The `scratch` buffer for incomplete sideband > messages is owned by that caller, and will continue to accumulate the > remainder(s) of those messages. The loop will only end once > `demultiplex_sideband()` returned non-zero _and_ did not indicate a > primary packet, which is the case only when we hit the `cleanup:` path, > in which we take care of flushing any unfinished sideband messages and > release the `scratch` buffer. > > To ensure that this does not get broken again, we introduce a pair of > subcommands of the `pkt-line` test helper that specifically chop up the > sideband message and squeeze a primary packet into the middle. > > Final note: The other test case touched by 2b695ecd74d (t5500: count > objects through stderr, not trace, 2020-05-06) is not affected by this > issue because the sideband machinery is not involved there. > > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> > --- Nicely explained. Do we want to also give credit to Peff for the single-liner fix here, perhaps with a suggested/helped-by trailer? > sideband.c | 2 +- > t/helper/test-pkt-line.c | 23 +++++++++++++++++++++++ > t/t0070-fundamental.sh | 6 ++++++ > 3 files changed, 30 insertions(+), 1 deletion(-) > > diff --git a/sideband.c b/sideband.c > index 0a60662fa6..a5405b9aaa 100644 > --- a/sideband.c > +++ b/sideband.c > @@ -190,7 +190,7 @@ int demultiplex_sideband(const char *me, char *buf, int len, > return 0; > case 1: > *sideband_type = SIDEBAND_PRIMARY; > - break; > + return 1; > default: > strbuf_addf(scratch, "%s%s: protocol error: bad band #%d", > scratch->len ? "\n" : "", me, band); > diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c > index 69152958e5..0bf20642be 100644 > --- a/t/helper/test-pkt-line.c > +++ b/t/helper/test-pkt-line.c > @@ -84,6 +84,25 @@ static void unpack_sideband(void) > } > } > > +static int send_split_sideband(void) > +{ > + const char *part1 = "Hello,"; > + const char *primary = "\001primary: regular output\n"; > + const char *part2 = " world!\n"; > + > + send_sideband(1, 2, part1, strlen(part1), LARGE_PACKET_MAX); > + packet_write(1, primary, strlen(primary)); > + send_sideband(1, 2, part2, strlen(part2), LARGE_PACKET_MAX); > + packet_response_end(1); > + > + return 0; > +} OK. > +static int receive_sideband(void) > +{ > + return recv_sideband("sideband: ", 0, 1); > +} > + > int cmd__pkt_line(int argc, const char **argv) > { > if (argc < 2) > @@ -95,6 +114,10 @@ int cmd__pkt_line(int argc, const char **argv) > unpack(); > else if (!strcmp(argv[1], "unpack-sideband")) > unpack_sideband(); > + else if (!strcmp(argv[1], "send-split-sideband")) > + send_split_sideband(); > + else if (!strcmp(argv[1], "receive-sideband")) > + receive_sideband(); > else > die("invalid argument '%s'", argv[1]); > > diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh > index 7b111a56fd..357201640a 100755 > --- a/t/t0070-fundamental.sh > +++ b/t/t0070-fundamental.sh > @@ -34,4 +34,10 @@ test_expect_success 'check for a bug in the regex routines' ' > test-tool regex --bug > ' > > +test_expect_success 'incomplete sideband messages are reassembled' ' > + test-tool pkt-line send-split-sideband >split-sideband && > + test-tool pkt-line receive-sideband <split-sideband 2>err && > + grep "Hello, world" err > +' > + > test_done
Hi Junio, On Tue, 20 Oct 2020, Junio C Hamano wrote: > "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com> > writes: > > > From: Johannes Schindelin <johannes.schindelin@gmx.de> > > > > In 2b695ecd74d (t5500: count objects through stderr, not trace, > > 2020-05-06) we tried to ensure that the "Total 3" message could be > > grepped in Git's output, even if it sometimes got chopped up into > > multiple lines in the trace machinery. > > ... > > The correct way to fix this is to return from `demultiplex_sideband()` > > early. The caller will then write out the contents of the primary packet > > and continue looping. The `scratch` buffer for incomplete sideband > > messages is owned by that caller, and will continue to accumulate the > > remainder(s) of those messages. The loop will only end once > > `demultiplex_sideband()` returned non-zero _and_ did not indicate a > > primary packet, which is the case only when we hit the `cleanup:` path, > > in which we take care of flushing any unfinished sideband messages and > > release the `scratch` buffer. > > > > To ensure that this does not get broken again, we introduce a pair of > > subcommands of the `pkt-line` test helper that specifically chop up the > > sideband message and squeeze a primary packet into the middle. > > > > Final note: The other test case touched by 2b695ecd74d (t5500: count > > objects through stderr, not trace, 2020-05-06) is not affected by this > > issue because the sideband machinery is not involved there. > > > > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> > > --- > > Nicely explained. Do we want to also give credit to Peff for the > single-liner fix here, perhaps with a suggested/helped-by trailer? Sure. I had not added that because I had actually come up with the fix independently in my analysis before I read Peff's reply thoroughly. But credit where credit is due: without Peff's reply, I would not have worked on the full fix and stayed with the work-around. Ciao, Dscho
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes: >> Nicely explained. Do we want to also give credit to Peff for the >> single-liner fix here, perhaps with a suggested/helped-by trailer? > > Sure. > > I had not added that because I had actually come up with the fix > independently in my analysis before I read Peff's reply thoroughly. Ah, of course, e-mails cross all the time so these things happen. Thanks, both.
diff --git a/sideband.c b/sideband.c index 0a60662fa6..a5405b9aaa 100644 --- a/sideband.c +++ b/sideband.c @@ -190,7 +190,7 @@ int demultiplex_sideband(const char *me, char *buf, int len, return 0; case 1: *sideband_type = SIDEBAND_PRIMARY; - break; + return 1; default: strbuf_addf(scratch, "%s%s: protocol error: bad band #%d", scratch->len ? "\n" : "", me, band); diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c index 69152958e5..0bf20642be 100644 --- a/t/helper/test-pkt-line.c +++ b/t/helper/test-pkt-line.c @@ -84,6 +84,25 @@ static void unpack_sideband(void) } } +static int send_split_sideband(void) +{ + const char *part1 = "Hello,"; + const char *primary = "\001primary: regular output\n"; + const char *part2 = " world!\n"; + + send_sideband(1, 2, part1, strlen(part1), LARGE_PACKET_MAX); + packet_write(1, primary, strlen(primary)); + send_sideband(1, 2, part2, strlen(part2), LARGE_PACKET_MAX); + packet_response_end(1); + + return 0; +} + +static int receive_sideband(void) +{ + return recv_sideband("sideband: ", 0, 1); +} + int cmd__pkt_line(int argc, const char **argv) { if (argc < 2) @@ -95,6 +114,10 @@ int cmd__pkt_line(int argc, const char **argv) unpack(); else if (!strcmp(argv[1], "unpack-sideband")) unpack_sideband(); + else if (!strcmp(argv[1], "send-split-sideband")) + send_split_sideband(); + else if (!strcmp(argv[1], "receive-sideband")) + receive_sideband(); else die("invalid argument '%s'", argv[1]); diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh index 7b111a56fd..357201640a 100755 --- a/t/t0070-fundamental.sh +++ b/t/t0070-fundamental.sh @@ -34,4 +34,10 @@ test_expect_success 'check for a bug in the regex routines' ' test-tool regex --bug ' +test_expect_success 'incomplete sideband messages are reassembled' ' + test-tool pkt-line send-split-sideband >split-sideband && + test-tool pkt-line receive-sideband <split-sideband 2>err && + grep "Hello, world" err +' + test_done