"examples/ssl/data_modules/_utils.py" did not exist on "6411c9ad25acfd323b06a520cda7e8963af4afbf"
Unverified Commit 48cc8fa8 authored by Chao Ma's avatar Chao Ma Committed by GitHub
Browse files

[KVStore] Update kvstore test (#1607)

* remove freeze

* update

* update

* fix lint

* update test

* update
parent 8eab08d0
import os import os
import time import time
import numpy as np import numpy as np
import socket
from scipy import sparse as spsp from scipy import sparse as spsp
import dgl import dgl
import backend as F import backend as F
...@@ -9,6 +10,35 @@ from dgl.graph_index import create_graph_index ...@@ -9,6 +10,35 @@ from dgl.graph_index import create_graph_index
from numpy.testing import assert_array_equal from numpy.testing import assert_array_equal
if os.name != 'nt':
import fcntl
import struct
def get_local_usable_addr():
"""Get local usable IP and port
Returns
-------
str
IP address, e.g., '192.168.8.12:50051'
"""
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# doesn't even have to be reachable
sock.connect(('10.255.255.255', 1))
ip_addr = sock.getsockname()[0]
except ValueError:
ip_addr = '127.0.0.1'
finally:
sock.close()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("", 0))
sock.listen(1)
port = sock.getsockname()[1]
sock.close()
return ip_addr + ' ' + str(port)
def create_random_graph(n): def create_random_graph(n):
arr = (spsp.random(n, n, density=0.001, format='coo') != 0).astype(np.int64) arr = (spsp.random(n, n, density=0.001, format='coo') != 0).astype(np.int64)
ig = create_graph_index(arr, readonly=True) ig = create_graph_index(arr, readonly=True)
...@@ -175,7 +205,8 @@ def start_client(): ...@@ -175,7 +205,8 @@ def start_client():
@unittest.skipIf(os.name == 'nt' or os.getenv('DGLBACKEND') == 'tensorflow', reason='Do not support windows and TF yet') @unittest.skipIf(os.name == 'nt' or os.getenv('DGLBACKEND') == 'tensorflow', reason='Do not support windows and TF yet')
def test_kv_store(): def test_kv_store():
ip_config = open("kv_ip_config.txt", "w") ip_config = open("kv_ip_config.txt", "w")
ip_config.write('127.0.0.1 2500 1\n') ip_addr = get_local_usable_addr()
ip_config.write('%s 1\n' % ip_addr)
ip_config.close() ip_config.close()
pid = os.fork() pid = os.fork()
if pid == 0: if pid == 0:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment