annotate tests/testlib/persistent-nodemap-race-ext.py @ 52143:dc97e8670dec stable 6.9rc0

doc: register the `config-doc` rst directive This was making the build fail because the directive was unknown.
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 28 Oct 2024 16:25:23 +0100
parents 805d4a462abb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50304
805d4a462abb py3: fix for Python 3.12 emitting SyntaxWarning on invalid escape sequences
Mads Kiilerich <mads@kiilerich.com>
parents: 48875
diff changeset
1 r"""Create the race condition for issue6554
48038
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
3 The persistent nodemap issues had an issue where a second writer could
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
4 overwrite the data that a previous write just wrote. The would break the append
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
5 only garantee of the persistent nodemap and could confuse reader. This
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
6 extensions create all the necessary synchronisation point to the race condition
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
7 to happen.
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
8
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
9 It involves 3 process <LEFT> (a writer) <RIGHT> (a writer) and <READER>
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
10
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
11 [1] <LEFT> take the lock and start a transaction
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
12 [2] <LEFT> updated `00changelog.i` with the new data
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
13 [3] <RIGHT> reads:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
14 - the new changelog index `00changelog.i`
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
15 - the old `00changelog.n`
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
16 [4] <LEFT> update the persistent nodemap:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
17 - writing new data from the last valid offset
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
18 - updating the docket (00changelog.n)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
19 [5] <LEFT> release the lock
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
20 [6] <RIGHT> grab the lock and run `repo.invalidate`
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
21 [7] <READER> reads:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
22 - the changelog index after <LEFT> write
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
23 - the nodemap docket after <LEFT> write
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
24 [8] <RIGHT> reload the changelog since `00changelog.n` changed
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
25 /!\ This is the faulty part in issue 6554, the outdated docket is kept
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
26 [9] <RIGHT> write:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
27 - the changelog index (00changelog.i)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
28 - the nodemap data (00changelog*.nd)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
29 /!\ if the outdated docket is used, the write starts from the same ofset
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
30 /!\ as in [4], overwriting data that <LEFT> wrote in step [4].
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
31 - the nodemap docket (00changelog.n)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
32 [10] <READER> reads the nodemap data from `00changelog*.nd`
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
33 /!\ if step [9] was wrong, the data matching the docket that <READER>
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
34 /!\ loaded have been overwritten and the expected root-nodes is no longer
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
35 /!\ valid.
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
36 """
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
37
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
38
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
39 import os
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
40
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
41 from mercurial.revlogutils.constants import KIND_CHANGELOG
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
42
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
43 from mercurial import (
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
44 changelog,
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
45 encoding,
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
46 extensions,
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
47 localrepo,
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
48 node,
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
49 pycompat,
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
50 registrar,
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
51 testing,
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
52 util,
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
53 )
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
54
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
55 from mercurial.revlogutils import (
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
56 nodemap as nodemaputil,
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
57 )
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
58
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
59 configtable = {}
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
60 configitem = registrar.configitem(configtable)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
61
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
62 configitem(b'devel', b'nodemap-race.role', default=None)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
63
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
64 cmdtable = {}
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
65 command = registrar.command(cmdtable)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
66
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
67 LEFT = b'left'
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
68 RIGHT = b'right'
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
69 READER = b'reader'
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
70
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
71 SYNC_DIR = os.path.join(encoding.environ[b'TESTTMP'], b'sync-files')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
72
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
73 # mark the end of step [1]
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
74 FILE_LEFT_LOCKED = os.path.join(SYNC_DIR, b'left-locked')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
75 # mark that step [3] is ready to run.
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
76 FILE_RIGHT_READY_TO_LOCK = os.path.join(SYNC_DIR, b'right-ready-to-lock')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
77
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
78 # mark the end of step [2]
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
79 FILE_LEFT_CL_DATA_WRITE = os.path.join(SYNC_DIR, b'left-data')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
80 # mark the end of step [4]
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
81 FILE_LEFT_CL_NODEMAP_WRITE = os.path.join(SYNC_DIR, b'left-nodemap')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
82 # mark the end of step [3]
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
83 FILE_RIGHT_CL_NODEMAP_READ = os.path.join(SYNC_DIR, b'right-nodemap')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
84 # mark that step [9] is read to run
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
85 FILE_RIGHT_CL_NODEMAP_PRE_WRITE = os.path.join(
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
86 SYNC_DIR, b'right-pre-nodemap-write'
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
87 )
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
88 # mark that step [9] has run.
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
89 FILE_RIGHT_CL_NODEMAP_POST_WRITE = os.path.join(
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
90 SYNC_DIR, b'right-post-nodemap-write'
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
91 )
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
92 # mark that step [7] is ready to run
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
93 FILE_READER_READY = os.path.join(SYNC_DIR, b'reader-ready')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
94 # mark that step [7] has run
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
95 FILE_READER_READ_DOCKET = os.path.join(SYNC_DIR, b'reader-read-docket')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
96
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
97
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
98 def _print(*args, **kwargs):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
99 print(*args, **kwargs)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
100
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
101
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
102 def _role(repo):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
103 """find the role associated with the process"""
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
104 return repo.ui.config(b'devel', b'nodemap-race.role')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
105
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
106
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
107 def wrap_changelog_finalize(orig, cl, tr):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
108 """wrap the update of `00changelog.i` during transaction finalization
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
109
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
110 This is useful for synchronisation before or after the file is updated on disk.
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
111 """
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
112 role = getattr(tr, '_race_role', None)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
113 if role == RIGHT:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
114 print('right ready to write, waiting for reader')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
115 testing.wait_file(FILE_READER_READY)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
116 testing.write_file(FILE_RIGHT_CL_NODEMAP_PRE_WRITE)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
117 testing.wait_file(FILE_READER_READ_DOCKET)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
118 print('right proceeding with writing its changelog index and nodemap')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
119 ret = orig(cl, tr)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
120 print("finalized changelog write")
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
121 if role == LEFT:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
122 testing.write_file(FILE_LEFT_CL_DATA_WRITE)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
123 return ret
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
124
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
125
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
126 def wrap_persist_nodemap(orig, tr, revlog, *args, **kwargs):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
127 """wrap the update of `00changelog.n` and `*.nd` during tr finalization
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
128
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
129 This is useful for synchronisation before or after the files are updated on
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
130 disk.
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
131 """
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
132 is_cl = revlog.target[0] == KIND_CHANGELOG
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
133 role = getattr(tr, '_race_role', None)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
134 if is_cl:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
135 if role == LEFT:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
136 testing.wait_file(FILE_RIGHT_CL_NODEMAP_READ)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
137 if is_cl:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
138 print("persisting changelog nodemap")
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
139 print(" new data start at", revlog._nodemap_docket.data_length)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
140 ret = orig(tr, revlog, *args, **kwargs)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
141 if is_cl:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
142 print("persisted changelog nodemap")
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
143 print_nodemap_details(revlog)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
144 if role == LEFT:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
145 testing.write_file(FILE_LEFT_CL_NODEMAP_WRITE)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
146 elif role == RIGHT:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
147 testing.write_file(FILE_RIGHT_CL_NODEMAP_POST_WRITE)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
148 return ret
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
149
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
150
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
151 def print_nodemap_details(cl):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
152 """print relevant information about the nodemap docket currently in memory"""
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
153 dkt = cl._nodemap_docket
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
154 print('docket-details:')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
155 if dkt is None:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
156 print(' <no-docket>')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
157 return
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
158 print(' uid: ', pycompat.sysstr(dkt.uid))
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
159 print(' actual-tip: ', cl.tiprev())
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
160 print(' tip-rev: ', dkt.tip_rev)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
161 print(' data-length:', dkt.data_length)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
162
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
163
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
164 def wrap_persisted_data(orig, revlog):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
165 """print some information about the nodemap information we just read
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
166
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
167 Used by the <READER> process only.
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
168 """
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
169 ret = orig(revlog)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
170 if ret is not None:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
171 docket, data = ret
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
172 file_path = nodemaputil._rawdata_filepath(revlog, docket)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
173 file_path = revlog.opener.join(file_path)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
174 file_size = os.path.getsize(file_path)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
175 print('record-data-length:', docket.data_length)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
176 print('actual-data-length:', len(data))
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
177 print('file-actual-length:', file_size)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
178 return ret
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
179
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
180
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
181 def sync_read(orig):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
182 """used by <READER> to force the race window
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
183
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
184 This make sure we read the docker from <LEFT> while reading the datafile
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
185 after <RIGHT> write.
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
186 """
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
187 orig()
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
188 testing.write_file(FILE_READER_READ_DOCKET)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
189 print('reader: nodemap docket read')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
190 testing.wait_file(FILE_RIGHT_CL_NODEMAP_POST_WRITE)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
191
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
192
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
193 def uisetup(ui):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
194 class RacedRepo(localrepo.localrepository):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
195 def lock(self, wait=True):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
196 # make sure <RIGHT> as the "Wrong" information in memory before
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
197 # grabbing the lock
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
198 newlock = self._currentlock(self._lockref) is None
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
199 if newlock and _role(self) == LEFT:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
200 cl = self.unfiltered().changelog
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
201 print_nodemap_details(cl)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
202 elif newlock and _role(self) == RIGHT:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
203 testing.write_file(FILE_RIGHT_READY_TO_LOCK)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
204 print('nodemap-race: right side start of the locking sequence')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
205 testing.wait_file(FILE_LEFT_LOCKED)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
206 testing.wait_file(FILE_LEFT_CL_DATA_WRITE)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
207 self.invalidate(clearfilecache=True)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
208 print('nodemap-race: right side reading changelog')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
209 cl = self.unfiltered().changelog
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
210 tiprev = cl.tiprev()
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
211 tip = cl.node(tiprev)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
212 tiprev2 = cl.rev(tip)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
213 if tiprev != tiprev2:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
214 raise RuntimeError(
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
215 'bad tip -round-trip %d %d' % (tiprev, tiprev2)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
216 )
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
217 testing.write_file(FILE_RIGHT_CL_NODEMAP_READ)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
218 print('nodemap-race: right side reading of changelog is done')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
219 print_nodemap_details(cl)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
220 testing.wait_file(FILE_LEFT_CL_NODEMAP_WRITE)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
221 print('nodemap-race: right side ready to wait for the lock')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
222 ret = super(RacedRepo, self).lock(wait=wait)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
223 if newlock and _role(self) == LEFT:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
224 print('nodemap-race: left side locked and ready to commit')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
225 testing.write_file(FILE_LEFT_LOCKED)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
226 testing.wait_file(FILE_RIGHT_READY_TO_LOCK)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
227 cl = self.unfiltered().changelog
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
228 print_nodemap_details(cl)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
229 elif newlock and _role(self) == RIGHT:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
230 print('nodemap-race: right side locked and ready to commit')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
231 cl = self.unfiltered().changelog
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
232 print_nodemap_details(cl)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
233 return ret
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
234
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
235 def transaction(self, *args, **kwargs):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
236 # duck punch the role on the transaction to help other pieces of code
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
237 tr = super(RacedRepo, self).transaction(*args, **kwargs)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
238 tr._race_role = _role(self)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
239 return tr
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
240
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
241 localrepo.localrepository = RacedRepo
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
242
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
243 extensions.wrapfunction(
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
244 nodemaputil, 'persist_nodemap', wrap_persist_nodemap
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
245 )
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
246 extensions.wrapfunction(
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
247 changelog.changelog, '_finalize', wrap_changelog_finalize
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
248 )
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
249
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
250
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
251 def reposetup(ui, repo):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
252 if _role(repo) == READER:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
253 extensions.wrapfunction(
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
254 nodemaputil, 'persisted_data', wrap_persisted_data
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
255 )
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
256 extensions.wrapfunction(nodemaputil, 'test_race_hook_1', sync_read)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
257
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
258 class ReaderRepo(repo.__class__):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
259 @util.propertycache
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
260 def changelog(self):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
261 print('reader ready to read the changelog, waiting for right')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
262 testing.write_file(FILE_READER_READY)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
263 testing.wait_file(FILE_RIGHT_CL_NODEMAP_PRE_WRITE)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
264 return super(ReaderRepo, self).changelog
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
265
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
266 repo.__class__ = ReaderRepo
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
267
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
268
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
269 @command(b'check-nodemap-race')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
270 def cmd_check_nodemap_race(ui, repo):
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
271 """Run proper <READER> access in the race Windows and check nodemap content"""
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
272 repo = repo.unfiltered()
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
273 print('reader: reading changelog')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
274 cl = repo.changelog
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
275 print('reader: changelog read')
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
276 print_nodemap_details(cl)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
277 tip_rev = cl.tiprev()
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
278 tip_node = cl.node(tip_rev)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
279 print('tip-rev: ', tip_rev)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
280 print('tip-node:', node.short(tip_node).decode('ascii'))
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
281 print('node-rev:', cl.rev(tip_node))
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
282 for r in cl.revs():
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
283 n = cl.node(r)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
284 try:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
285 r2 = cl.rev(n)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
286 except ValueError as exc:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
287 print('error while checking revision:', r)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
288 print(' ', exc)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
289 return 1
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
290 else:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
291 if r2 != r:
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
292 print('revision %d is missing from the nodemap' % r)
52018f8ef020 persistent-nodemap: introduce a test to highlight possible race
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
293 return 1