annotate tests/test-hup.t @ 20742:3681de20b0a7

parsers: fail fast if Python has wrong minor version (issue4110) This change causes an informative ImportError to be raised when importing the parsers extension module if the minor version of the currently-running Python interpreter doesn't match that of the Python used when compiling the extension module. This change also exposes a parsers.versionerrortext constant in the C implementation of the module. Its presence can be used to determine whether this behavior is present in a version of the module. The value of the constant is the leading text of the ImportError raised and is set to "Python minor version mismatch". Here is an example of what the new error looks like: Traceback (most recent call last): File "test.py", line 1, in <module> import mercurial.parsers ImportError: Python minor version mismatch: The Mercurial extension modules were compiled with Python 2.7.6, but Mercurial is currently using Python with sys.hexversion=33883888: Python 2.5.6 (r256:88840, Nov 18 2012, 05:37:10) [GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] at: /opt/local/Library/Frameworks/Python.framework/Versions/2.5/Resources/ Python.app/Contents/MacOS/Python The reason for raising an error in this scenario is that Python's C API is known not to be compatible from minor version to minor version, even if sys.api_version is the same. See for example this Python bug report about incompatibilities between 2.5 and 2.6+: http://bugs.python.org/issue8118 These incompatibilities can cause Mercurial to break in mysterious, unforeseen ways. For example, when Mercurial compiled with Python 2.7 was run with 2.5, the following crash occurred when running "hg status": http://bz.selenic.com/show_bug.cgi?id=4110 After this crash was fixed, running with Python 2.5 no longer crashes, but the following puzzling behavior still occurs: $ hg status ... File ".../mercurial/changelog.py", line 123, in __init__ revlog.revlog.__init__(self, opener, "00changelog.i") File ".../mercurial/revlog.py", line 251, in __init__ d = self._io.parseindex(i, self._inline) File ".../mercurial/revlog.py", line 158, in parseindex index, cache = parsers.parse_index2(data, inline) TypeError: data is not a string which can be reproduced more simply with: import mercurial.parsers as parsers parsers.parse_index2("", True) Both the crash and the TypeError occurred because the Python C API's PyString_Check() returns the wrong value when the C header files from Python 2.7 are run with Python 2.5. This is an example of an incompatibility of the sort mentioned in the Python bug report above. Failing fast with an informative error message results in a better user experience in cases like the above. The information in the ImportError also simplifies troubleshooting for those on Mercurial mailing lists, the bug tracker, etc. This patch only adds the version check to parsers.c, which is sufficient to affect command-line commands like "hg status" and "hg summary". An idea for a future improvement is to move the version-checking C code to a more central location, and have it run when importing all Mercurial extension modules and not just parsers.c.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Wed, 04 Dec 2013 20:38:27 -0800
parents f64b25f147d7
children 9fae01831dea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12413
f8dc83689f19 tests: unify test-hup
Matt Mackall <mpm@selenic.com>
parents: 7080
diff changeset
1 Test hangup signal in the middle of transaction
642
5d6177b72fcc Update tests
Matt Mackall <mpm@selenic.com>
parents:
diff changeset
2
15446
c5c9ca3719f9 tests: use 'hghave serve' to guard tests that requires serve daemon management
Mads Kiilerich <mads@kiilerich.com>
parents: 14266
diff changeset
3 $ "$TESTDIR/hghave" serve fifo || exit 80
12413
f8dc83689f19 tests: unify test-hup
Matt Mackall <mpm@selenic.com>
parents: 7080
diff changeset
4 $ hg init
f8dc83689f19 tests: unify test-hup
Matt Mackall <mpm@selenic.com>
parents: 7080
diff changeset
5 $ mkfifo p
16342
7e24d34837a9 tests: make test-hup more race-proof
Matt Mackall <mpm@selenic.com>
parents: 16299
diff changeset
6 $ hg serve --stdio < p 1>out 2>&1 &
12413
f8dc83689f19 tests: unify test-hup
Matt Mackall <mpm@selenic.com>
parents: 7080
diff changeset
7 $ P=$!
16299
853ffcafecfa tests: remove sleep/startup/shutdown races from test-hup
Matt Mackall <mpm@selenic.com>
parents: 15455
diff changeset
8
853ffcafecfa tests: remove sleep/startup/shutdown races from test-hup
Matt Mackall <mpm@selenic.com>
parents: 15455
diff changeset
9 Do test while holding fifo open
853ffcafecfa tests: remove sleep/startup/shutdown races from test-hup
Matt Mackall <mpm@selenic.com>
parents: 15455
diff changeset
10
853ffcafecfa tests: remove sleep/startup/shutdown races from test-hup
Matt Mackall <mpm@selenic.com>
parents: 15455
diff changeset
11 $ (
853ffcafecfa tests: remove sleep/startup/shutdown races from test-hup
Matt Mackall <mpm@selenic.com>
parents: 15455
diff changeset
12 > echo lock
853ffcafecfa tests: remove sleep/startup/shutdown races from test-hup
Matt Mackall <mpm@selenic.com>
parents: 15455
diff changeset
13 > echo addchangegroup
16364
f64b25f147d7 tests: avoid test-hup hanging on AIX
Jim Hague <jim.hague@acm.org>
parents: 16344
diff changeset
14 > while [ ! -s .hg/store/journal ]; do sleep 0; done
16299
853ffcafecfa tests: remove sleep/startup/shutdown races from test-hup
Matt Mackall <mpm@selenic.com>
parents: 15455
diff changeset
15 > kill -HUP $P
853ffcafecfa tests: remove sleep/startup/shutdown races from test-hup
Matt Mackall <mpm@selenic.com>
parents: 15455
diff changeset
16 > ) > p
16342
7e24d34837a9 tests: make test-hup more race-proof
Matt Mackall <mpm@selenic.com>
parents: 16299
diff changeset
17
16344
fb765286f2f9 tests: avoid zombie lockup with test-hup
Matt Mackall <mpm@selenic.com>
parents: 16342
diff changeset
18 $ wait
16342
7e24d34837a9 tests: make test-hup more race-proof
Matt Mackall <mpm@selenic.com>
parents: 16299
diff changeset
19 $ cat out
12413
f8dc83689f19 tests: unify test-hup
Matt Mackall <mpm@selenic.com>
parents: 7080
diff changeset
20 0
f8dc83689f19 tests: unify test-hup
Matt Mackall <mpm@selenic.com>
parents: 7080
diff changeset
21 0
f8dc83689f19 tests: unify test-hup
Matt Mackall <mpm@selenic.com>
parents: 7080
diff changeset
22 adding changesets
f8dc83689f19 tests: unify test-hup
Matt Mackall <mpm@selenic.com>
parents: 7080
diff changeset
23 transaction abort!
f8dc83689f19 tests: unify test-hup
Matt Mackall <mpm@selenic.com>
parents: 7080
diff changeset
24 rollback completed
f8dc83689f19 tests: unify test-hup
Matt Mackall <mpm@selenic.com>
parents: 7080
diff changeset
25 killed!
16299
853ffcafecfa tests: remove sleep/startup/shutdown races from test-hup
Matt Mackall <mpm@selenic.com>
parents: 15455
diff changeset
26
12413
f8dc83689f19 tests: unify test-hup
Matt Mackall <mpm@selenic.com>
parents: 7080
diff changeset
27 $ echo .hg/* .hg/store/*
15455
c6f87bdab2a1 phases: add rollback support
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15446
diff changeset
28 .hg/00changelog.i .hg/journal.bookmarks .hg/journal.branch .hg/journal.desc .hg/journal.dirstate .hg/requires .hg/store .hg/store/00changelog.i .hg/store/00changelog.i.a .hg/store/journal.phaseroots