Debian Codegraph @

tests/test-chg.t

raw
1 #require chg
2
3 Scale the timeout for the chg-server to the test timeout scaling.
4 This is done to reduce the flakiness of this test on heavy load.
5
6 $ CHGTIMEOUT=`expr $HGTEST_TIMEOUT / 6`
7 $ export CHGTIMEOUT
8
9 $ mkdir log
10 $ cp $HGRCPATH $HGRCPATH.unconfigured
11 $ cat <<'EOF' >> $HGRCPATH
12 > [cmdserver]
13 > log = $TESTTMP/log/server.log
14 > max-log-files = 1
15 > max-log-size = 10 kB
16 > EOF
17 $ cp $HGRCPATH $HGRCPATH.orig
18
19 $ filterlog () {
20 > sed -e 's!^[0-9/]* [0-9:]* ([0-9]*)>!YYYY/MM/DD HH:MM:SS (PID)>!' \
21 > -e 's!\(setprocname\|received fds\|setenv\): .*!\1: ...!' \
22 > -e 's!\(confighash\|mtimehash\) = [0-9a-f]*!\1 = ...!g' \
23 > -e 's!\(in \)[0-9.]*s\b!\1 ...s!g' \
24 > -e 's!\(pid\)=[0-9]*!\1=...!g' \
25 > -e 's!\(/server-\)[0-9a-f]*!\1...!g'
26 > }
27
28 init repo
29
30 $ chg init foo
31 $ cd foo
32
33 ill-formed config
34
35 $ chg status
36 $ echo '=brokenconfig' >> $HGRCPATH
37 $ chg status
38 config error at * =brokenconfig (glob)
39 [30]
40
41 $ cp $HGRCPATH.orig $HGRCPATH
42
43 long socket path
44
45 $ sockpath=$TESTTMP/this/path/should/be/longer/than/one-hundred-and-seven/characters/where/107/is/the/typical/size/limit/of/unix-domain-socket
46 $ mkdir -p $sockpath
47 $ bakchgsockname=$CHGSOCKNAME
48 $ CHGSOCKNAME=$sockpath/server
49 $ export CHGSOCKNAME
50 $ chg root
51 $TESTTMP/foo
52 $ rm -rf $sockpath
53 $ CHGSOCKNAME=$bakchgsockname
54 $ export CHGSOCKNAME
55
56 $ cd ..
57
58 editor
59 ------
60
61 $ cat >> pushbuffer.py <<EOF
62 > def reposetup(ui, repo):
63 > repo.ui.pushbuffer(subproc=True)
64 > EOF
65
66 $ chg init editor
67 $ cd editor
68
69 by default, system() should be redirected to the client:
70
71 $ touch foo
72 $ CHGDEBUG= HGEDITOR=cat chg ci -Am channeled --edit 2>&1 \
73 > | grep -E "HG:|run 'cat"
74 chg: debug: * run 'cat "*"' at '$TESTTMP/editor' (glob)
75 HG: Enter commit message. Lines beginning with 'HG:' are removed.
76 HG: Leave message empty to abort commit.
77 HG: --
78 HG: user: test
79 HG: branch 'default'
80 HG: added foo
81
82 but no redirection should be made if output is captured:
83
84 $ touch bar
85 $ CHGDEBUG= HGEDITOR=cat chg ci -Am bufferred --edit \
86 > --config extensions.pushbuffer="$TESTTMP/pushbuffer.py" 2>&1 \
87 > | grep -E "HG:|run 'cat"
88 [1]
89
90 check that commit commands succeeded:
91
92 $ hg log -T '{rev}:{desc}\n'
93 1:bufferred
94 0:channeled
95
96 $ cd ..
97
98 pager
99 -----
100
101 $ cat >> fakepager.py <<EOF
102 > import sys
103 > for line in sys.stdin:
104 > sys.stdout.write('paged! %r\n' % line)
105 > EOF
106
107 enable pager extension globally, but spawns the master server with no tty:
108
109 $ chg init pager
110 $ cd pager
111 $ cat >> $HGRCPATH <<EOF
112 > [extensions]
113 > pager =
114 > [pager]
115 > pager = "$PYTHON" $TESTTMP/fakepager.py
116 > EOF
117 $ chg version > /dev/null
118 $ touch foo
119 $ chg ci -qAm foo
120
121 pager should be enabled if the attached client has a tty:
122
123 $ chg log -l1 -q --config ui.formatted=True
124 paged! '0:1f7b0de80e11\n'
125 $ chg log -l1 -q --config ui.formatted=False
126 0:1f7b0de80e11
127
128 chg waits for pager if runcommand raises
129
130 $ cat > $TESTTMP/crash.py <<EOF
131 > from mercurial import registrar
132 > cmdtable = {}
133 > command = registrar.command(cmdtable)
134 > @command(b'crash')
135 > def pagercrash(ui, repo, *pats, **opts):
136 > ui.write(b'going to crash\n')
137 > raise Exception('.')
138 > EOF
139
140 $ cat > $TESTTMP/fakepager.py <<EOF
141 > import sys
142 > import time
143 > for line in iter(sys.stdin.readline, ''):
144 > if 'crash' in line: # only interested in lines containing 'crash'
145 > # if chg exits when pager is sleeping (incorrectly), the output
146 > # will be captured by the next test case
147 > time.sleep(1)
148 > sys.stdout.write('crash-pager: %s' % line)
149 > EOF
150
151 $ cat >> .hg/hgrc <<EOF
152 > [extensions]
153 > crash = $TESTTMP/crash.py
154 > EOF
155
156 $ chg crash --pager=on --config ui.formatted=True 2>/dev/null
157 crash-pager: going to crash
158 [255]
159
160 no stdout data should be printed after pager quits, and the buffered data
161 should never persist (issue6207)
162
163 "killed!" may be printed if terminated by SIGPIPE, which isn't important
164 in this test.
165
166 $ cat > $TESTTMP/bulkwrite.py <<'EOF'
167 > import time
168 > from mercurial import error, registrar
169 > cmdtable = {}
170 > command = registrar.command(cmdtable)
171 > @command(b'bulkwrite')
172 > def bulkwrite(ui, repo, *pats, **opts):
173 > ui.write(b'going to write massive data\n')
174 > ui.flush()
175 > t = time.time()
176 > while time.time() - t < 2:
177 > ui.write(b'x' * 1023 + b'\n') # will be interrupted by SIGPIPE
178 > raise error.Abort(b"write() doesn't block")
179 > EOF
180
181 $ cat > $TESTTMP/fakepager.py <<'EOF'
182 > import sys
183 > import time
184 > sys.stdout.write('paged! %r\n' % sys.stdin.readline())
185 > time.sleep(1) # new data will be written
186 > EOF
187
188 $ cat >> .hg/hgrc <<EOF
189 > [extensions]
190 > bulkwrite = $TESTTMP/bulkwrite.py
191 > EOF
192
193 $ chg bulkwrite --pager=on --color no --config ui.formatted=True
194 paged! 'going to write massive data\n'
195 killed! (?)
196 [255]
197
198 $ chg bulkwrite --pager=on --color no --config ui.formatted=True
199 paged! 'going to write massive data\n'
200 killed! (?)
201 [255]
202
203 $ cd ..
204
205 missing stdio
206 -------------
207
208 $ CHGDEBUG=1 chg version -q 0<&-
209 chg: debug: * stdio fds are missing (glob)
210 chg: debug: * execute original hg (glob)
211 Mercurial Distributed SCM * (glob)
212
213 server lifecycle
214 ----------------
215
216 chg server should be restarted on code change, and old server will shut down
217 automatically. In this test, we use the following time parameters:
218
219 - "sleep 1" to make mtime different
220 - "sleep 2" to notice mtime change (polling interval is 1 sec)
221
222 set up repository with an extension:
223
224 $ chg init extreload
225 $ cd extreload
226 $ touch dummyext.py
227 $ cat <<EOF >> .hg/hgrc
228 > [extensions]
229 > dummyext = dummyext.py
230 > EOF
231
232 isolate socket directory for stable result:
233
234 $ OLDCHGSOCKNAME=$CHGSOCKNAME
235 $ mkdir chgsock
236 $ CHGSOCKNAME=`pwd`/chgsock/server
237
238 warm up server:
239
240 $ CHGDEBUG= chg log 2>&1 | grep -E 'instruction|start'
241 chg: debug: * start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob)
242
243 new server should be started if extension modified:
244
245 $ sleep 1
246 $ touch dummyext.py
247 $ CHGDEBUG= chg log 2>&1 | grep -E 'instruction|start'
248 chg: debug: * instruction: unlink $TESTTMP/extreload/chgsock/server-* (glob)
249 chg: debug: * instruction: reconnect (glob)
250 chg: debug: * start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob)
251
252 old server will shut down, while new server should still be reachable:
253
254 $ sleep 2
255 $ CHGDEBUG= chg log 2>&1 | (grep -E 'instruction|start' || true)
256
257 socket file should never be unlinked by old server:
258 (simulates unowned socket by updating mtime, which makes sure server exits
259 at polling cycle)
260
261 $ ls chgsock/server-*
262 chgsock/server-* (glob)
263 $ touch chgsock/server-*
264 $ sleep 2
265 $ ls chgsock/server-*
266 chgsock/server-* (glob)
267
268 since no server is reachable from socket file, new server should be started:
269 (this test makes sure that old server shut down automatically)
270
271 $ CHGDEBUG= chg log 2>&1 | grep -E 'instruction|start'
272 chg: debug: * start cmdserver at $TESTTMP/extreload/chgsock/server.* (glob)
273
274 shut down servers and restore environment:
275
276 $ rm -R chgsock
277 $ sleep 2
278 $ CHGSOCKNAME=$OLDCHGSOCKNAME
279 $ cd ..
280
281 check that server events are recorded:
282
283 $ ls log
284 server.log
285 server.log.1
286
287 print only the last 10 lines, since we aren't sure how many records are
288 preserved (since setprocname isn't available on py3 and pure version,
289 the 10th-most-recent line is different when using py3):
290
291 (the "worker process exited" line is matched independently as it order is unstable with the "exiting" line, the worker might exit before the server decide to exit).
292
293 $ cat log/server.log.1 log/server.log | tail -10 | grep -v "worker process exited" | filterlog
294 YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ... (no-setprocname !)
295 YYYY/MM/DD HH:MM:SS (PID)> forked worker process (pid=...)
296 YYYY/MM/DD HH:MM:SS (PID)> setprocname: ... (setprocname !)
297 YYYY/MM/DD HH:MM:SS (PID)> received fds: ...
298 YYYY/MM/DD HH:MM:SS (PID)> chdir to '$TESTTMP/extreload'
299 YYYY/MM/DD HH:MM:SS (PID)> setumask 18
300 YYYY/MM/DD HH:MM:SS (PID)> setenv: ...
301 YYYY/MM/DD HH:MM:SS (PID)> confighash = ... mtimehash = ...
302 YYYY/MM/DD HH:MM:SS (PID)> validate: []
303 YYYY/MM/DD HH:MM:SS (PID)> $TESTTMP/extreload/chgsock/server-... is not owned, exiting.
304 $ cat log/server.log.1 log/server.log | tail -10 | grep "worker process exited" | filterlog
305 YYYY/MM/DD HH:MM:SS (PID)> worker process exited (pid=...)
306
307 global data mutated by schems
308 -----------------------------
309
310 $ hg init schemes
311 $ cd schemes
312
313 initial state
314
315 $ cat > .hg/hgrc <<'EOF'
316 > [extensions]
317 > schemes =
318 > [schemes]
319 > foo = https://foo.example.org/
320 > EOF
321 $ hg debugexpandscheme foo://expanded
322 https://foo.example.org/expanded
323 $ hg debugexpandscheme bar://unexpanded
324 bar://unexpanded
325
326 add bar
327
328 $ cat > .hg/hgrc <<'EOF'
329 > [extensions]
330 > schemes =
331 > [schemes]
332 > foo = https://foo.example.org/
333 > bar = https://bar.example.org/
334 > EOF
335 $ hg debugexpandscheme foo://expanded
336 https://foo.example.org/expanded
337 $ hg debugexpandscheme bar://expanded
338 https://bar.example.org/expanded
339
340 remove foo
341
342 $ cat > .hg/hgrc <<'EOF'
343 > [extensions]
344 > schemes =
345 > [schemes]
346 > bar = https://bar.example.org/
347 > EOF
348 $ hg debugexpandscheme foo://unexpanded
349 foo://unexpanded
350 $ hg debugexpandscheme bar://expanded
351 https://bar.example.org/expanded
352
353 $ cd ..
354
355 repository cache
356 ----------------
357
358 $ cp $HGRCPATH.unconfigured $HGRCPATH
359 $ cat <<'EOF' >> $HGRCPATH
360 > [cmdserver]
361 > log = $TESTTMP/log/server-cached.log
362 > max-repo-cache = 1
363 > track-log = command, repocache
364 > EOF
365
366 isolate socket directory for stable result:
367
368 $ OLDCHGSOCKNAME=$CHGSOCKNAME
369 $ mkdir chgsock
370 $ CHGSOCKNAME=`pwd`/chgsock/server
371
372 create empty repo and cache it:
373
374 $ hg init cached
375 $ hg id -R cached
376 000000000000 tip
377 $ sleep 1
378
379 modify repo (and cache will be invalidated):
380
381 $ touch cached/a
382 $ hg ci -R cached -Am 'add a'
383 adding a
384 $ sleep 1
385
386 read cached repo:
387
388 $ hg log -R cached
389 changeset: 0:ac82d8b1f7c4
390 tag: tip
391 user: test
392 date: Thu Jan 01 00:00:00 1970 +0000
393 summary: add a
394
395 $ sleep 1
396
397 discard cached from LRU cache:
398
399 $ hg clone cached cached2
400 updating to branch default
401 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
402 $ hg id -R cached2
403 ac82d8b1f7c4 tip
404 $ sleep 1
405
406 read uncached repo:
407
408 $ hg log -R cached
409 changeset: 0:ac82d8b1f7c4
410 tag: tip
411 user: test
412 date: Thu Jan 01 00:00:00 1970 +0000
413 summary: add a
414
415 $ sleep 1
416
417 shut down servers and restore environment:
418
419 $ rm -R chgsock
420 $ sleep 2
421 $ CHGSOCKNAME=$OLDCHGSOCKNAME
422
423 check server log:
424
425 $ cat log/server-cached.log | filterlog
426 YYYY/MM/DD HH:MM:SS (PID)> init cached
427 YYYY/MM/DD HH:MM:SS (PID)> id -R cached
428 YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached (in ...s)
429 YYYY/MM/DD HH:MM:SS (PID)> repo from cache: $TESTTMP/cached
430 YYYY/MM/DD HH:MM:SS (PID)> ci -R cached -Am 'add a'
431 YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached (in ...s)
432 YYYY/MM/DD HH:MM:SS (PID)> repo from cache: $TESTTMP/cached
433 YYYY/MM/DD HH:MM:SS (PID)> log -R cached
434 YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached (in ...s)
435 YYYY/MM/DD HH:MM:SS (PID)> clone cached cached2
436 YYYY/MM/DD HH:MM:SS (PID)> id -R cached2
437 YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached2 (in ...s)
438 YYYY/MM/DD HH:MM:SS (PID)> log -R cached
439 YYYY/MM/DD HH:MM:SS (PID)> loaded repo into cache: $TESTTMP/cached (in ...s)
440
441 Test that -R is interpreted relative to --cwd.
442
443 $ hg init repo1
444 $ mkdir -p a/b
445 $ hg init a/b/repo2
446 $ printf "[alias]\ntest=repo1\n" >> repo1/.hg/hgrc
447 $ printf "[alias]\ntest=repo2\n" >> a/b/repo2/.hg/hgrc
448 $ cd a
449 $ chg --cwd .. -R repo1 show alias.test
450 repo1
451 $ chg --cwd . -R b/repo2 show alias.test
452 repo2
453 $ cd ..
454
455 Test that chg works (sets to the user's actual LC_CTYPE) even when python
456 "coerces" the locale (py3.7+)
457
458 $ cat > $TESTTMP/debugenv.py <<EOF
459 > from mercurial import encoding
460 > from mercurial import registrar
461 > cmdtable = {}
462 > command = registrar.command(cmdtable)
463 > @command(b'debugenv', [], b'', norepo=True)
464 > def debugenv(ui):
465 > for k in [b'LC_ALL', b'LC_CTYPE', b'LANG']:
466 > v = encoding.environ.get(k)
467 > if v is not None:
468 > ui.write(b'%s=%s\n' % (k, encoding.environ[k]))
469 > EOF
470 (hg keeps python's modified LC_CTYPE, chg doesn't)
471
472 #if python-local-coerce
473
474 $ (unset LC_ALL; unset LANG; LC_CTYPE= "$CHGHG" \
475 > --config extensions.debugenv=$TESTTMP/debugenv.py debugenv)
476 LC_CTYPE=C.UTF-8
477
478 #endif
479
480 $ (unset LC_ALL; unset LANG; LC_CTYPE= chg \
481 > --config extensions.debugenv=$TESTTMP/debugenv.py debugenv)
482 LC_CTYPE=
483 $ (unset LC_ALL; unset LANG; LC_CTYPE=unsupported_value chg \
484 > --config extensions.debugenv=$TESTTMP/debugenv.py debugenv)
485 *cannot change locale* (glob) (?)
486 LC_CTYPE=unsupported_value
487 $ (unset LC_ALL; unset LANG; LC_CTYPE= chg \
488 > --config extensions.debugenv=$TESTTMP/debugenv.py debugenv)
489 LC_CTYPE=
490 $ LANG= LC_ALL= LC_CTYPE= chg \
491 > --config extensions.debugenv=$TESTTMP/debugenv.py debugenv
492 LC_ALL=
493 LC_CTYPE=
494 LANG=
495
496 Profiling isn't permanently enabled or carried over between chg invocations that
497 share the same server
498 $ cp $HGRCPATH.orig $HGRCPATH
499 $ hg init $TESTTMP/profiling
500 $ cd $TESTTMP/profiling
501 $ filteredchg() {
502 > CHGDEBUG=1 chg "$@" 2>&1 | sed -rn 's_^No samples recorded.*$_Sample count: 0_; /Sample count/p; /start cmdserver/p'
503 > }
504 $ newchg() {
505 > chg --kill-chg-daemon
506 > filteredchg "$@" | grep -E -v 'start cmdserver' || true
507 > }
508 (--profile isn't permanently on just because it was specified when chg was
509 started)
510 $ newchg log -r . --profile
511 Sample count: * (glob)
512 $ filteredchg log -r .
513 (enabling profiling via config works, even on the first chg command that starts
514 a cmdserver)
515 $ cat >> $HGRCPATH <<EOF
516 > [profiling]
517 > type=stat
518 > enabled=1
519 > EOF
520 $ newchg log -r .
521 Sample count: * (glob)
522 $ filteredchg log -r .
523 Sample count: * (glob)
524 (test that we aren't accumulating more and more samples each run)
525 $ cat > $TESTTMP/debugsleep.py <<EOF
526 > import time
527 > from mercurial import registrar
528 > cmdtable = {}
529 > command = registrar.command(cmdtable)
530 > @command(b'debugsleep', [], b'', norepo=True)
531 > def debugsleep(ui):
532 > start = time.time()
533 > x = 0
534 > while time.time() < start + 0.5:
535 > time.sleep(.1)
536 > x += 1
537 > ui.status(b'%d debugsleep iterations in %.03fs\n' % (x, time.time() - start))
538 > EOF
539 $ cat >> $HGRCPATH <<EOF
540 > [extensions]
541 > debugsleep = $TESTTMP/debugsleep.py
542 > EOF
543 $ newchg debugsleep > run_1
544 $ filteredchg debugsleep > run_2
545 $ filteredchg debugsleep > run_3
546 $ filteredchg debugsleep > run_4
547 FIXME: Run 4 should not be >3x Run 1's number of samples.
548 $ "$PYTHON" <<EOF
549 > r1 = int(open("run_1", "r").read().split()[-1])
550 > r4 = int(open("run_4", "r").read().split()[-1])
551 > print("Run 1: %d samples\nRun 4: %d samples\nRun 4 > 3 * Run 1: %s" %
552 > (r1, r4, r4 > (r1 * 3)))
553 > EOF
554 Run 1: * samples (glob)
555 Run 4: * samples (glob)
556 Run 4 > 3 * Run 1: False
557 (Disabling with --no-profile on the commandline still works, but isn't permanent)
558 $ newchg log -r . --no-profile
559 $ filteredchg log -r .
560 Sample count: * (glob)
561 $ filteredchg log -r . --no-profile
562 $ filteredchg log -r .
563 Sample count: * (glob)
564
565 chg setting CHGHG itself
566 ------------------------
567
568 If CHGHG is not set, chg will set it before spawning the command server.
569 $ hg --kill-chg-daemon
570 $ HG=$CHGHG CHGHG= CHGDEBUG= hg debugshell -c \
571 > 'ui.write(b"CHGHG=%s\n" % ui.environ.get(b"CHGHG"))' 2>&1 \
572 > | grep -E 'CHGHG|start cmdserver'
573 chg: debug: * start cmdserver at * (glob)
574 CHGHG=/*/install/bin/hg (glob)
575
576 Running the same command a second time shouldn't spawn a new command server.
577 $ HG=$CHGHG CHGHG= CHGDEBUG= hg debugshell -c \
578 > 'ui.write(b"CHGHG=%s\n" % ui.environ.get(b"CHGHG"))' 2>&1 \
579 > | grep -E 'CHGHG|start cmdserver'
580 CHGHG=/*/install/bin/hg (glob)
581
582 $ cd ..
583
584 Test behaviors around --profile/--no-profile and the associated config
585 ----------------------------------------------------------------------
586
587 Test that profiling.enabled=true in user config is respected when using chg.
588
589 This is a regression test for a bug where the chg server, started with --no-profile
590 from a directory with no repo, would inadvertently set profiling.enabled=false on
591 the ui object that gets reused for subsequent commands.
592
593 $ mkdir profiles
594 $ PROFILES=$(pwd)/profiles
595 $ cp $HGRCPATH.unconfigured $HGRCPATH
596 $ cat >> "$HGRCPATH" <<EOF
597 > [profiling]
598 > type=stat
599 > enabled=true
600 > output-dir=$PROFILES
601 > EOF
602
603 Start chg server in a repo:
604
605 $ hg init repo
606 $ cd repo
607 $ chg --kill-chg-daemon
608 $ chg debugconf --source profiling.enabled
609 $HGRCPATH:*: true (glob)
610
611 Same test but the chg server is initially started outside any repo:
612
613 $ cd "$TESTTMP"
614 $ chg --kill-chg-daemon
615 $ chg version -q > /dev/null
616 $ cd repo
617 $ chg debugconf --source profiling.enabled
618 $HGRCPATH:*: true (glob)
619 $ cd ..