1818
1919import asyncio
2020import multiprocessing
21- import os
22- import platform
2321import random
24- import tempfile
2522
2623from avocado .core .dispatcher import SpawnerDispatcher
2724from avocado .core .exceptions import JobError , JobFailFast
3128from avocado .core .plugin_interfaces import CLI , Init , SuiteRunner
3229from avocado .core .settings import settings
3330from avocado .core .status .repo import StatusRepo
34- from avocado .core .status .server import StatusServer
31+ from avocado .core .status .server import StatusServer , resolve_listen_uri
3532from avocado .core .task .runtime import RuntimeTaskGraph
3633from avocado .core .task .statemachine import TaskStateMachine , Worker
3734
38- DEFAULT_SERVER_URI = "127.0.0.1:8888"
35+ # Default port range so multiple avocado runs can bind without conflict
36+ DEFAULT_SERVER_URI = "127.0.0.1:8888-9000"
3937
4038
4139class RunnerInit (Init ):
@@ -55,10 +53,9 @@ def initialize(self):
5553 )
5654
5755 help_msg = (
58- "If the status server should automatically choose "
59- 'a "status_server_listen" and "status_server_uri" '
60- "configuration. Default is to auto configure a "
61- "status server."
56+ "If the status server should automatically choose a listen address "
57+ "from the default port range so multiple runs do not conflict. "
58+ "When disabled, use status_server_listen/status_server_uri."
6259 )
6360 settings .register_option (
6461 section = section ,
@@ -69,10 +66,10 @@ def initialize(self):
6966 )
7067
7168 help_msg = (
72- 'URI where status server will listen on. Usually a "HOST:PORT " '
73- 'string. This is only effective if "status_server_auto" is disabled. '
74- 'If "status_server_uri" is not set, the value from "status_server_listen " '
75- "will be used."
69+ 'URI where status server will listen. "HOST:PORT" or "HOST:START-END " '
70+ "port range (default: 127.0.0.1:8888-9000). Only used when "
71+ '"status_server_auto" is disabled. If "status_server_uri" is not set, '
72+ '"status_server_listen" is used.'
7673 )
7774 settings .register_option (
7875 section = section ,
@@ -83,12 +80,10 @@ def initialize(self):
8380 )
8481
8582 help_msg = (
86- "URI for connecting to the status server, usually "
87- 'a "HOST:PORT" string. Use this if your status server '
88- "is in another host, or different port. This is only "
89- 'effective if "status_server_auto" is disabled. '
90- 'If "status_server_listen" is not set, the value from "status_server_uri" '
91- "will be used."
83+ 'URI for connecting to the status server: "HOST:PORT" or "HOST:START-END" '
84+ 'port range (default: 127.0.0.1:8888-9000). Only used when "status_server_auto" '
85+ 'is disabled. If "status_server_listen" is not set, '
86+ '"status_server_uri" is used.'
9287 )
9388 settings .register_option (
9489 section = section ,
@@ -207,19 +202,8 @@ class Runner(SuiteRunner):
207202 name = "nrunner"
208203 description = "nrunner based implementation of job compliant runner"
209204
210- def __init__ (self ):
211- super ().__init__ ()
212- self .status_server_dir = None
213-
214205 def _determine_status_server (self , test_suite , config_key ):
215- if test_suite .config .get ("run.status_server_auto" ):
216- # no UNIX domain sockets on Windows
217- if platform .system () != "Windows" :
218- if self .status_server_dir is None :
219- self .status_server_dir = tempfile .TemporaryDirectory (
220- prefix = "avocado_"
221- )
222- return os .path .join (self .status_server_dir .name , ".status_server.sock" )
206+ """Return listen/uri config; default is a port range so multiple runs work."""
223207 return test_suite .config .get (config_key )
224208
225209 def _sync_status_server_urls (self , config ):
@@ -240,10 +224,19 @@ def _sync_status_server_urls(self, config):
240224 def _create_status_server (self , test_suite , job ):
241225 self ._sync_status_server_urls (test_suite .config )
242226 listen = self ._determine_status_server (test_suite , "run.status_server_listen" )
227+ try :
228+ resolved_listen = resolve_listen_uri (listen )
229+ except (ValueError , OSError ) as exc :
230+ raise JobError (str (exc )) from exc
231+ if resolved_listen != listen :
232+ test_suite .config ["run.status_server_listen" ] = resolved_listen
233+ server_uri = test_suite .config .get ("run.status_server_uri" )
234+ if server_uri in (listen , DEFAULT_SERVER_URI ):
235+ test_suite .config ["run.status_server_uri" ] = resolved_listen
243236 # pylint: disable=W0201
244237 self .status_repo = StatusRepo (job .unique_id )
245238 # pylint: disable=W0201
246- self .status_server = StatusServer (listen , self .status_repo )
239+ self .status_server = StatusServer (resolved_listen , self .status_repo )
247240
248241 async def _update_status (self , job ):
249242 message_handler = MessageHandler ()
@@ -384,8 +377,6 @@ def run_suite(self, job, test_suite):
384377
385378 job .result .end_tests ()
386379 self .status_server .close ()
387- if self .status_server_dir is not None :
388- self .status_server_dir .cleanup ()
389380
390381 # Update the overall summary with found test statuses, which will
391382 # determine the Avocado command line exit status
0 commit comments