X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/763e5bd313592a1c1f161b80bc07c94a49f8fb91..8dedd02357a95a0ae2c7961c8f1d0896b6311b3b:/services/fuse/tests/test_command_args.py diff --git a/services/fuse/tests/test_command_args.py b/services/fuse/tests/test_command_args.py index 600bb0fe22..a6a387789d 100644 --- a/services/fuse/tests/test_command_args.py +++ b/services/fuse/tests/test_command_args.py @@ -2,9 +2,6 @@ # # SPDX-License-Identifier: AGPL-3.0 -from __future__ import absolute_import -from __future__ import print_function -from six import assertRegex import arvados import arvados_fuse import arvados_fuse.command @@ -14,12 +11,15 @@ import io import json import llfuse import logging -import mock import os -from . import run_test_server import sys import tempfile import unittest +import resource + +from unittest import mock + +from . import run_test_server def noexit(func): """If argparse or arvados_fuse tries to exit, fail the test instead""" @@ -83,13 +83,13 @@ class MountArgsTest(unittest.TestCase): e = self.check_ent_type(arvados_fuse.StringFile, 'README') readme = e.readfrom(0, -1).decode() - assertRegex(self, readme, r'active-user@arvados\.local') - assertRegex(self, readme, r'\n$') + self.assertRegex(readme, r'active-user@arvados\.local') + self.assertRegex(readme, r'\n$') e = self.check_ent_type(arvados_fuse.StringFile, 'by_id', 'README') txt = e.readfrom(0, -1).decode() - assertRegex(self, txt, r'portable data hash') - assertRegex(self, txt, r'\n$') + self.assertRegex(txt, r'portable data hash') + self.assertRegex(txt, r'\n$') @noexit def test_by_id(self): @@ -198,7 +198,7 @@ class MountArgsTest(unittest.TestCase): with self.assertRaises(SystemExit): args = arvados_fuse.command.ArgumentParser().parse_args(['--version']) - assertRegex(self, sys.stdout.getvalue(), "[0-9]+\.[0-9]+\.[0-9]+") + self.assertRegex(sys.stdout.getvalue(), "[0-9]+\.[0-9]+\.[0-9]+") sys.stderr.close() sys.stderr = origerr sys.stdout = origout @@ -261,6 +261,50 @@ class MountArgsTest(unittest.TestCase): '--foreground', self.mntdir]) arvados_fuse.command.Mount(args) + @noexit + @mock.patch('resource.setrlimit') + @mock.patch('resource.getrlimit') + def test_default_file_cache(self, getrlimit, setrlimit): + args = arvados_fuse.command.ArgumentParser().parse_args([ + '--foreground', self.mntdir]) + self.assertEqual(args.mode, None) + getrlimit.return_value = (1024, 1048576) + self.mnt = arvados_fuse.command.Mount(args) + setrlimit.assert_called_with(resource.RLIMIT_NOFILE, (10240, 1048576)) + + @noexit + @mock.patch('resource.setrlimit') + @mock.patch('resource.getrlimit') + def test_small_file_cache(self, getrlimit, setrlimit): + args = arvados_fuse.command.ArgumentParser().parse_args([ + '--foreground', '--file-cache=256000000', self.mntdir]) + self.assertEqual(args.mode, None) + getrlimit.return_value = (1024, 1048576) + self.mnt = arvados_fuse.command.Mount(args) + setrlimit.assert_not_called() + + @noexit + @mock.patch('resource.setrlimit') + @mock.patch('resource.getrlimit') + def test_large_file_cache(self, getrlimit, setrlimit): + args = arvados_fuse.command.ArgumentParser().parse_args([ + '--foreground', '--file-cache=256000000000', self.mntdir]) + self.assertEqual(args.mode, None) + getrlimit.return_value = (1024, 1048576) + self.mnt = arvados_fuse.command.Mount(args) + setrlimit.assert_called_with(resource.RLIMIT_NOFILE, (30517, 1048576)) + + @noexit + @mock.patch('resource.setrlimit') + @mock.patch('resource.getrlimit') + def test_file_cache_hard_limit(self, getrlimit, setrlimit): + args = arvados_fuse.command.ArgumentParser().parse_args([ + '--foreground', '--file-cache=256000000000', self.mntdir]) + self.assertEqual(args.mode, None) + getrlimit.return_value = (1024, 2048) + self.mnt = arvados_fuse.command.Mount(args) + setrlimit.assert_called_with(resource.RLIMIT_NOFILE, (2048, 2048)) + class MountErrorTest(unittest.TestCase): def setUp(self): self.mntdir = tempfile.mkdtemp()