Skip to content

Commit

Permalink
bpd tests: Randomize port number
Browse files Browse the repository at this point in the history
This is a hacky but effective way to work around a problem when running
the tests in parallel where two different test executions want to use
the same port.
  • Loading branch information
sampsyo committed May 30, 2019
1 parent a0f326e commit 99778d9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import yaml
import tempfile
from contextlib import contextmanager
import random

from beets.util import confit, py3_path
from beetsplug import bpd
Expand Down Expand Up @@ -261,12 +262,17 @@ def tearDown(self):
self.unload_plugins()

@contextmanager
def run_bpd(self, host='localhost', port=9876, password=None,
def run_bpd(self, host='localhost', port=None, password=None,
do_hello=True, second_client=False):
""" Runs BPD in another process, configured with the same library
database as we created in the setUp method. Exposes a client that is
connected to the server, and kills the server at the end.
"""
# Choose a port (randomly) to avoid conflicts between parallel
# tests.
if not port:
port = 9876 + random.randint(0, 10000)

# Create a config file:
config = {
'pluginpath': [py3_path(self.temp_dir)],
Expand Down

0 comments on commit 99778d9

Please sign in to comment.