From 54c2a46f1b869ecee866c653177723855a36adde Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Tue, 29 Oct 2024 16:19:42 -0700 Subject: [PATCH] t: cover flow control Problem: There is no coverage to ensure that stdin flow control truly works with flux-exec. Add a test to t0005-exec.t that sends a 50 meg file while only using a 4K buffer. A buffer overflow would almost certainly happen if flow control was not working. --- t/t0005-exec.t | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/t/t0005-exec.t b/t/t0005-exec.t index 41ed8d941c2a..d59b5fd94c23 100755 --- a/t/t0005-exec.t +++ b/t/t0005-exec.t @@ -250,6 +250,56 @@ test_expect_success 'stdin redirect from /dev/null works with -n' ' test_expect_code 0 run_timeout 10 flux exec -n -r0-3 cat ' +test_expect_success 'create large file for tests' ' + dd if=/dev/urandom of=50Mfile bs=5M count=10 +' + +test_expect_success 'create test script to redirect stdin to a file' ' + cat <<-EOT >stdin2file && + #!/bin/bash + rank=\$(flux getattr rank) + dd of=cpy.\$rank + EOT + chmod +x stdin2file +' + +# piping a 50M file using a 4K buffer should overflow if flow control +# is not functioning correctly +test_expect_success 'stdin flow control works (1 rank)' ' + cat 50Mfile | flux exec -r 0 --setopt=stdin_BUFSIZE=4096 ./stdin2file && + cmp 50Mfile cpy.0 && + rm cpy.0 +' + +test_expect_success 'stdin flow control works (all ranks)' ' + cat 50Mfile | flux exec -r 0-3 --setopt=stdin_BUFSIZE=4096 ./stdin2file && + cmp 50Mfile cpy.0 && + cmp 50Mfile cpy.1 && + cmp 50Mfile cpy.2 && + cmp 50Mfile cpy.3 && + rm cpy.* +' + +test_expect_success 'create test script to redirect stdin to a file, one rank exits early' ' + cat <<-EOT >stdin2file && + #!/bin/bash + rank=\$(flux getattr rank) + if test \$rank -ne 0; then + dd of=cpy.\$rank + fi + EOT + chmod +x stdin2file +' + +test_expect_success 'stdin flow control works (all ranks, one rank will exit early)' ' + cat 50Mfile | flux exec -r 0-3 --setopt=stdin_BUFSIZE=4096 ./stdin2file && + test_must_fail ls cpy.0 && + cmp 50Mfile cpy.1 && + cmp 50Mfile cpy.2 && + cmp 50Mfile cpy.3 && + rm cpy.* +' + test_expect_success 'stdin broadcast -- multiple lines' ' dd if=/dev/urandom bs=1024 count=4 | base64 >expected && cat expected | run_timeout 10 flux exec -l -r0-3 cat >output &&