Skip to content

Commit

Permalink
Enable picking a free port for ZServer layers automatically.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rotonen committed Oct 1, 2018
1 parent cc2f063 commit 61ee2c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Changelog

Breaking changes:

- *add item here*
- Default to picking a dynamical port for ZServer layers instead of a static
default port.
[Rotonen]

New features:

Expand Down
14 changes: 12 additions & 2 deletions src/plone/testing/z2.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,8 @@ class ZServer(Layer):

defaultBases = (STARTUP,)

host = os.environ.get('ZSERVER_HOST', 'localhost')
port = int(os.environ.get('ZSERVER_PORT', 55001))
host = os.environ.get('ZSERVER_HOST', '')
port = int(os.environ.get('ZSERVER_PORT', 0))
timeout = 5.0
log = None

Expand Down Expand Up @@ -1044,6 +1044,16 @@ def setUpServer(self):

self.zserver = server

# If we dynamically set the host/port, we want to reset it to localhost
if self.host == '':
self.zserver.server_name = 'localhost'

# Refresh the hostname and port in case we dynamically picked them
self.host = self.zserver.server_name
self['host'] = self.host
self.port = self.zserver.server_port
self['port'] = self.port

def tearDownServer(self):
"""Close the ZServer socket
"""
Expand Down
4 changes: 2 additions & 2 deletions src/plone/testing/z2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ After layer setup, the resources ``host`` and ``port`` are available, and indica

>>> port = z2.ZSERVER['port']
>>> import os
>>> port == int(os.environ.get('ZSERVER_PORT', 55001))
True
>>> port == int(os.environ.get('ZSERVER_PORT', 0))
0

Let's now simulate a test.
Test setup does nothing beyond what the base layers do.::
Expand Down

1 comment on commit 61ee2c4

@jenkins-plone-org
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rotonen Jenkins CI reporting about code analysis
See the full report here: https://jenkins.plone.org/job/package-plone.testing/94/violations

src/plone/testing/z2.py:98:1: C901 'uninstallProduct' is too complex (15)
src/plone/testing/z2.py:138:19: T000 Todo note found.
src/plone/testing/z2.py:414:5: C901 'Startup.setUpPatches' is too complex (11)
src/plone/testing/z2.py:829:11: T000 Todo note found.

Follow these instructions to reproduce it locally.

Please sign in to comment.