Skip to content

Commit

Permalink
Use system available ports in cluster test (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjaahhh committed Aug 7, 2020
1 parent 5b700fe commit a14fa5c
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions quarkchain/cluster/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import os
from contextlib import ContextDecorator
import socket
from contextlib import ContextDecorator, closing

from quarkchain.cluster.cluster_config import (
ClusterConfig,
Expand Down Expand Up @@ -288,21 +288,11 @@ def get_shard_state(self, full_shard_id: int) -> ShardState:
return shard.state


# server.close() does not release the port sometimes even after server.wait_closed() is awaited.
# we have to use unique ports for each test as a workaround.
# also check if in CircleCI to avoid port collision
if "CIRCLE_NODE_INDEX" in os.environ:
# max parallelism is 4
PORT_START = (int(os.environ["CIRCLE_NODE_INDEX"]) + 1) * 10000
else:
PORT_START = 50000


def get_next_port():
global PORT_START
port = PORT_START
PORT_START += 1
return port
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
s.bind(("", 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return s.getsockname()[1]


def create_test_clusters(
Expand Down

0 comments on commit a14fa5c

Please sign in to comment.