From b3292b541ec1feb3162a514a0493054a1a5318ab Mon Sep 17 00:00:00 2001 From: vporpo Date: Sat, 1 Oct 2022 14:45:18 -0700 Subject: smbget: Adds a rate limiting option --limit-rate in KB/s This patch implements a very simple rate limiter. It works by pausing the main download loop whenever the bytes transferred are more than what we would get with if it were transferred at the rate set by the user. Please note that this may reduce the blocksize if the limit is too small. Signed-off-by: Vasileios Porpodas Reviewed-by: Jeremy Allison Reviewed-by: Andreas Schneider Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Wed Nov 2 22:47:10 UTC 2022 on sn-devel-184 --- source3/script/tests/test_smbget.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source3/script/tests') diff --git a/source3/script/tests/test_smbget.sh b/source3/script/tests/test_smbget.sh index c1c99579a8c..2322f3af942 100755 --- a/source3/script/tests/test_smbget.sh +++ b/source3/script/tests/test_smbget.sh @@ -269,6 +269,32 @@ test_msdfs_link() return 0 } +# Tests --limit-rate. Getting the testfile (128K in size) with --limit-rate 100 +# (that is 100KB/s) should take at least 1 sec to complete. +test_limit_rate() +{ + clear_download_area + echo "$SMBGET -v -a --limit-rate 100 smb://$SERVER_IP/smbget/testfile" + time_begin=$(date +%s) + $SMBGET -v -a --limit-rate 100 smb://$SERVER_IP/smbget/testfile + if [ $? -ne 0 ]; then + echo 'ERROR: RC does not match, expected: 0' + return 1 + fi + time_end=$(date +%s) + cmp --silent $WORKDIR/testfile ./testfile + if [ $? -ne 0 ]; then + echo 'ERROR: file content does not match' + return 1 + fi + if [ $((time_end - time_begin)) -lt 1 ]; then + echo 'ERROR: It should take at least 1s to transfer 128KB with rate 100KB/s' + return 1 + fi + return 0 +} + + create_test_data pushd $TMPDIR @@ -306,6 +332,10 @@ testit "update" test_update || testit "msdfs" test_msdfs_link || failed=$((failed + 1)) + +testit "limit rate" test_limit_rate || + failed=$((failed + 1)) + clear_download_area popd # TMPDIR -- cgit v1.2.1