summaryrefslogtreecommitdiffstats
path: root/deluge/tests/test_torrent.py
diff options
context:
space:
mode:
authorCalum Lind <calumlind+deluge@gmail.com>2016-10-11 11:26:52 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2016-10-18 18:40:25 +0100
commit9dd3b1617d44d717fc8d2844d40bd61969c1a157 (patch)
treead4d29f211bf4cc5d4642ba50128c48efa6459f3 /deluge/tests/test_torrent.py
parent58835eeb2ea974962527d9848b18c6560b7ff881 (diff)
downloaddeluge-9dd3b1617d44d717fc8d2844d40bd61969c1a157.tar.gz
deluge-9dd3b1617d44d717fc8d2844d40bd61969c1a157.tar.bz2
deluge-9dd3b1617d44d717fc8d2844d40bd61969c1a157.zip
[#2889] Fixes for 'Too many files open' error
* Ensure all file descriptors are closed. Using the with statement ensures closure. * The main problem was with thousands of unclosed file desciptors from tracker_icons mkstemp. * Use a prefix 'deluge_ticon.' to identify created tracker_icon tmp files.
Diffstat (limited to 'deluge/tests/test_torrent.py')
-rw-r--r--deluge/tests/test_torrent.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/deluge/tests/test_torrent.py b/deluge/tests/test_torrent.py
index e059ae251..f477c2251 100644
--- a/deluge/tests/test_torrent.py
+++ b/deluge/tests/test_torrent.py
@@ -53,8 +53,8 @@ class TorrentTestCase(BaseTestCase):
def get_torrent_atp(self, filename):
filename = os.path.join(os.path.dirname(__file__), filename)
- e = lt.bdecode(open(filename, 'rb').read())
- info = lt.torrent_info(e)
+ with open(filename, 'rb') as _file:
+ info = lt.torrent_info(lt.bdecode(_file.read()))
atp = {"ti": info}
atp["save_path"] = os.getcwd()
atp["storage_mode"] = lt.storage_mode_t.storage_mode_sparse
@@ -118,7 +118,9 @@ class TorrentTestCase(BaseTestCase):
def test_torrent_error_data_missing(self):
options = {"seed_mode": True}
filename = os.path.join(os.path.dirname(__file__), "test_torrent.file.torrent")
- torrent_id = yield self.core.add_torrent_file(filename, base64.encodestring(open(filename).read()), options)
+ with open(filename) as _file:
+ filedump = base64.encodestring(_file.read())
+ torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
torrent = self.core.torrentmanager.torrents[torrent_id]
self.assert_state(torrent, "Seeding")
@@ -132,7 +134,9 @@ class TorrentTestCase(BaseTestCase):
def test_torrent_error_resume_original_state(self):
options = {"seed_mode": True, "add_paused": True}
filename = os.path.join(os.path.dirname(__file__), "test_torrent.file.torrent")
- torrent_id = yield self.core.add_torrent_file(filename, base64.encodestring(open(filename).read()), options)
+ with open(filename) as _file:
+ filedump = base64.encodestring(_file.read())
+ torrent_id = yield self.core.add_torrent_file(filename, filedump, options)
torrent = self.core.torrentmanager.torrents[torrent_id]
orig_state = "Paused"
@@ -175,7 +179,8 @@ class TorrentTestCase(BaseTestCase):
)
filename = os.path.join(os.path.dirname(__file__), "test_torrent.file.torrent")
- filedump = open(filename).read()
+ with open(filename) as _file:
+ filedump = _file.read()
torrent_id = yield self.core.torrentmanager.add(state=torrent_state, filedump=filedump,
resume_data=lt.bencode(resume_data))
torrent = self.core.torrentmanager.torrents[torrent_id]