mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-29 17:28:53 +00:00
log failure properly, add test
This commit is contained in:
parent
39080852cc
commit
797932244d
@ -681,7 +681,7 @@ class Uploader(QueueMixin):
|
|||||||
return self._real_notify(opaque, path, events_mask)
|
return self._real_notify(opaque, path, events_mask)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log(u"error calling _real_notify: {}".format(e))
|
self._log(u"error calling _real_notify: {}".format(e))
|
||||||
return Failure()
|
twlog.err(Failure())
|
||||||
|
|
||||||
def _real_notify(self, opaque, path, events_mask):
|
def _real_notify(self, opaque, path, events_mask):
|
||||||
self._log("inotify event %r, %r, %r\n" % (opaque, path, ', '.join(self._inotify.humanReadableMask(events_mask))))
|
self._log("inotify event %r, %r, %r\n" % (opaque, path, ', '.join(self._inotify.humanReadableMask(events_mask))))
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
import os, sys, time
|
import os, sys, time
|
||||||
import shutil, json
|
import shutil, json
|
||||||
|
import mock
|
||||||
from os.path import join, exists
|
from os.path import join, exists
|
||||||
|
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
@ -1553,6 +1554,35 @@ class SingleMagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, Reall
|
|||||||
for item0, item1 in zip(upstatus0, upstatus1):
|
for item0, item1 in zip(upstatus0, upstatus1):
|
||||||
self.assertEqual(item0, item1)
|
self.assertEqual(item0, item1)
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def test_real_notify_failure(self):
|
||||||
|
|
||||||
|
def bad_stuff(*args, **kw):
|
||||||
|
# the function we replaced would trigger this hook, so we
|
||||||
|
# have to or things will stall
|
||||||
|
self.magicfolder.uploader._call_hook(u"foo", "inotify")
|
||||||
|
raise RuntimeError("the bad stuff")
|
||||||
|
|
||||||
|
patch_notify = mock.patch.object(
|
||||||
|
self.magicfolder.uploader,
|
||||||
|
'_real_notify',
|
||||||
|
mock.Mock(side_effect=bad_stuff),
|
||||||
|
)
|
||||||
|
with patch_notify:
|
||||||
|
path0 = os.path.join(self.local_dir, u'foo')
|
||||||
|
yield self.fileops.write(path0, 'foo\n')
|
||||||
|
|
||||||
|
# do a reactor turn; this is necessary because our "bad_stuff"
|
||||||
|
# method calls the hook (so the above 'yield' resumes) right
|
||||||
|
# *before* it raises the exception; thus, we ensure all the
|
||||||
|
# pending callbacks including the exception are processed
|
||||||
|
# before we flush the errors.
|
||||||
|
yield task.deferLater(reactor, 0, lambda: None)
|
||||||
|
errors = self.flushLoggedErrors()
|
||||||
|
|
||||||
|
self.assertEqual(1, len(errors))
|
||||||
|
self.assertIn("the bad stuff", str(errors[0]))
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_delete_and_restore(self):
|
def test_delete_and_restore(self):
|
||||||
# setup: create a file
|
# setup: create a file
|
||||||
|
Loading…
Reference in New Issue
Block a user