[PATCH 1 of 5] bundle2: add a test for exceptions raised during the generation process
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Wed Oct 15 20:18:27 UTC 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1413318183 25200
# Tue Oct 14 13:23:03 2014 -0700
# Node ID b4a0127f86b795eca57e183bebb8d19442858f82
# Parent 1acb81d10eaf811cbdbcf3006375352b4b877118
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 show that we are not
doing it yet.
diff --git a/tests/test-bundle2-format.t b/tests/test-bundle2-format.t
--- a/tests/test-bundle2-format.t
+++ b/tests/test-bundle2-format.t
@@ -75,10 +75,11 @@ Create an extension to test bundle2 API
> ('', 'unknown', False, 'include an unknown mandatory part in the bundle'),
> ('', 'unknownparams', False, 'include an unknown part parameters in the bundle'),
> ('', '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):
> """write a bundle2 container on standard ouput"""
> bundler = bundle2.bundle20(ui)
@@ -127,18 +128,26 @@ Create an extension to test bundle2 API
> bundler.newpart('test:UNKNOWN', data='some random content')
> if opts['unknownparams']:
> 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 us up 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):
> """process a bundle2 stream from stdin on the current repo"""
> try:
@@ -764,6 +773,30 @@ with reply
adding manifests
adding file changes
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 us up 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 ..
More information about the Mercurial-devel
mailing list