Merge lp:~jelmer/brz/big-file-test into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/big-file-test
Merge into: lp:brz
Diff against target: 111 lines (+96/-0)
2 files modified
breezy/tests/blackbox/__init__.py (+1/-0)
breezy/tests/blackbox/test_big_file.py (+95/-0)
To merge this branch: bzr merge lp:~jelmer/brz/big-file-test
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+368868@code.launchpad.net

Commit message

Add some tests that use big files.

Description of the change

Add some tests with big files.

This uses rlimits to artificially restrict the available memory.

Adding files to a working tree works. Committing files currently does not and is marked as known failing.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Looks good, thanks. We did discuss a while back some means of marking tests as big/slow so they could be skipped in some circumstances, but can look at that if CI has issues.

review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/tests/blackbox/__init__.py'
2--- breezy/tests/blackbox/__init__.py 2019-06-02 03:11:13 +0000
3+++ breezy/tests/blackbox/__init__.py 2019-06-15 21:46:20 +0000
4@@ -40,6 +40,7 @@
5 'test_ancestry',
6 'test_annotate',
7 'test_bisect',
8+ 'test_big_file',
9 'test_branch',
10 'test_branches',
11 'test_break_lock',
12
13=== added file 'breezy/tests/blackbox/test_big_file.py'
14--- breezy/tests/blackbox/test_big_file.py 1970-01-01 00:00:00 +0000
15+++ breezy/tests/blackbox/test_big_file.py 2019-06-15 21:46:20 +0000
16@@ -0,0 +1,95 @@
17+# Copyright (C) 2009 Jelmer Vernooij <jelmer@jelmer.uk>
18+#
19+# This program is free software; you can redistribute it and/or modify
20+# it under the terms of the GNU General Public License as published by
21+# the Free Software Foundation; either version 2 of the License, or
22+# (at your option) any later version.
23+#
24+# This program is distributed in the hope that it will be useful,
25+# but WITHOUT ANY WARRANTY; without even the implied warranty of
26+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+# GNU General Public License for more details.
28+#
29+# You should have received a copy of the GNU General Public License
30+# along with this program; if not, write to the Free Software
31+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32+#
33+
34+"""Tests with "big" files.
35+
36+These are meant to ensure that Breezy never keeps full copies of files in
37+memory.
38+"""
39+
40+import os
41+import resource
42+
43+from breezy import (
44+ osutils,
45+ tests,
46+ )
47+from breezy.tests import (
48+ features,
49+ script,
50+ )
51+
52+BIG_FILE_SIZE = 1024 * 1024 * 500
53+BIG_FILE_CHUNK_SIZE = 1024 * 1024
54+
55+RESOURCE = resource.RLIMIT_DATA
56+LIMIT = 1024 * 1024 * 200
57+
58+
59+def make_big_file(path):
60+ blob_1mb = BIG_FILE_CHUNK_SIZE * b'\x0c'
61+ with open(path, 'wb') as f:
62+ for i in range(BIG_FILE_SIZE // BIG_FILE_CHUNK_SIZE):
63+ f.write(blob_1mb)
64+
65+
66+class TestAdd(tests.TestCaseWithTransport):
67+
68+ def writeBigFile(self, path):
69+ make_big_file(path)
70+ self.addCleanup(os.unlink, path)
71+
72+ def setUp(self):
73+ super(TestAdd, self).setUp()
74+ previous = resource.getrlimit(RESOURCE)
75+ self.addCleanup(resource.setrlimit, RESOURCE, previous)
76+ resource.setrlimit(RESOURCE, (LIMIT, -1))
77+
78+ def test_allocate(self):
79+ def allocate():
80+ "." * BIG_FILE_SIZE
81+ self.assertRaises(MemoryError, allocate)
82+
83+ def test_add(self):
84+ tree = self.make_branch_and_tree('tree')
85+ self.writeBigFile(os.path.join(tree.basedir, 'testfile'))
86+ tree.add('testfile')
87+
88+ def test_make_file_big(self):
89+ self.knownFailure('commit keeps entire files in memory')
90+ tree = self.make_branch_and_tree('tree')
91+ self.build_tree(['tree/testfile'])
92+ tree.add('testfile')
93+ tree.commit('add small file')
94+ self.writeBigFile(os.path.join(tree.basedir, 'testfile'))
95+ tree.commit('small files get big')
96+ self.knownFailure('commit keeps entire files in memory')
97+
98+ def test_commit(self):
99+ self.knownFailure('commit keeps entire files in memory')
100+ tree = self.make_branch_and_tree('tree')
101+ self.writeBigFile(os.path.join(tree.basedir, 'testfile'))
102+ tree.add('testfile')
103+ tree.commit('foo')
104+
105+ def test_clone(self):
106+ self.knownFailure('commit keeps entire files in memory')
107+ tree = self.make_branch_and_tree('tree')
108+ self.writeBigFile(os.path.join(tree.basedir, 'testfile'))
109+ tree.add('testfile')
110+ tree.commit('foo')
111+ tree.clone.sprout('newtree')

Subscribers

People subscribed via source and target branches