Finally track down that cursed read test failure

The read.fish check has a test where it limits the amount of data passed to
`read` to 8192 bytes, and verifies that fish reads exactly that amount.
This check occasionally fails on the OBS builds; it's very hard to repro a
failure locally, but I finally did it.

The amount of data written is limited via `yes` and `dd`:

    yes $line | dd bs=1024 count=(math "$fish_read_limit / 1024")

The bug is that `dd` outputs a fixed number of "blocks" where a block
corresponds to a single read. As `yes` and `dd` are running concurrently,
it may happen that `dd` performs a short read; this then counts as a single
block. So `dd` may output less than the desired amount of data.

This can be verified by removing the 2>/dev/null redirection; on a
successful run dd reports `8+0 records out`, on a failed run it reports
`7+1 records out` because one of the records was short.

Fix this by using `fullblock` so that dd will no longer count a short read
as a single block. `head` would probably be a simpler tool to use but we'll
do this for now.

Happily it's not a fish bug. No need to relnote it.
This commit is contained in:
ridiculousfish 2022-04-02 11:31:55 -07:00
parent a80e680125
commit 108fe574a0

View file

@ -192,7 +192,7 @@ set line abcdefghijklmnopqrstuvwxyz
# Ensure the `read` command terminates if asked to read too much data. The var
# should be empty. We throw away any data we read if it exceeds the limit on
# what we consider reasonable.
yes $line | dd bs=1024 count=(math "1 + $fish_read_limit / 1024") 2>/dev/null | read --null x
yes $line | dd iflag=fullblock bs=1024 count=(math "1 + $fish_read_limit / 1024") 2>/dev/null | read --null x
if test $status -ne 122
echo reading too much data did not terminate with failure status
end
@ -239,13 +239,13 @@ end
# Same as previous test but limit the amount of data fed to `read` rather than
# using the `--nchars` flag.
yes $line | dd bs=1024 count=(math "$fish_read_limit / 1024") 2>/dev/null | read --null x
yes $line | dd iflag=fullblock bs=1024 count=(math "$fish_read_limit / 1024") 2>/dev/null | read --null x
if test $status -ne 0
echo the read of the max amount of data failed unexpectedly
end
if test (string length "$x") -ne $fish_read_limit
# See how much data 'yes' produced.
set yeslen (yes $line | dd bs=1024 count=(math "$fish_read_limit / 1024") 2>/dev/null | wc -c | tr -d " \t\n\r")
set yeslen (yes $line | dd iflag=fullblock bs=1024 count=(math "$fish_read_limit / 1024") 2>/dev/null | wc -c | tr -d " \t\n\r")
echo reading the max amount of data with --nchars failed the length test. read: (string length "$x"), limit: $fish_read_limit, yes produced: $yeslen
end