summaryrefslogtreecommitdiff
path: root/source3/script/tests
diff options
context:
space:
mode:
authorvporpo <v.porpodas@gmail.com>2022-10-01 14:45:18 -0700
committerJeremy Allison <jra@samba.org>2022-11-02 22:47:10 +0000
commitb3292b541ec1feb3162a514a0493054a1a5318ab (patch)
tree94174594e02bf526ec2ffaf9a11bd03f08932778 /source3/script/tests
parentbf446bcf612791c7fcf8284cca4061b651b7d4f6 (diff)
downloadsamba-b3292b541ec1feb3162a514a0493054a1a5318ab.tar.gz
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 <v.porpodas@gmail.com> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Wed Nov 2 22:47:10 UTC 2022 on sn-devel-184
Diffstat (limited to 'source3/script/tests')
-rwxr-xr-xsource3/script/tests/test_smbget.sh30
1 files changed, 30 insertions, 0 deletions
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