Mercurial > hg
annotate tests/testlib/ext-sidedata-3.py @ 46800:186c0f6fbc16
tests: ask any chg instance to terminate before looking at sqlite dbs
There are spurious errors in CI where the database is still locked, so
force the daemon to quit to get deterministic behavior. Since the kill
command itself is racy, also sleep 2s to give the server time to wake up
and exit.
Differential Revision: https://phab.mercurial-scm.org/D10244
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Sat, 20 Mar 2021 00:37:57 +0100 |
parents | ba8e508a8e69 |
children | 64cd1496bb70 |
rev | line source |
---|---|
46718
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
1 # coding: utf8 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
2 # ext-sidedata-3.py - small extension to test (differently still) the sidedata |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
3 # logic |
43040
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
4 # |
46718
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
5 # Simulates a client for a complex sidedata exchange. |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
6 # |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
7 # Copyright 2021 Raphaël Gomès <rgomes@octobus.net> |
43040
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
8 # |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
9 # This software may be used and distributed according to the terms of the |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
10 # GNU General Public License version 2 or any later version. |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
11 |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 from __future__ import absolute_import |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
13 |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 import hashlib |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
15 import struct |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
17 from mercurial import ( |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
18 extensions, |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
19 revlog, |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
20 ) |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
21 |
46718
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
22 from mercurial.revlogutils import sidedata as sidedatamod |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
23 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
24 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
25 def compute_sidedata_1(repo, revlog, rev, sidedata, text=None): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
26 sidedata = sidedata.copy() |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
27 if text is None: |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
28 text = revlog.revision(rev) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
29 sidedata[sidedatamod.SD_TEST1] = struct.pack('>I', len(text)) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
30 return sidedata |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
31 |
46046
f105c49e89cd
upgrade: split actual upgrade code away from the main module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45735
diff
changeset
|
32 |
46718
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
33 def compute_sidedata_2(repo, revlog, rev, sidedata, text=None): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
34 sidedata = sidedata.copy() |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
35 if text is None: |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
36 text = revlog.revision(rev) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
37 sha256 = hashlib.sha256(text).digest() |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
38 sidedata[sidedatamod.SD_TEST2] = struct.pack('>32s', sha256) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
39 return sidedata |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
40 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
41 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
42 def compute_sidedata_3(repo, revlog, rev, sidedata, text=None): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
43 sidedata = sidedata.copy() |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
44 if text is None: |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
45 text = revlog.revision(rev) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
46 sha384 = hashlib.sha384(text).digest() |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
47 sidedata[sidedatamod.SD_TEST3] = struct.pack('>48s', sha384) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
48 return sidedata |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43042
diff
changeset
|
49 |
43040
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
50 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43042
diff
changeset
|
51 def wrapaddrevision( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43042
diff
changeset
|
52 orig, self, text, transaction, link, p1, p2, *args, **kwargs |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43042
diff
changeset
|
53 ): |
43040
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
54 if kwargs.get('sidedata') is None: |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
55 kwargs['sidedata'] = {} |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
56 sd = kwargs['sidedata'] |
46718
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
57 sd = compute_sidedata_1(None, self, None, sd, text=text) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
58 kwargs['sidedata'] = compute_sidedata_2(None, self, None, sd, text=text) |
43040
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
59 return orig(self, text, transaction, link, p1, p2, *args, **kwargs) |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
60 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43042
diff
changeset
|
61 |
43040
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
62 def extsetup(ui): |
ba4072c0a911
sidedata: test we can successfully write sidedata
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
63 extensions.wrapfunction(revlog.revlog, 'addrevision', wrapaddrevision) |
46718
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
64 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
65 |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
66 def reposetup(ui, repo): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
67 # Sidedata keys happen to be the same as the categories, easier for testing. |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
68 for kind in (b'changelog', b'manifest', b'filelog'): |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
69 repo.register_sidedata_computer( |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
70 kind, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
71 sidedatamod.SD_TEST1, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
72 (sidedatamod.SD_TEST1,), |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
73 compute_sidedata_1, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
74 ) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
75 repo.register_sidedata_computer( |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
76 kind, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
77 sidedatamod.SD_TEST2, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
78 (sidedatamod.SD_TEST2,), |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
79 compute_sidedata_2, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
80 ) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
81 repo.register_sidedata_computer( |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
82 kind, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
83 sidedatamod.SD_TEST3, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
84 (sidedatamod.SD_TEST3,), |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
85 compute_sidedata_3, |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
86 ) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
87 repo.register_wanted_sidedata(sidedatamod.SD_TEST1) |
ba8e508a8e69
sidedata-exchange: rewrite sidedata on-the-fly whenever possible
Raphaël Gomès <rgomes@octobus.net>
parents:
46709
diff
changeset
|
88 repo.register_wanted_sidedata(sidedatamod.SD_TEST2) |