Skip to content

Commit eca5316

Browse files
committed
add tests for quota behavior
1 parent c174623 commit eca5316

File tree

7 files changed

+107
-1
lines changed

7 files changed

+107
-1
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
2727
- name: Run tests
2828
run: |
29+
# github runner kernel for some reason doesn't have ext4 quota
30+
# support, but does have tmpfs quotas
31+
export TEST_QUOTAS=tmpfs
2932
docker compose -p cms -f docker/docker-compose.test.yml run --rm testcms
3033
3134
- name: Upload test results to Codecov

cmstestsuite/Tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# You should have received a copy of the GNU Affero General Public License
2121
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2222

23+
import os
24+
2325
import cmstestsuite.tasks.batch_and_output as batch_and_output
2426
import cmstestsuite.tasks.batch_fileio as batch_fileio
2527
import cmstestsuite.tasks.batch_fileio_managed as batch_fileio_managed
@@ -464,3 +466,16 @@
464466
checks=[CheckOverallScore(0, 100)]),
465467

466468
]
469+
470+
# TODO figure out a better way to enable/disable this.........
471+
if os.environ.get('TEST_QUOTAS', '') != '':
472+
ALL_TESTS += [
473+
Test('write-many-files',
474+
task=batch_fileio, filenames=['write-many-files.%l'],
475+
languages=(LANG_C,),
476+
checks=[CheckOverallScore(100, 100)]),
477+
Test('write-big-file-quota',
478+
task=batch_fileio, filenames=['write-big-file-quota.%l'],
479+
languages=(LANG_C,),
480+
checks=[CheckOverallScore(100, 100)])
481+
]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
#include <errno.h>
3+
#include <stddef.h>
4+
#include <stdio.h>
5+
#include <stdlib.h>
6+
#include <unistd.h>
7+
8+
int main() {
9+
int n, i;
10+
FILE* in = fopen("input.txt", "r");
11+
fscanf(in, "%d", &n);
12+
13+
FILE* temp = fopen("temp.txt", "w");
14+
// The quota is set to 64MB, so this should fail.
15+
int size = 65*1024*1024;
16+
char* buf = calloc(size, 1);
17+
size_t res = fwrite(buf, 1, size, temp);
18+
int write_error = errno;
19+
fclose(temp);
20+
// Clean up the temporary file, so that we have space for output.txt
21+
unlink("temp.txt");
22+
FILE* out = fopen("output.txt", "w");
23+
24+
if (res < size && write_error == EDQUOT) {
25+
fprintf(out, "correct %d\n", n);
26+
return 0;
27+
} else {
28+
fprintf(out, "incorrect %d\n%d", n, write_error);
29+
return 0;
30+
}
31+
}

cmstestsuite/code/write-big-fileio.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
/* First we create a huge file in output.txt (2 GB). If the check on
99
file size is enforced, the write fails and we write a wrong
10-
output. Otherwise we write correct output. */
10+
output. Otherwise we write correct output.
11+
12+
Note that since the file is sparse, it doesn't use up much real disk
13+
space, and thus won't hit the disk quota (if that is configured).
14+
*/
1115

1216
int main() {
1317
int n, i;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <errno.h>
2+
#include <stdio.h>
3+
4+
int main() {
5+
int n, i;
6+
FILE* in = fopen("input.txt", "r");
7+
fscanf(in, "%d", &n);
8+
fclose(in);
9+
10+
FILE* out = fopen("output.txt", "w");
11+
12+
for(i = 0; i < 1025; i++) {
13+
char outname[32];
14+
sprintf(outname, "out_%d.txt", i);
15+
FILE* f = fopen(outname, "w");
16+
if(!f && errno == EDQUOT) {
17+
break;
18+
}
19+
if(f) fclose(f);
20+
}
21+
22+
if (i >= 1000 && i < 1025) {
23+
fprintf(out, "correct %d\n", n);
24+
return 0;
25+
} else {
26+
fprintf(out, "incorrect %d\n", n);
27+
return 0;
28+
}
29+
}

docker/_cms-test-internal.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,29 @@ dropdb --host=testdb --username=postgres cmsdbfortesting
1313
createdb --host=testdb --username=postgres cmsdbfortesting
1414
cmsInitDB
1515

16+
if [ -n $TEST_QUOTAS ]; then
17+
sed -i 's/#fs_quota/fs_quota/' /home/cmsuser/cms/etc/cms-testdb.toml
18+
# Some platforms only support quotas on ext4, some only support them
19+
# on tmpfs. So pick the filesystem accordingly.
20+
case $TEST_QUOTAS in
21+
ext4)
22+
# 5 times the disk quota: the test runs up to 4 workers
23+
# concurrently; this makes sure they can't get spurious failures
24+
# from running out of disk space
25+
fallocate -l 320M ~/boxfs.img
26+
mkfs.ext4 -O quota ~/boxfs.img
27+
sudo mount -o loop,usrquota ~/boxfs.img /var/lib/isolate
28+
;;
29+
tmpfs)
30+
sudo mount -o usrquota -t tmpfs tmpfs /var/lib/isolate
31+
;;
32+
*)
33+
echo "Bad TEST_QUOTAS value (expected ext4 or tmpfs)" >&2
34+
exit 1
35+
;;
36+
esac
37+
fi
38+
1639
cmsRunFunctionalTests -v --coverage codecov/functionaltests.xml
1740
FUNC=$?
1841

docker/docker-compose.test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ services:
1414
# - https://github.com/pytest-dev/pytest/issues/7443
1515
# - https://github.com/actions/runner/issues/241
1616
PYTEST_ADDOPTS: --color=yes
17+
TEST_QUOTAS: ${TEST_QUOTAS-ext4}
1718
volumes:
1819
- "../codecov:/home/cmsuser/src/codecov"
1920
privileged: true

0 commit comments

Comments
 (0)