-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix for #379, save() ignores write failures #380
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,11 +13,11 @@ | |
# the License. | ||
|
||
import os | ||
import sys | ||
import random | ||
from common import TestCase | ||
from annoy import AnnoyIndex | ||
|
||
|
||
class IndexTest(TestCase): | ||
def test_not_found_tree(self): | ||
i = AnnoyIndex(10) | ||
|
@@ -172,3 +172,35 @@ def test_get_n_trees(self): | |
i = AnnoyIndex(10) | ||
i.load('test/test.tree') | ||
self.assertEqual(i.get_n_trees(), 10) | ||
|
||
def test_write_failed(self): | ||
f = 40 | ||
|
||
# Build the initial index | ||
t = AnnoyIndex(f) | ||
for i in range(1000): | ||
v = [random.gauss(0, 1) for z in range(f)] | ||
t.add_item(i, v) | ||
t.build(10) | ||
|
||
if sys.platform == "linux" or sys.platform == "linux2": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
# linux | ||
try: | ||
t.save("/dev/full") | ||
self.fail("didn't get expected exception") | ||
except Exception as e: | ||
self.assertTrue(str(e).find("No space left on device") > 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Python nit: could do |
||
elif sys.platform == "darwin": | ||
volume = "FULLDISK" | ||
device = os.popen('hdiutil attach -nomount ram://64').read() | ||
os.popen('diskutil erasevolume MS-DOS %s %s' % (volume, device)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works, but I'm pretty wary of calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure a pipe would work. Might just block rather than out of disk space. I agree it is a bit wonky. Possibly we just test this on linux? Where it is clear and concise? |
||
os.popen('touch "/Volumes/%s/full"' % volume) | ||
try: | ||
t.save('/Volumes/%s/annoy.tree' % volume) | ||
self.fail("didn't get expected exception") | ||
except Exception as e: | ||
self.assertTrue(str(e).find("No space left on device") > 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
finally: | ||
os.popen("hdiutil detach %s" % device) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't think this one is really needed, could just
return false
at each point?not blocking though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored that a few times deciding if I wanted to unload or not in case of error. That is a vestige of that.