##// END OF EJS Templates
dirstate: check dirstate race condition around commit...
marmoute -
r51125:e5fea4f1 stable
parent child Browse files
Show More
@@ -1,143 +1,198 b''
1 ==============================================================================
1 ==============================================================================
2 Check potential race conditions between a dirstate's read and other operations
2 Check potential race conditions between a dirstate's read and other operations
3 ==============================================================================
3 ==============================================================================
4
4
5 Some commands, like `hg status`, do not need to take the wlock but need to
5 Some commands, like `hg status`, do not need to take the wlock but need to
6 access dirstate data.
6 access dirstate data.
7 Other commands might update the dirstate data while this happens.
7 Other commands might update the dirstate data while this happens.
8
8
9 This can create issues if repository data is read in the wrong order, or for
9 This can create issues if repository data is read in the wrong order, or for
10 the dirstate-v2 format where the data is contained in multiple files.
10 the dirstate-v2 format where the data is contained in multiple files.
11
11
12 This test file is meant to test various cases where such parallel operations
12 This test file is meant to test various cases where such parallel operations
13 happen and make sure the reading process behaves fine. We do so with a `hg
13 happen and make sure the reading process behaves fine. We do so with a `hg
14 status` command since it is probably the most advanced of such read-only
14 status` command since it is probably the most advanced of such read-only
15 command.
15 command.
16
16
17 It bears simililarity with `tests/test-dirstate-status-race.t ` but tests a
17 It bears simililarity with `tests/test-dirstate-status-race.t ` but tests a
18 different type of race.
18 different type of race.
19
19
20 Setup
20 Setup
21 =====
21 =====
22
22
23 $ directories="dir dir/nested dir2"
23 $ directories="dir dir/nested dir2"
24 $ first_files="dir/nested/a dir/b dir/c dir/d dir2/e f"
24 $ first_files="dir/nested/a dir/b dir/c dir/d dir2/e f"
25 $ second_files="g dir/nested/h dir/i dir/j dir2/k dir2/l dir/nested/m"
25 $ second_files="g dir/nested/h dir/i dir/j dir2/k dir2/l dir/nested/m"
26 $ extra_files="dir/n dir/o p q"
26 $ extra_files="dir/n dir/o p q"
27
27
28 $ hg init reference-repo
28 $ hg init reference-repo
29 $ cd reference-repo
29 $ cd reference-repo
30 $ mkdir -p dir/nested dir2
30 $ mkdir -p dir/nested dir2
31 $ touch -t 200001010000 $first_files $directories
31 $ touch -t 200001010000 $first_files $directories
32 $ hg commit -Aqm "recreate a bunch of files to facilitate dirstate-v2 append"
32 $ hg commit -Aqm "recreate a bunch of files to facilitate dirstate-v2 append"
33 $ touch -t 200001010010 $second_files $directories
33 $ touch -t 200001010010 $second_files $directories
34 $ hg commit -Aqm "more files to have two commit"
34 $ hg commit -Aqm "more files to have two commit"
35 $ hg log -G -v
35 $ hg log -G -v
36 @ changeset: 1:9a86dcbfb938
36 @ changeset: 1:9a86dcbfb938
37 | tag: tip
37 | tag: tip
38 | user: test
38 | user: test
39 | date: Thu Jan 01 00:00:00 1970 +0000
39 | date: Thu Jan 01 00:00:00 1970 +0000
40 | files: dir/i dir/j dir/nested/h dir/nested/m dir2/k dir2/l g
40 | files: dir/i dir/j dir/nested/h dir/nested/m dir2/k dir2/l g
41 | description:
41 | description:
42 | more files to have two commit
42 | more files to have two commit
43 |
43 |
44 |
44 |
45 o changeset: 0:4f23db756b09
45 o changeset: 0:4f23db756b09
46 user: test
46 user: test
47 date: Thu Jan 01 00:00:00 1970 +0000
47 date: Thu Jan 01 00:00:00 1970 +0000
48 files: dir/b dir/c dir/d dir/nested/a dir2/e f
48 files: dir/b dir/c dir/d dir/nested/a dir2/e f
49 description:
49 description:
50 recreate a bunch of files to facilitate dirstate-v2 append
50 recreate a bunch of files to facilitate dirstate-v2 append
51
51
52
52
53 $ hg manifest
53 $ hg manifest
54 dir/b
54 dir/b
55 dir/c
55 dir/c
56 dir/d
56 dir/d
57 dir/i
57 dir/i
58 dir/j
58 dir/j
59 dir/nested/a
59 dir/nested/a
60 dir/nested/h
60 dir/nested/h
61 dir/nested/m
61 dir/nested/m
62 dir2/e
62 dir2/e
63 dir2/k
63 dir2/k
64 dir2/l
64 dir2/l
65 f
65 f
66 g
66 g
67
67
68 Add some unknown files and refresh the dirstate
68 Add some unknown files and refresh the dirstate
69
69
70 $ touch -t 200001010020 $extra_files
70 $ touch -t 200001010020 $extra_files
71 $ hg add dir/o
71 $ hg add dir/o
72 $ hg remove dir/nested/m
72 $ hg remove dir/nested/m
73
73
74 $ hg st --config devel.dirstate.v2.data_update_mode=force-new
74 $ hg st --config devel.dirstate.v2.data_update_mode=force-new
75 A dir/o
75 A dir/o
76 R dir/nested/m
76 R dir/nested/m
77 ? dir/n
77 ? dir/n
78 ? p
78 ? p
79 ? q
79 ? q
80 $ hg debugstate
80 $ hg debugstate
81 n 644 0 2000-01-01 00:00:00 dir/b
81 n 644 0 2000-01-01 00:00:00 dir/b
82 n 644 0 2000-01-01 00:00:00 dir/c
82 n 644 0 2000-01-01 00:00:00 dir/c
83 n 644 0 2000-01-01 00:00:00 dir/d
83 n 644 0 2000-01-01 00:00:00 dir/d
84 n 644 0 2000-01-01 00:10:00 dir/i
84 n 644 0 2000-01-01 00:10:00 dir/i
85 n 644 0 2000-01-01 00:10:00 dir/j
85 n 644 0 2000-01-01 00:10:00 dir/j
86 n 644 0 2000-01-01 00:00:00 dir/nested/a
86 n 644 0 2000-01-01 00:00:00 dir/nested/a
87 n 644 0 2000-01-01 00:10:00 dir/nested/h
87 n 644 0 2000-01-01 00:10:00 dir/nested/h
88 r ?????????????????????????????????? dir/nested/m (glob)
88 r ?????????????????????????????????? dir/nested/m (glob)
89 a ?????????????????????????????????? dir/o (glob)
89 a ?????????????????????????????????? dir/o (glob)
90 n 644 0 2000-01-01 00:00:00 dir2/e
90 n 644 0 2000-01-01 00:00:00 dir2/e
91 n 644 0 2000-01-01 00:10:00 dir2/k
91 n 644 0 2000-01-01 00:10:00 dir2/k
92 n 644 0 2000-01-01 00:10:00 dir2/l
92 n 644 0 2000-01-01 00:10:00 dir2/l
93 n 644 0 2000-01-01 00:00:00 f
93 n 644 0 2000-01-01 00:00:00 f
94 n 644 0 2000-01-01 00:10:00 g
94 n 644 0 2000-01-01 00:10:00 g
95 $ hg debugstate > ../reference
95 $ hg debugstate > ../reference
96 $ cd ..
96 $ cd ..
97
97
98 Actual Testing
98 Actual Testing
99 ==============
99 ==============
100
100
101 Race with a `hg add`
101 Race with a `hg add`
102 -------------------
102 -------------------
103
103
104 $ cp -a reference-repo race-with-add
104 $ cp -a reference-repo race-with-add
105 $ cd race-with-add
105 $ cd race-with-add
106
106
107 spin a `hg status` with some caches to update
107 spin a `hg status` with some caches to update
108
108
109 $ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \
109 $ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \
110 > --config rhg.on-unsupported=abort \
110 > --config rhg.on-unsupported=abort \
111 > --config devel.sync.dirstate.pre-read-file=$TESTTMP/status-race-lock \
111 > --config devel.sync.dirstate.pre-read-file=$TESTTMP/status-race-lock \
112 > &
112 > &
113 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting
113 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting
114
114
115 Add a file
115 Add a file
116
116
117 $ hg add dir/n $d2args
117 $ hg add dir/n $d2args
118 $ touch $TESTTMP/status-race-lock
118 $ touch $TESTTMP/status-race-lock
119 $ wait
119 $ wait
120
120
121 The file should in a "added" state
121 The file should in a "added" state
122
122
123 $ hg status
123 $ hg status
124 A dir/n
124 A dir/n
125 A dir/o
125 A dir/o
126 R dir/nested/m
126 R dir/nested/m
127 ? p
127 ? p
128 ? q
128 ? q
129
129
130 The status process should return a consistent result and not crash.
130 The status process should return a consistent result and not crash.
131
131
132 $ cat $TESTTMP/status-race-lock.out
132 $ cat $TESTTMP/status-race-lock.out
133 A dir/n
133 A dir/n
134 A dir/o
134 A dir/o
135 R dir/nested/m
135 R dir/nested/m
136 ? p
136 ? p
137 ? q
137 ? q
138 $ cat $TESTTMP/status-race-lock.log
138 $ cat $TESTTMP/status-race-lock.log
139
139
140 final cleanup
140 final cleanup
141
141
142 $ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting
142 $ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting
143 $ cd ..
143 $ cd ..
144
145 Race with a `hg commit`
146 -----------------------
147
148 $ cp -a reference-repo race-with-commit
149 $ cd race-with-commit
150
151 spin a `hg status with some cache to update
152
153 $ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \
154 > --config rhg.on-unsupported=abort \
155 > --config devel.sync.dirstate.pre-read-file=$TESTTMP/status-race-lock \
156 > &
157 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting
158
159 Add a do a commit
160
161 $ hg status
162 A dir/o
163 R dir/nested/m
164 ? dir/n
165 ? p
166 ? q
167 $ hg commit -m 'racing commit'
168 $ touch $TESTTMP/status-race-lock
169 $ wait
170
171 commit was created, and status is now clean
172
173 $ hg log -GT '{node|short} {desc}\n'
174 @ 02a67a77ee9b racing commit
175 |
176 o 9a86dcbfb938 more files to have two commit
177 |
178 o 4f23db756b09 recreate a bunch of files to facilitate dirstate-v2 append
179
180 $ hg status
181 ? dir/n
182 ? p
183 ? q
184
185 The status process should return a consistent result and not crash.
186
187 $ cat $TESTTMP/status-race-lock.out
188 M dir/o (known-bad-output no-rhg !)
189 ? dir/n
190 ? p
191 ? q
192 $ cat $TESTTMP/status-race-lock.log
193 warning: ignoring unknown working parent 02a67a77ee9b! (known-bad-output no-rhg !)
194
195 final cleanup
196
197 $ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting
198 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now