Exemple #1
0
 def test_create_store_timeout_on_worker(self):
     with self.assertRaises(TimeoutError):
         port = get_free_port()
         create_c10d_store(
             is_server=False,
             server_addr=socket.gethostname(),
             server_port=port,
             world_size=2,
             timeout=1,
         )
Exemple #2
0
 def test_create_store_timeout_on_worker(self):
     with self.assertRaises(TimeoutError):
         # use any available port (port 0) since timeout is expected
         create_c10d_store(
             is_server=False,
             server_addr=socket.gethostname(),
             server_port=0,
             world_size=2,
             timeout=1,
         )
Exemple #3
0
 def test_port_already_in_use_on_worker(self):
     sock = get_socket_with_port()
     with closing(sock):
         port = sock.getsockname()[1]
         # on the worker port conflict shouldn't matter, it should just timeout
         # since we never created a server
         with self.assertRaises(IOError):
             create_c10d_store(
                 is_server=False,
                 server_addr=socket.gethostname(),
                 server_port=port,
                 timeout=1,
             )
Exemple #4
0
 def test_port_already_in_use_on_server(self):
     sock = get_socket_with_port()
     with closing(sock):
         # try to create a store on the same port without releasing the socket
         # should raise a IOError
         port = sock.getsockname()[1]
         with self.assertRaises(IOError):
             create_c10d_store(
                 is_server=True,
                 server_addr=socket.gethostname(),
                 server_port=port,
                 timeout=1,
             )
Exemple #5
0
 def test_port_already_in_use_on_server(self):
     # try to create the TCPStore server twice on the same port
     # the second should fail due to a port conflict
     # first store binds onto a free port
     # try creating the second store on the port that the first store binded to
     server_addr = socket.gethostname()
     pick_free_port = 0
     store1 = create_c10d_store(
         is_server=True,
         server_addr=server_addr,
         server_port=pick_free_port,
         timeout=1,
     )
     with self.assertRaises(IOError):
         create_c10d_store(is_server=True,
                           server_addr=server_addr,
                           server_port=store1.port)
Exemple #6
0
def _create_c10d_store_mp(is_server, server_addr, port, world_size):
    store = create_c10d_store(is_server,
                              server_addr,
                              port,
                              world_size,
                              timeout=2)
    if store is None:
        raise AssertionError()

    store.set(f"test_key/{os.getpid()}", "test_value".encode("UTF-8"))
Exemple #7
0
    def test_create_store_multi(self):
        world_size = 3
        wait_for_workers = False
        localhost = socket.gethostname()

        # start the server on the main process using an available port
        store = create_c10d_store(
            is_server=True,
            server_addr=localhost,
            server_port=0,
            timeout=2,
            world_size=world_size,
            wait_for_workers=wait_for_workers,
        )

        # worker processes will use the port that was assigned to the server
        server_port = store.port

        worker0 = mp.Process(
            target=_create_c10d_store_mp,
            args=(False, localhost, server_port, world_size, wait_for_workers),
        )
        worker1 = mp.Process(
            target=_create_c10d_store_mp,
            args=(False, localhost, server_port, world_size, wait_for_workers),
        )

        worker0.start()
        worker1.start()

        worker0.join()
        worker1.join()

        # check test_key/pid == "test_value"
        self.assertEqual("test_value",
                         store.get(f"test_key/{worker0.pid}").decode("UTF-8"))
        self.assertEqual("test_value",
                         store.get(f"test_key/{worker1.pid}").decode("UTF-8"))

        self.assertEqual(0, worker0.exitcode)
        self.assertEqual(0, worker1.exitcode)
Exemple #8
0
    def test_create_store_multi(self):
        world_size = 3
        server_port = get_free_port()
        localhost = socket.gethostname()
        worker0 = mp.Process(
            target=_create_c10d_store_mp,
            args=(False, localhost, server_port, world_size),
        )
        worker1 = mp.Process(
            target=_create_c10d_store_mp,
            args=(False, localhost, server_port, world_size),
        )

        worker0.start()
        worker1.start()

        # start the server on the main process
        store = create_c10d_store(
            is_server=True,
            server_addr=localhost,
            server_port=server_port,
            world_size=world_size,
            timeout=2,
        )

        worker0.join()
        worker1.join()

        # check test_key/pid == "test_value"
        self.assertEqual(
            "test_value", store.get(f"test_key/{worker0.pid}").decode("UTF-8")
        )
        self.assertEqual(
            "test_value", store.get(f"test_key/{worker1.pid}").decode("UTF-8")
        )

        self.assertEqual(0, worker0.exitcode)
        self.assertEqual(0, worker1.exitcode)
Exemple #9
0
 def test_create_store_no_port_multi(self):
     with self.assertRaises(ValueError):
         create_c10d_store(is_server=True,
                           server_addr=socket.gethostname(),
                           world_size=2)
Exemple #10
0
 def test_create_store_single_server(self):
     store = create_c10d_store(is_server=True,
                               server_addr=socket.gethostname())
     self.assertIsNotNone(store)