Exemplo n.º 1
0
 def test_single_core(self):
     url = get_random_port_url()
     filename = make_temp_dir('locker_test/score.txt')
     self.create_file(filename)
     self.start_server(url)
     lock = LockerClient(url)
     iterator = [(irun, lock, filename) for irun in range(self.ITERATIONS)]
     list(map(the_job, iterator))
     lock.send_done()
     self.check_file(filename)
     self.lock_process.join()
Exemplo n.º 2
0
 def test_single_core(self):
     url = get_random_port_url()
     filename = make_temp_dir('locker_test/score.txt')
     self.create_file(filename)
     self.start_server(url)
     lock = LockerClient(url)
     iterator = [(irun, lock, filename) for irun in range(self.ITERATIONS)]
     list(map(the_job, iterator))
     lock.send_done()
     self.check_file(filename)
     self.lock_process.join()
Exemplo n.º 3
0
 def test_timout_pool(self):
     pool = mp.Pool(5)
     url = get_random_port_url()
     self.start_timeout_server(url, 0.25)
     lock = LockerClient(url)
     lock.start()
     iterator = [(irun, lock) for irun in range(self.ITERATIONS)]
     potential_timeouts = list(pool.imap(time_out_job, iterator))
     pool.close()
     pool.join()
     all_time_outs = [x for x in potential_timeouts if x]
     self.assertGreaterEqual(len(all_time_outs), 1)
     lock.send_done()
     self.lock_process.join()
Exemplo n.º 4
0
 def test_concurrent_pool(self, faulty=False, filename='locker_test/pool.txt'):
     pool = mp.Pool(5)
     url = get_random_port_url()
     filename = make_temp_dir(filename)
     self.create_file(filename)
     self.start_server(url, faulty)
     lock = LockerClient(url)
     iterator = [(irun, lock, filename) for irun in range(self.ITERATIONS)]
     pool.imap(the_job, iterator)
     pool.close()
     pool.join()
     lock.send_done()
     self.check_file(filename)
     self.lock_process.join()
Exemplo n.º 5
0
 def test_timout_pool(self):
     pool = mp.Pool(5)
     url = get_random_port_url()
     self.start_timeout_server(url, 0.25)
     lock = LockerClient(url)
     lock.start()
     iterator = [(irun, lock) for irun in range(self.ITERATIONS)]
     potential_timeouts = list(pool.imap(time_out_job, iterator))
     pool.close()
     pool.join()
     all_time_outs = [x for x in potential_timeouts if x]
     self.assertGreaterEqual(len(all_time_outs), 1)
     lock.send_done()
     self.lock_process.join()
Exemplo n.º 6
0
 def test_concurrent_pool(self,
                          faulty=False,
                          filename='locker_test/pool.txt'):
     pool = mp.Pool(5)
     url = get_random_port_url()
     filename = make_temp_dir(filename)
     self.create_file(filename)
     self.start_server(url, faulty)
     lock = LockerClient(url)
     iterator = [(irun, lock, filename) for irun in range(self.ITERATIONS)]
     pool.imap(the_job, iterator)
     pool.close()
     pool.join()
     lock.send_done()
     self.check_file(filename)
     self.lock_process.join()
Exemplo n.º 7
0
 def test_concurrent_scoop(self):
     # test several restarts
     old_iter = self.ITERATIONS
     for jrun in range(3):
         self.ITERATIONS = 11
         url = get_random_port_url()
         filename = make_temp_dir('locker_test/scoop.txt')
         self.create_file(filename)
         self.start_server(url)
         lock = LockerClient(url)
         lock.start()
         iterator = [(irun, lock, filename) for irun in range(self.ITERATIONS)]
         list(futures.map(the_job, iterator))
         lock.send_done()
         self.check_file(filename)
         self.lock_process.join()
         # errwrite(str(irun))
     self.ITERATIONS = old_iter
Exemplo n.º 8
0
 def test_concurrent_scoop(self):
     # test several restarts
     old_iter = self.ITERATIONS
     for jrun in range(3):
         self.ITERATIONS = 11
         url = get_random_port_url()
         filename = make_temp_dir('locker_test/scoop.txt')
         self.create_file(filename)
         self.start_server(url)
         lock = LockerClient(url)
         lock.start()
         iterator = [(irun, lock, filename)
                     for irun in range(self.ITERATIONS)]
         list(futures.map(the_job, iterator))
         lock.send_done()
         self.check_file(filename)
         self.lock_process.join()
         # errwrite(str(irun))
     self.ITERATIONS = old_iter
Exemplo n.º 9
0
    def test_errors(self):
        url = get_random_port_url()
        self.start_server(url)
        ctx = zmq.Context()
        sck = ctx.socket(zmq.REQ)
        sck.ipv6 = is_ipv6(url)
        sck.connect(url)
        sck.send_string(LockerServer.UNLOCK + LockerServer.DELIMITER + 'test' +
                        LockerServer.DELIMITER + 'hi' +
                        LockerServer.DELIMITER + '12344')
        response = sck.recv_string()
        self.assertTrue(response.startswith(LockerServer.RELEASE_ERROR))

        sck.send_string(LockerServer.LOCK + LockerServer.DELIMITER + 'test' +
                        LockerServer.DELIMITER + 'hi' +
                        LockerServer.DELIMITER + '12344')
        response = sck.recv_string()
        self.assertEqual(response, LockerServer.GO)

        sck.send_string(LockerServer.UNLOCK + LockerServer.DELIMITER + 'test' +
                        LockerServer.DELIMITER + 'ha' +
                        LockerServer.DELIMITER + '12344')
        response = sck.recv_string()
        self.assertTrue(response.startswith(LockerServer.RELEASE_ERROR))

        sck.send_string(LockerServer.UNLOCK + LockerServer.DELIMITER + 'test')
        response = sck.recv_string()
        self.assertTrue(response.startswith(LockerServer.MSG_ERROR))

        sck.send_string(LockerServer.LOCK + LockerServer.DELIMITER + 'test')
        response = sck.recv_string()
        self.assertTrue(response.startswith(LockerServer.MSG_ERROR))

        sck.send_string('Wooopiee!')
        response = sck.recv_string()
        self.assertTrue(response.startswith(LockerServer.MSG_ERROR))

        sck.close()

        lock = LockerClient(url)
        lock.send_done()
        self.lock_process.join()
        lock.finalize()
Exemplo n.º 10
0
    def test_errors(self):
        url = get_random_port_url()
        self.start_server(url)
        ctx = zmq.Context()
        sck = ctx.socket(zmq.REQ)
        sck.ipv6 = is_ipv6(url)
        sck.connect(url)
        sck.send_string(LockerServer.UNLOCK + LockerServer.DELIMITER + 'test'
                        + LockerServer.DELIMITER + 'hi' + LockerServer.DELIMITER + '12344')
        response = sck.recv_string()
        self.assertTrue(response.startswith(LockerServer.RELEASE_ERROR))

        sck.send_string(LockerServer.LOCK + LockerServer.DELIMITER + 'test'
                        + LockerServer.DELIMITER + 'hi' + LockerServer.DELIMITER + '12344')
        response = sck.recv_string()
        self.assertEqual(response, LockerServer.GO)

        sck.send_string(LockerServer.UNLOCK + LockerServer.DELIMITER + 'test'
                        + LockerServer.DELIMITER + 'ha' + LockerServer.DELIMITER + '12344')
        response = sck.recv_string()
        self.assertTrue(response.startswith(LockerServer.RELEASE_ERROR))

        sck.send_string(LockerServer.UNLOCK + LockerServer.DELIMITER + 'test')
        response = sck.recv_string()
        self.assertTrue(response.startswith(LockerServer.MSG_ERROR))

        sck.send_string(LockerServer.LOCK + LockerServer.DELIMITER + 'test')
        response = sck.recv_string()
        self.assertTrue(response.startswith(LockerServer.MSG_ERROR))

        sck.send_string('Wooopiee!')
        response = sck.recv_string()
        self.assertTrue(response.startswith(LockerServer.MSG_ERROR))

        sck.close()

        lock = LockerClient(url)
        lock.send_done()
        self.lock_process.join()
        lock.finalize()