##// END OF EJS Templates
dirstate: initial creation of a test file to check dirstate race read...
marmoute -
r51124:7169ff59 stable
parent child Browse files
Show More
@@ -0,0 +1,143 b''
1 ==============================================================================
2 Check potential race conditions between a dirstate's read and other operations
3 ==============================================================================
4
5 Some commands, like `hg status`, do not need to take the wlock but need to
6 access dirstate data.
7 Other commands might update the dirstate data while this happens.
8
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.
11
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
14 status` command since it is probably the most advanced of such read-only
15 command.
16
17 It bears simililarity with `tests/test-dirstate-status-race.t ` but tests a
18 different type of race.
19
20 Setup
21 =====
22
23 $ directories="dir dir/nested dir2"
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"
26 $ extra_files="dir/n dir/o p q"
27
28 $ hg init reference-repo
29 $ cd reference-repo
30 $ mkdir -p dir/nested dir2
31 $ touch -t 200001010000 $first_files $directories
32 $ hg commit -Aqm "recreate a bunch of files to facilitate dirstate-v2 append"
33 $ touch -t 200001010010 $second_files $directories
34 $ hg commit -Aqm "more files to have two commit"
35 $ hg log -G -v
36 @ changeset: 1:9a86dcbfb938
37 | tag: tip
38 | user: test
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
41 | description:
42 | more files to have two commit
43 |
44 |
45 o changeset: 0:4f23db756b09
46 user: test
47 date: Thu Jan 01 00:00:00 1970 +0000
48 files: dir/b dir/c dir/d dir/nested/a dir2/e f
49 description:
50 recreate a bunch of files to facilitate dirstate-v2 append
51
52
53 $ hg manifest
54 dir/b
55 dir/c
56 dir/d
57 dir/i
58 dir/j
59 dir/nested/a
60 dir/nested/h
61 dir/nested/m
62 dir2/e
63 dir2/k
64 dir2/l
65 f
66 g
67
68 Add some unknown files and refresh the dirstate
69
70 $ touch -t 200001010020 $extra_files
71 $ hg add dir/o
72 $ hg remove dir/nested/m
73
74 $ hg st --config devel.dirstate.v2.data_update_mode=force-new
75 A dir/o
76 R dir/nested/m
77 ? dir/n
78 ? p
79 ? q
80 $ hg debugstate
81 n 644 0 2000-01-01 00:00:00 dir/b
82 n 644 0 2000-01-01 00:00:00 dir/c
83 n 644 0 2000-01-01 00:00:00 dir/d
84 n 644 0 2000-01-01 00:10:00 dir/i
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
87 n 644 0 2000-01-01 00:10:00 dir/nested/h
88 r ?????????????????????????????????? dir/nested/m (glob)
89 a ?????????????????????????????????? dir/o (glob)
90 n 644 0 2000-01-01 00:00:00 dir2/e
91 n 644 0 2000-01-01 00:10:00 dir2/k
92 n 644 0 2000-01-01 00:10:00 dir2/l
93 n 644 0 2000-01-01 00:00:00 f
94 n 644 0 2000-01-01 00:10:00 g
95 $ hg debugstate > ../reference
96 $ cd ..
97
98 Actual Testing
99 ==============
100
101 Race with a `hg add`
102 -------------------
103
104 $ cp -a reference-repo race-with-add
105 $ cd race-with-add
106
107 spin a `hg status` with some caches to update
108
109 $ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \
110 > --config rhg.on-unsupported=abort \
111 > --config devel.sync.dirstate.pre-read-file=$TESTTMP/status-race-lock \
112 > &
113 $ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting
114
115 Add a file
116
117 $ hg add dir/n $d2args
118 $ touch $TESTTMP/status-race-lock
119 $ wait
120
121 The file should in a "added" state
122
123 $ hg status
124 A dir/n
125 A dir/o
126 R dir/nested/m
127 ? p
128 ? q
129
130 The status process should return a consistent result and not crash.
131
132 $ cat $TESTTMP/status-race-lock.out
133 A dir/n
134 A dir/o
135 R dir/nested/m
136 ? p
137 ? q
138 $ cat $TESTTMP/status-race-lock.log
139
140 final cleanup
141
142 $ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting
143 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now