def test_refresh_peers(self): sa = SocketAddress('127.0.0.1', 11111) node = MagicMock() node.key = EllipticalKeysAuth(self.path, "TESTPRIV", "TESTPUB").get_key_id() node.key_id = node.key node.address = sa node2 = MagicMock() node2.key = EllipticalKeysAuth(self.path, "TESTPRIV2", "TESTPUB2").get_key_id() node2.key_id = node2.key node2.address = sa self.service.add_peer(node.key, node) self.service.add_peer(node2.key, node2) self.service.peers[node.key].last_message_time = time.time() + 1000 self.service.peers[node2.key].last_message_time = time.time() + 1000 self.service.config_desc.opt_peer_num = 1000 assert len(self.service.peers) == 2 self.service.sync_network() assert len(self.service.peers) == 2 self.service.last_refresh_peers = 0 self.service.last_peers_request = 0 self.service._peer_dbg_time_threshold = 0 self.service.sync_network() # disabled assert len(self.service.peers) == 2
def testChangeResourceDir(self): keys_auth = EllipticalKeysAuth(self.path) client = MockClient() rm = TestResourceManager(self.dir_manager) rs = BaseResourceServer(TestResourceManager(self.dir_manager), self.dir_manager, keys_auth, client) rm.add_files(self._resources(), self.task_id, absolute_path=True) resources = rm.storage.get_resources(self.task_id) assert resources new_path = self.path + '_' + str(uuid.uuid4()) new_config_desc = MockConfig(new_path, node_name + "-new") rs.change_resource_dir(new_config_desc) new_resources = rm.storage.get_resources(self.task_id) assert len(resources) == len(new_resources) for resource in resources: assert resource in new_resources if os.path.exists(new_path): shutil.rmtree(new_path)
def test_results(self, trust, mock_addr, dump_mock): mock_addr.return_value = ("10.10.10.10", 1111, "Full NAT") ccd = self._get_config_desc() ts = TaskServer(Node(), ccd, EllipticalKeysAuth(self.path), self.client, use_docker_machine_manager=False) self.ts = ts ts.task_manager.listen_port = 1111 ts.task_manager.listen_address = "10.10.10.10" ts.receive_subtask_computation_time("xxyyzz", 1031) extra_data = Mock() extra_data.ctd = ComputeTaskDef() extra_data.ctd.task_id = "xyz" extra_data.ctd.subtask_id = "xxyyzz" extra_data.ctd.environment = "DEFAULT" extra_data.should_wait = False task_mock = get_mock_task("xyz", "xxyyzz") task_mock.query_extra_data.return_value = extra_data sync_wait(ts.task_manager.add_new_task(task_mock)) ts.task_manager.tasks_states["xyz"].status = ts.task_manager.activeStatus[0] subtask, wrong_task, wait = ts.task_manager.get_next_subtask("DEF", "DEF", "xyz", 1000, 10, 5, 10, 2, "10.10.10.10") ts.receive_subtask_computation_time("xxyyzz", 1031) self.assertEqual(ts.task_manager.tasks_states["xyz"].subtask_states["xxyyzz"].computation_time, 1031) expected_value = ceil(1031 * 10 / 3600) self.assertEqual(ts.task_manager.tasks_states["xyz"].subtask_states["xxyyzz"].value, expected_value) account_info = Mock() account_info.key_id = "key" prev_calls = trust.COMPUTED.increase.call_count ts.accept_result("xxyyzz", account_info) ts.client.transaction_system.add_payment_info.assert_called_with("xyz", "xxyyzz", expected_value, account_info) self.assertGreater(trust.COMPUTED.increase.call_count, prev_calls)
def test_add_to_peer_keeper(self): node = Node() node.key = EllipticalKeysAuth("TEST").get_key_id() m_test2 = MagicMock() m_test3 = MagicMock() self.service.peers["TEST3"] = m_test3 self.service.peers["TEST2"] = m_test2 self.service.peer_keeper = MagicMock() node2 = Node() node2.key = "TEST2" self.service.peer_keeper.add_peer = MagicMock(return_value=node2) self.service.add_to_peer_keeper(node) m_test2.ping.assert_called_with(0) m_test3.ping.assert_not_called() for i in range(100): self.service.peers[str(i)] = MagicMock() node2.key = "59" self.service.add_to_peer_keeper(node) self.service.peers["59"].ping.assert_called_with(0) for i in range(58) + range(60, 100): self.service.peers[str(i)].ping.assert_not_called() node2.key = None self.service.add_to_peer_keeper(node) for i in range(58) + range(60, 100): self.service.peers[str(i)].ping.assert_not_called() self.service.peers["59"].ping.assert_called_once_with(0) m_test2.ping.assert_called_once_with(0) m_test3.ping.assert_not_called() self.assertEqual(len(self.service.peers), 102)
def test_forwarded_session_requests(self): ccd = self._get_config_desc() ts = TaskServer(Node(), ccd, EllipticalKeysAuth(self.path), self.client, use_docker_machine_manager=False) self.ts = ts ts.network = Mock() key_id = str(uuid.uuid4()) conn_id = str(uuid.uuid4()) subtask_id = str(uuid.uuid4()) ts.add_forwarded_session_request(key_id, conn_id) self.assertEqual(len(ts.forwarded_session_requests), 1) ts.forwarded_session_requests[key_id]['time'] = 0 ts._sync_forwarded_session_requests() self.assertEqual(len(ts.forwarded_session_requests), 0) ts.add_forwarded_session_request(key_id, conn_id) ts.forwarded_session_requests[key_id] = None ts._sync_forwarded_session_requests() self.assertEqual(len(ts.forwarded_session_requests), 0) session = MagicMock() session.address = '127.0.0.1' session.port = 65535 ts.conn_established_for_type[TASK_CONN_TYPES['task_failure']]( session, conn_id, key_id, subtask_id, "None" ) self.assertEqual(ts.task_sessions[subtask_id], session)
def test_request(self): ccd = self._get_config_desc() ccd.min_price = 10 n = Node() ka = EllipticalKeysAuth(self.path) ts = TaskServer(n, ccd, ka, self.client, use_docker_machine_manager=False) ts.verify_header_sig = lambda x: True self.ts = ts ts.client.get_suggested_addr.return_value = "10.10.10.10" ts.client.get_suggested_conn_reverse.return_value = False ts.client.get_requesting_trust.return_value = 0.3 self.assertIsInstance(ts, TaskServer) self.assertIsNone(ts.request_task()) n2 = Node() n2.prv_addr = "10.10.10.10" n2.port = 10101 task_header = get_example_task_header() task_header["task_owner"] = n2 ts.add_task_header(task_header) self.assertEqual(ts.request_task(), "uvw") ts.remove_task_header("uvw") task_header["task_owner_port"] = 0 task_header["task_id"] = "uvw2" self.assertTrue(ts.add_task_header(task_header)) self.assertIsNotNone(ts.task_keeper.task_headers["uvw2"]) self.assertIsNone(ts.request_task()) self.assertIsNone(ts.task_keeper.task_headers.get("uvw2"))
def test_results_no_payment_addr(self, trust, mock_addr, dump_mock): mock_addr.return_value = ("10.10.10.10", 1111, "Full NAT") # FIXME: This test is too heavy, it starts up whole Golem Client. ccd = self._get_config_desc() ts = TaskServer(Node(), ccd, EllipticalKeysAuth(self.path), self.client, use_docker_machine_manager=False) ts.task_manager.listen_address = "10.10.10.10" ts.task_manager.listen_port = 1111 ts.receive_subtask_computation_time("xxyyzz", 1031) self.ts = ts extra_data = Mock() extra_data.ctd = ComputeTaskDef() extra_data.ctd.task_id = "xyz" extra_data.ctd.subtask_id = "xxyyzz" extra_data.ctd.environment = "DEFAULT" extra_data.should_wait = False task_mock = get_mock_task("xyz", "xxyyzz") task_mock.query_extra_data.return_value = extra_data sync_wait(ts.task_manager.add_new_task(task_mock)) ts.task_manager.tasks_states["xyz"].status = ts.task_manager.activeStatus[0] subtask, wrong_task, wait = ts.task_manager.get_next_subtask( "DEF", "DEF", "xyz", 1000, 10, 5, 10, 2, "10.10.10.10") ts.receive_subtask_computation_time("xxyyzz", 1031) account_info = Mock() account_info.key_id = "key" account_info.eth_account = Mock() account_info.eth_account.address = None ts.accept_result("xxyyzz", account_info) self.assertEqual(ts.client.transaction_system.add_payment_info.call_count, 0)
def test_change_config(self): ccd = self._get_config_desc() ccd.task_session_timeout = 40 ccd.min_price = 1.0 ccd.use_distributed_resource_management = 10 ccd.task_request_interval = 10 # ccd.use_waiting_ttl = True ccd.waiting_for_task_timeout = 19 ts = TaskServer(Node(), ccd, EllipticalKeysAuth(self.path), self.client, use_docker_machine_manager=False) self.ts = ts ccd2 = self._get_config_desc() ccd2.task_session_timeout = 124 ccd2.min_price = 0.0057 ccd2.use_distributed_resource_management = 0 ccd2.task_request_interval = 31 # ccd2.use_waiting_ttl = False ccd2.waiting_for_task_timeout = 90 ts.change_config(ccd2) self.assertEqual(ts.config_desc, ccd2) self.assertEqual(ts.last_message_time_threshold, 124) self.assertEqual(ts.task_keeper.min_price, 0.0057) self.assertEqual(ts.task_manager.use_distributed_resources, False) self.assertEqual(ts.task_computer.task_request_frequency, 31) self.assertEqual(ts.task_computer.waiting_for_task_timeout, 90)
def testVerifySig(self): keys_auth = EllipticalKeysAuth(self.path) rs = BaseResourceServer(TestResourceManager(self.dir_manager), self.dir_manager, keys_auth, MockClient()) test_str = "A test string to sign" sig = rs.sign(test_str) self.assertTrue(rs.verify_sig(sig, test_str, keys_auth.get_public_key()))
def testGetDistributedResourceRoot(self): keys_auth = EllipticalKeysAuth(self.path) client = MockClient() rs = BaseResourceServer(TestResourceManager(self.dir_manager), self.dir_manager, keys_auth, client) resource_dir = self.dir_manager.get_node_dir() assert rs.get_distributed_resource_root() == resource_dir
def test_traverse_nat(self): ccd = self._get_config_desc() ts = TaskServer(Node(), ccd, EllipticalKeysAuth(self.path), self.client, use_docker_machine_manager=False) self.ts = ts ts.network = Mock() ts.traverse_nat("ABC", "10.10.10.10", 1312, 310319041904, "DEF") self.assertEqual(ts.network.connect.call_args[0][0].socket_addresses[0].address, "10.10.10.10") self.assertEqual(ts.network.connect.call_args[0][0].socket_addresses[0].port, 1312)
def test_verify(self): conn = MagicMock() peer_session = PeerSession(conn) keys_auth = EllipticalKeysAuth(self.path) peer_session.key_id = keys_auth.get_key_id() peer_session.p2p_service.verify_sig = keys_auth.verify msg = MessageStopGossip() assert not peer_session.verify(msg) msg.sig = keys_auth.sign(msg.get_short_hash()) assert peer_session.verify(msg)
def test_encrypt_decrypt(self): ps = PeerSession(MagicMock()) ps2 = PeerSession(MagicMock()) ek = EllipticalKeysAuth(self.path, "RANDOMPRIV", "RANDOMPUB") ek2 = EllipticalKeysAuth(self.path, "RANDOMPRIV2", "RANDOMPUB2") ps.p2p_service.encrypt = ek.encrypt ps.p2p_service.decrypt = ek.decrypt ps.key_id = ek2.key_id ps2.p2p_service.encrypt = ek2.encrypt ps2.p2p_service.decrypt = ek2.decrypt ps2.key_id = ek.key_id data = "abcdefghijklm" * 1000 self.assertEqual(ps2.decrypt(ps.encrypt(data)), data) self.assertEqual(ps.decrypt(ps2.encrypt(data)), data) with self.assertLogs(logger, level=1) as l: self.assertEqual(ps2.decrypt(data), data) self.assertTrue(any("not encrypted" in log for log in l.output))
def test_add_known_peer(self): key_id = EllipticalKeysAuth(self.path, "TESTPRIV", "TESTPUB").get_key_id() nominal_seeds = len(self.service.seeds) node = Node( 'super_node', key_id, pub_addr='1.2.3.4', prv_addr='1.2.3.4', pub_port=10000, prv_port=10000 ) node.prv_addresses = [node.prv_addr, '172.1.2.3'] assert Node.is_super_node(node) KnownHosts.delete().execute() len_start = len(KnownHosts.select()) # insert one self.service.add_known_peer(node, node.pub_addr, node.pub_port) select_1 = KnownHosts.select() len_1 = len(select_1) last_conn_1 = select_1[0].last_connected assert len_1 > len_start # advance time time.sleep(0.1) # insert duplicate self.service.add_known_peer(node, node.pub_addr, node.pub_port) select_2 = KnownHosts.select() len_2 = len(select_2) assert len_2 == len_1 assert select_2[0].last_connected > last_conn_1 assert len(self.service.seeds) > nominal_seeds # try to add more than max, we already have at least 1 pub_prefix = '2.2.3.' prv_prefix = '172.1.2.' for i in xrange(1, MAX_STORED_HOSTS + 6): i_str = str(i) pub = pub_prefix + i_str prv = prv_prefix + i_str n = Node( i_str, key_id + i_str, pub_addr=pub, prv_addr=prv, pub_port=10000, prv_port=10000 ) self.service.add_known_peer(n, pub, n.prv_port) assert len(KnownHosts.select()) == MAX_STORED_HOSTS assert len(self.service.seeds) == nominal_seeds
def test_send_results(self, trust): ccd = self._get_config_desc() ccd.min_price = 11 n = Node() ka = EllipticalKeysAuth(self.path) ts = TaskServer(n, ccd, ka, self.client, use_docker_machine_manager=False) ts.verify_header_sig = lambda x: True self.ts = ts ts.client.get_suggested_addr.return_value = "10.10.10.10" results = {"data": "", "result_type": 0} task_header = get_example_task_header() task_header["task_id"] = "xyz" ts.add_task_header(task_header) ts.request_task() self.assertTrue(ts.send_results("xxyyzz", "xyz", results, 40, "10.10.10.10", 10101, "key", n, "node_name")) self.assertTrue(ts.send_results("xyzxyz", "xyz", results, 40, "10.10.10.10", 10101, "key", n, "node_name")) self.assertEqual(ts.get_subtask_ttl("xyz"), 120) wtr = ts.results_to_send["xxyyzz"] self.assertIsInstance(wtr, WaitingTaskResult) self.assertEqual(wtr.subtask_id, "xxyyzz") self.assertEqual(wtr.result, "") self.assertEqual(wtr.result_type, 0) self.assertEqual(wtr.computing_time, 40) self.assertEqual(wtr.last_sending_trial, 0) self.assertEqual(wtr.delay_time, 0) self.assertEqual(wtr.owner_address, "10.10.10.10") self.assertEqual(wtr.owner_port, 10101) self.assertEqual(wtr.owner_key_id, "key") self.assertEqual(wtr.owner, n) self.assertEqual(wtr.already_sending, False) ts.client.transaction_system.add_to_waiting_payments.assert_called_with( "xyz", "key", 1) with self.assertLogs(logger, level='WARNING'): ts.subtask_rejected("aabbcc") self.assertIsNotNone(ts.task_keeper.task_headers.get("xyz")) prev_call_count = trust.PAYMENT.increase.call_count with self.assertLogs(logger, level="WARNING"): ts.reward_for_subtask_paid("aa2bb2cc") self.assertEqual(trust.PAYMENT.increase.call_count, prev_call_count) ctd = ComputeTaskDef() ctd.task_id = "xyz" ctd.subtask_id = "xxyyzz" ts.task_manager.comp_task_keeper.receive_subtask(ctd) ts.reward_for_subtask_paid("xxyyzz") self.assertGreater(trust.PAYMENT.increase.call_count, prev_call_count) prev_call_count = trust.PAYMENT.increase.call_count ts.increase_trust_payment("xyz") self.assertGreater(trust.PAYMENT.increase.call_count, prev_call_count) prev_call_count = trust.PAYMENT.decrease.call_count ts.decrease_trust_payment("xyz") self.assertGreater(trust.PAYMENT.decrease.call_count, prev_call_count)
def testDecrypt(self): keys_auth = EllipticalKeysAuth(self.path) client = MockClient() rs = BaseResourceServer(TestResourceManager(self.dir_manager), self.dir_manager, keys_auth, client) to_encrypt = "test string to enc" encrypted = rs.encrypt(to_encrypt, keys_auth.get_public_key()) decrypted = rs.decrypt(encrypted) self.assertEqual(decrypted, to_encrypt)
def test_add_task_header(self): config = self._get_config_desc() keys_auth = EllipticalKeysAuth(self.path) keys_auth_2 = EllipticalKeysAuth(os.path.join(self.path, "2")) self.ts = ts = TaskServer(Node(), config, keys_auth, self.client, use_docker_machine_manager=False) task_header = get_example_task_header() task_header["task_id"] = "xyz" with self.assertRaises(Exception) as raised: ts.add_task_header(task_header) self.assertEqual(raised.exception.message, "Invalid signature") self.assertEqual(len(ts.get_tasks_headers()), 0) task_header["task_owner_key_id"] = keys_auth_2.key_id task_header["signature"] = keys_auth_2.sign(TaskHeader.dict_to_binary(task_header)) self.assertIsNotNone(ts.add_task_header(task_header)) self.assertEqual(len(ts.get_tasks_headers()), 1) task_header = get_example_task_header() task_header["task_id"] = "xyz_2" task_header["task_owner_key_id"] = keys_auth_2.key_id task_header["signature"] = keys_auth_2.sign(TaskHeader.dict_to_binary(task_header)) self.assertIsNotNone(ts.add_task_header(task_header)) self.assertEqual(len(ts.get_tasks_headers()), 2) self.assertIsNotNone(ts.add_task_header(task_header)) self.assertEqual(len(ts.get_tasks_headers()), 2) new_header = dict(task_header) new_header["task_owner"]["pub_port"] = 9999 new_header["signature"] = keys_auth_2.sign(TaskHeader.dict_to_binary(new_header)) self.assertIsNotNone(ts.add_task_header(new_header)) self.assertEqual(len(ts.get_tasks_headers()), 2) saved_task = next(th for th in ts.get_tasks_headers() if th["task_id"] == "xyz_2") self.assertEqual(saved_task["signature"], new_header["signature"])
def test_verify(self): keys_auth = EllipticalKeysAuth(self.path) conn = Mock() ts = TaskSession(conn) ts.task_server = Mock() ts.task_server.verify_sig = keys_auth.verify msg = message.MessageRemoveTask() assert not ts.verify(msg) msg.sig = keys_auth.sign(msg.get_short_hash()) ts.key_id = keys_auth.get_key_id() assert ts.verify(msg)
def test_comparison(self): k = EllipticalKeysAuth(self.path) e = urandom(20) a = EthAccountInfo(k.get_key_id(), 5111, "10.0.0.1", "test-test-test", Node(), e) b = EthAccountInfo(k.get_key_id(), 5111, "10.0.0.1", "test-test-test", Node(), e) self.assertEqual(a, b) n = Node(prv_addr="10.10.10.10", prv_port=1031, pub_addr="10.10.10.10", pub_port=1032) c = EthAccountInfo(k.get_key_id(), 5112, "10.0.0.2", "test-test2-test", n, e) self.assertEqual(a, c) k.generate_new(2) c.key_id = k.get_key_id() self.assertNotEqual(a, c)
def _add_task(self): keys_auth = EllipticalKeysAuth(self.path) client = MockClient() new_config_desc = MockConfig(self.path, node_name) dir_manager = DirManager(new_config_desc.root_path) rs = BaseResourceServer(TestResourceManager(self.dir_manager), dir_manager, keys_auth, client) rm = rs.resource_manager rm.storage.clear_cache() existing_paths = self._resources() return rm, rs, rs.add_task(existing_paths, self.task_id)
def test_get_diagnostic(self): m = MagicMock() m.transport.getPeer.return_value.port = "10432" m.transport.getPeer.return_value.host = "10.10.10.10" ps1 = PeerSession(m) ps1.key_id = self.keys_auth.key_id self.service.add_peer(self.keys_auth.key_id, ps1) m2 = MagicMock() m2.transport.getPeer.return_value.port = "11432" m2.transport.getPeer.return_value.host = "127.0.0.1" ps2 = PeerSession(m2) keys_auth2 = EllipticalKeysAuth(self.path, "PUBTESTPATH1", "PUBTESTPATH2") ps2.key_id = keys_auth2.key_id self.service.add_peer(keys_auth2.key_id, ps2) self.service.get_diagnostics(DiagnosticsOutputFormat.json)
def testAddFilesToGet(self): keys_auth = EllipticalKeysAuth(self.path) rs = BaseResourceServer(TestResourceManager(self.dir_manager), self.dir_manager, keys_auth, MockClient()) test_files = [ ['file1.txt', '1'], [os.path.join('tmp', 'file2.bin'), '2'] ] assert not rs.pending_resources rs.download_resources(test_files, self.task_id) assert len(rs.pending_resources[self.task_id]) == len(test_files) return rs, test_files
def test_retry_sending_task_result(self): ccd = self._get_config_desc() ts = TaskServer(Node(), ccd, EllipticalKeysAuth(self.path), self.client, use_docker_machine_manager=False) self.ts = ts ts.network = Mock() subtask_id = 'xxyyzz' wtr = Mock() wtr.already_sending = True ts.results_to_send[subtask_id] = wtr ts.retry_sending_task_result(subtask_id) self.assertFalse(wtr.already_sending)
def testRemoveTask(self): keys_auth = EllipticalKeysAuth(self.path) client = MockClient() rs = BaseResourceServer(TestResourceManager(self.dir_manager), self.dir_manager, keys_auth, client) rm = rs.resource_manager rm.add_files(self._resources(), self.task_id, absolute_path=True) assert rm.storage.get_resources(self.task_id) rs.remove_task(self.task_id) resources = rm.storage.get_resources(self.task_id) assert not resources
def test_remove_old_peers(self): node = MagicMock() node.key = EllipticalKeysAuth(self.path, "TESTPRIV", "TESTPUB").get_key_id() node.key_id = node.key self.service.last_peers_request = time.time() + 10 self.service.add_peer(node.key, node) assert len(self.service.peers) == 1 node.last_message_time = 0 self.service.sync_network() assert len(self.service.peers) == 0 self.service.add_peer(node.key, node) self.service.peers[node.key].last_message_time = time.time() + 1000 assert len(self.service.peers) == 1 self.service.sync_network() assert len(self.service.peers) == 1
def test_broadcast_on_name_change(self): conn = MagicMock() peer = PeerSession(conn) peer.hello_called = False def fake_hello(self): self.hello_called = True import types peer.hello = types.MethodType(fake_hello, peer) keys_auth = EllipticalKeysAuth(self.path, "PUBTESTPATH1", "PUBTESTPATH2") peer.key_id = keys_auth.key_id self.service.add_peer(keys_auth.key_id, peer) ccd = ClientConfigDescriptor() assert not peer.hello_called self.service.change_config(ccd) assert not peer.hello_called # negative test ccd = ClientConfigDescriptor() ccd.node_name = "test sending hello on name change" self.service.change_config(ccd) assert peer.hello_called # positive test
def test_connection_for_task_request_established(self): ccd = self._get_config_desc() ccd.min_price = 11 n = Node() ka = EllipticalKeysAuth(self.path) ts = TaskServer(n, ccd, ka, self.client, use_docker_machine_manager=False) self.ts = ts session = Mock() session.address = "10.10.10.10" session.port = 1020 ts.conn_established_for_type[TASK_CONN_TYPES['task_request']](session, "abc", "nodename", "key", "xyz", 1010, 30, 3, 1, 2) self.assertEqual(session.task_id, "xyz") self.assertEqual(session.key_id, "key") self.assertEqual(session.conn_id, "abc") self.assertEqual(ts.task_sessions["xyz"], session) session.send_hello.assert_called_with() session.request_task.assert_called_with("nodename", "xyz", 1010, 30, 3, 1, 2)
def test_progress(self): long_string = "abcdefghijklmn opqrstuvwxyz" datas = ( ("", None), ("abcde", None), (long_string, 8), (long_string * 1000, 16), (long_string * 1000, 128), # (long_string * 1000 * 1000 * 10, None) # This takes some time. ) for args in datas: self.__producer_consumer_test(*args, session=MagicMock()) self.ek = EllipticalKeysAuth(self.path) for args in datas: self.__producer_consumer_test(*args, data_producer_cls=EncryptDataProducer, data_consumer_cls=DecryptDataConsumer, session=self.__make_encrypted_session_mock())
def test_progress(self): self.__producer_consumer_test([], session=MagicMock()) self.__producer_consumer_test([self.tmp_file1], session=MagicMock()) self.__producer_consumer_test([self.tmp_file2], session=MagicMock()) self.__producer_consumer_test([self.tmp_file1, self.tmp_file3], session=MagicMock()) self.__producer_consumer_test([self.tmp_file1, self.tmp_file2, self.tmp_file3], 32, session=MagicMock()) self.ek = EllipticalKeysAuth(self.path) self.__producer_consumer_test([], file_producer_cls=EncryptFileProducer, file_consumer_cls=DecryptFileConsumer, session=self.__make_encrypted_session_mock()) self.__producer_consumer_test([self.tmp_file1], file_producer_cls=EncryptFileProducer, file_consumer_cls=DecryptFileConsumer, session=self.__make_encrypted_session_mock()) self.__producer_consumer_test([self.tmp_file2], file_producer_cls=EncryptFileProducer, file_consumer_cls=DecryptFileConsumer, session=self.__make_encrypted_session_mock()) self.__producer_consumer_test([self.tmp_file1, self.tmp_file3], file_producer_cls=EncryptFileProducer, file_consumer_cls=DecryptFileConsumer, session=self.__make_encrypted_session_mock()) self.__producer_consumer_test([self.tmp_file1, self.tmp_file2, self.tmp_file3], 32, file_producer_cls=EncryptFileProducer, file_consumer_cls=DecryptFileConsumer, session=self.__make_encrypted_session_mock())
def test_sync_free_peers(self): node = MagicMock() node.key = EllipticalKeysAuth(self.path, "PRIVTEST", "PUBTEST").get_key_id() node.key_id = node.key node.pub_addr = '127.0.0.1' node.pub_port = 10000 self.service.config_desc.opt_peer_num = 10 self.service.free_peers.append(node.key) self.service.incoming_peers[node.key] = { 'address': '127.0.0.1', 'port': 10000, 'node': node, 'node_name': 'TEST', 'conn_trials': 0 } self.service.last_peers_request = time.time() - 60 self.service.sync_network() assert not self.service.free_peers assert len(self.service.pending_connections) == 1