diff options
Diffstat (limited to 'cherrypy/test/test_core.py')
| -rw-r--r-- | cherrypy/test/test_core.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/cherrypy/test/test_core.py b/cherrypy/test/test_core.py index 0140bef4..a104216f 100644 --- a/cherrypy/test/test_core.py +++ b/cherrypy/test/test_core.py @@ -757,3 +757,22 @@ class ErrorTests(helper.CPWebCase): self.getPage('/stat/missing') self.assertStatus(404) self.assertInBody('No such file or directory') + + +class TestBinding: + def test_bind_ephemeral_port(self): + """ + A server configured to bind to port 0 will bind to an ephemeral + port and indicate that port number on startup. + """ + cherrypy.config.reset() + bind_ephemeral_conf = { + 'server.socket_port': 0, + } + cherrypy.config.update(bind_ephemeral_conf) + cherrypy.engine.start() + assert cherrypy.server.bound_addr != cherrypy.server.bind_addr + _host, port = cherrypy.server.bound_addr + assert port > 0 + cherrypy.engine.stop() + assert cherrypy.server.bind_addr == cherrypy.server.bound_addr |
