sapling/tests/test-hggit-http.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

47 lines
1.2 KiB
Perl

#require serve
$ hg init test
$ cd test
$ echo foo>foo
$ mkdir foo.d foo.d/bAr.hg.d foo.d/baR.d.hg
$ echo foo>foo.d/foo
$ echo bar>foo.d/bAr.hg.d/BaR
$ echo bar>foo.d/baR.d.hg/bAR
$ hg commit -A -m 1
adding foo
adding foo.d/bAr.hg.d/BaR
adding foo.d/baR.d.hg/bAR
adding foo.d/foo
$ hg serve -p 0 --port-file $TESTTMP/.port -d --pid-file=../hg1.pid -E ../error.log
$ HGPORT=`cat $TESTTMP/.port`
$ hg --config server.uncompressed=False serve -p $HGPORT1 -d --pid-file=../hg2.pid
Test server address cannot be reused
#if windows
$ hg serve -p $HGPORT1 2>&1
abort: cannot start server at '*:$HGPORT1': * (glob)
[255]
#else
$ hg serve -p $HGPORT1 2>&1
abort: cannot start server at 'localhost:$HGPORT1': $EADDRINUSE$ (glob)
[255]
#endif
$ cd ..
$ cat hg1.pid hg2.pid >> $DAEMON_PIDS
Load commonly used test logic
$ . "$TESTDIR/hggit/testutil"
Make sure that clone regular mercurial repos over http doesn't break
$ hg clone http://localhost:$HGPORT/ copy 2>&1
requesting all changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 4 changes to 4 files
new changesets 8b6053c928fe (?)
updating to branch default
4 files updated, 0 files merged, 0 files removed, 0 files unresolved