sapling/tests/test-hgweb-bundle.t
Jun Wu 4a7b28d08b serve: assign hg serve ports dynamically in tests
Summary:
Previously `hg server` uses `HGPORT` that might be in use. This patch uses
`-p 0 --port-file ...` so `hg server` always gets assigned a free port.

The change was first made by the following Ruby script:

```
re = /^  \$ hg serve(.*) -p \$(HGPORT[12]?) (.*[^\\])$\n  \$/
Dir['*.t'].each do |path|
  old = File.read(path)
  new = old.lines.map do |l|
    next l if l[/\(glob\)/] or not l['$HGPORT'] or l[/^  [$>]/]
    "#{l.chomp} (glob)\n"
  end.join.gsub re, <<-'EOS'.chomp
  $ hg serve\1 -p 0 --port-file $TESTTMP/.port \3
  $ \2=`cat $TESTTMP/.port`
  $
  EOS
  File.write(path, new) if old != new
end
```

Then there are some manual changes:

run-tests.py: It now treats `$HGPORT` in output as glob pattern `*`, since
it does not know the assigned value in tests.

test-bookmarks-pushpull.t, test-https.t: Some `hg pull`s were changed to use
explicit paths instead of relying on `.hgrc` since the test restarts the
server and `.hg/hgrc` having an outdated URL.

test-schemes.t: The test writes `$HGPORT` to `.hgrc` before assigning it.
Changed the order so the correct `$HGPORT` is written.

test-patchbomb-tls.t: Changed `(?) (glob)` to `(glob) (?)`.

Reviewed By: DurhamG

Differential Revision: D6925398

fbshipit-source-id: d5c10476f43ce23f9e99618807580cf8ba92595c
2018-04-13 21:51:07 -07:00

39 lines
826 B
Perl

#require serve
$ hg init server
$ cd server
$ cat >> .hg/hgrc << EOF
> [extensions]
> strip=
> EOF
$ echo 1 > foo
$ hg commit -A -m 'first'
adding foo
$ echo 2 > bar
$ hg commit -A -m 'second'
adding bar
Produce a bundle to use
$ hg strip -r 1
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
saved backup bundle to $TESTTMP/server/.hg/strip-backup/ed602e697e0f-cc9fff6a-backup.hg
Serve from a bundle file
$ hg serve -R .hg/strip-backup/ed602e697e0f-cc9fff6a-backup.hg -d -p 0 --port-file $TESTTMP/.port --pid-file=hg.pid
$ HGPORT=`cat $TESTTMP/.port`
$ cat hg.pid >> $DAEMON_PIDS
Ensure we're serving from the bundle
$ (get-with-headers.py localhost:$HGPORT 'file/tip/?style=raw')
200 Script output follows
-rw-r--r-- 2 bar
-rw-r--r-- 2 foo