[xharness] Try to use a fixed port for the html server (but fallback to random port if it fails). (#2967)

Just so that the URL doesn't change every time you launch the server.
This commit is contained in:
Rolf Bjarne Kvinge 2017-11-07 16:12:13 +01:00 коммит произвёл GitHub
Родитель 5caddb3571
Коммит fa7c6fb8eb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 3 добавлений и 2 удалений

Просмотреть файл

@ -742,10 +742,10 @@ namespace xharness
// Try and find an unused port
int attemptsLeft = 50;
int port = 0;
int port = 51234; // Try this port first, to try to not vary between runs just because.
Random r = new Random ((int) DateTime.Now.Ticks);
while (attemptsLeft-- > 0) {
var newPort = r.Next (49152, 65535); // The suggested range for dynamic ports is 49152-65535 (IANA)
var newPort = port != 0 ? port : r.Next (49152, 65535); // The suggested range for dynamic ports is 49152-65535 (IANA)
server.Prefixes.Clear ();
server.Prefixes.Add ("http://*:" + newPort + "/");
try {
@ -754,6 +754,7 @@ namespace xharness
break;
} catch (Exception ex) {
MainLog.WriteLine ("Failed to listen on port {0}: {1}", newPort, ex.Message);
port = 0;
}
}
MainLog.WriteLine ($"Created server on localhost:{port}");