bundle2: add a test for exceptions raised during the generation process
authorPierre-Yves David <pierre-yves.david@fb.com>
Tue, 14 Oct 2014 13:23:03 -0700
changeset 23007 03f3af8f4415
parent 23006 bb1bd9ee323d
child 23008 d3137827016a
bundle2: add a test for exceptions raised during the generation process We would like exceptions raised during the generation process to be gracefully handled on the receiver side. We add a test for it. It shows that we are not doing it yet.
tests/test-bundle2-format.t
--- a/tests/test-bundle2-format.t	Wed Oct 08 02:43:51 2014 -0700
+++ b/tests/test-bundle2-format.t	Tue Oct 14 13:23:03 2014 -0700
@@ -76,6 +76,7 @@
   >           ('', 'parts', False, 'include some arbitrary parts to the bundle'),
   >           ('', 'reply', False, 'produce a reply bundle'),
   >           ('', 'pushrace', False, 'includes a check:head part with unknown nodes'),
+  >           ('', 'genraise', False, 'includes a part that raise an exception during generation'),
   >           ('r', 'rev', [], 'includes those changeset in the bundle'),],
   >          '[OUTPUTFILE]')
   > def cmdbundle2(ui, repo, path=None, **opts):
@@ -128,14 +129,22 @@
   >        bundler.newpart('test:SONG', [('randomparams', '')])
   >     if opts['parts']:
   >        bundler.newpart('test:ping')
+  >     if opts['genraise']:
+  >        def genraise():
+  >            yield 'first line\n'
+  >            raise RuntimeError('Someone set up us the bomb!')
+  >        bundler.newpart('b2x:output', data=genraise())
   > 
   >     if path is None:
   >        file = sys.stdout
   >     else:
   >         file = open(path, 'wb')
   > 
-  >     for chunk in bundler.getchunks():
-  >         file.write(chunk)
+  >     try:
+  >         for chunk in bundler.getchunks():
+  >             file.write(chunk)
+  >     except RuntimeError, exc:
+  >         raise util.Abort(exc)
   > 
   > @command('unbundle2', [], '')
   > def cmdunbundle2(ui, repo, replypath=None):
@@ -766,4 +775,28 @@
   added 0 changesets with 0 changes to 3 files
   \x00\x00\x00\x00\x00\x00 (no-eol) (esc)
 
+Check handling of exception during generation.
+----------------------------------------------
+(is currently not right)
+
+  $ hg bundle2 --genraise > ../genfailed.hg2
+  abort: Someone set up us the bomb!
+  [255]
+
+Should still be a valid bundle
+(is currently not right)
+
+  $ cat ../genfailed.hg2
+  HG2X\x00\x00\x00\x11 (esc)
+  b2x:output\x00\x00\x00\x00\x00\x00 (no-eol) (esc)
+
+And its handling on the other size raise a clean exception
+(is currently not right)
+
+  $ cat ../genfailed.hg2 | hg unbundle2
+  0 unread bytes
+  abort: stream ended unexpectedly (got 0 bytes, expected 2)
+  [255]
+
+
   $ cd ..