How to use process_messages method in prospector

Best Python code snippet using prospector_python

test_simple_node.py

Source:test_simple_node.py Github

copy

Full Screen

...29 assert 3 == len(node.incoming_messages)30 assert (2.5, fake_block, 5) == node.incoming_messages[0]31 assert (3.5, fake_block, 42) == node.incoming_messages[1]32 assert (5.5, fake_block, 34) == node.incoming_messages[2]33def test_process_messages():34 clock = CheatedClock(time=0)35 latency_policy = StaticLatencyPolicy(base_delay=1.5)36 genesis = Block.genesis(37 timestamp=0,38 compact_target=b'\xff\xff\xff\xff',39 vout=[100, 100, 100, 100]40 )41 funds_a = set(genesis.coinstake_tx.get_all_coins()[:2])42 funds_d = set(genesis.coinstake_tx.get_all_coins()[2:])43 # Preparing the nodes44 node_a = SimpleNode(45 node_id=0,46 latency_policy=latency_policy,47 chain=BlockChain(genesis=genesis, clock=clock),48 initial_coins=funds_a,49 processing_time=0.1,50 is_proposer=True51 )52 node_b = SimpleNode(53 node_id=1,54 latency_policy=latency_policy,55 chain=BlockChain(genesis=genesis, clock=clock),56 initial_coins=set(),57 processing_time=0.1,58 is_proposer=False59 )60 node_c = SimpleNode(61 node_id=2,62 latency_policy=latency_policy,63 chain=BlockChain(genesis=genesis, clock=clock),64 initial_coins=set(),65 processing_time=0.1,66 is_proposer=False67 )68 # node_a --> node_b --> node_c69 node_a.add_outbound_peer(node_b)70 node_b.add_outbound_peer(node_c)71 # Let's test message propagation72 ############################################################################73 clock.advance_time(1) # time == 174 assert node_a.main_chain.height == 075 assert node_a.try_to_propose() # True because the target is trivial76 assert node_a.main_chain.height == 177 assert node_b.main_chain.height == 078 assert node_c.main_chain.height == 079 node_b.process_messages() # 1.5 + 0.1 seconds left80 node_c.process_messages()81 assert node_a.main_chain.height == 182 assert node_b.main_chain.height == 083 assert node_c.main_chain.height == 084 clock.advance_time(1) # time == 285 node_b.process_messages() # 0.6 seconds left...86 node_c.process_messages()87 assert node_a.main_chain.height == 188 assert node_b.main_chain.height == 089 assert node_c.main_chain.height == 090 clock.advance_time(1) # time == 391 node_b.process_messages()92 node_c.process_messages()93 assert node_a.main_chain.height == 194 assert node_b.main_chain.height == 1 # The message "arrived" at time=2.695 assert node_c.main_chain.height == 096 clock.advance_time(1) # time == 497 node_b.process_messages()98 node_c.process_messages()99 assert node_a.main_chain.height == 1100 assert node_b.main_chain.height == 1101 assert node_c.main_chain.height == 0 # 0.2 seconds left to add the block102 clock.advance_time(1) # time == 5103 node_b.process_messages()104 node_c.process_messages()105 assert node_a.main_chain.height == 1106 assert node_b.main_chain.height == 1107 assert node_c.main_chain.height == 1 # The message "arrived" at time=4.2108 # We'll create some forks now, but let's check some pre-conditions before109 ############################################################################110 assert 0 == len(node_a.alternative_chains)111 assert 0 == len(node_b.alternative_chains)112 assert 0 == len(node_c.alternative_chains)113 node_d = SimpleNode(114 node_id=3,115 latency_policy=latency_policy,116 chain=BlockChain(genesis=genesis, clock=clock),117 initial_coins=funds_d,118 processing_time=0.1,119 is_proposer=True120 )121 # node_a ----> node_b --> node_c122 # node_d --┘123 node_d.add_outbound_peer(node_b)124 assert node_d.try_to_propose() # Let's create a fork (from b's perspective)125 chain_b = node_b.main_chain # We cache the reference just in case of re-org126 clock.advance_time(2) # time == 7127 node_b.process_messages()128 assert node_d.main_chain.height == 1129 assert node_b.main_chain.height == 1 # the height was not changed130 assert len(node_d.alternative_chains) == 0 # d does not see any fork131 assert len(node_b.alternative_chains) == 1 # We have a fork132 # node_b didn't do re-org, because chain work is the same for both forks133 assert node_b.main_chain is chain_b134 # Let's extend the fork, to force a re-org135 ############################################################################136 assert node_d.try_to_propose()137 clock.advance_time(2) # time == 9138 node_b.process_messages()139 assert node_d.main_chain.height == 2140 assert node_b.main_chain.height == 2141 assert len(node_d.alternative_chains) == 0 # Nothing changed here142 assert len(node_b.alternative_chains) == 1 # Nothing changed here143 assert node_b.main_chain is not chain_b # We had a re-org :) .144 # Now we'll check that SimpleNode is able to deal with orphan blocks145 ############################################################################146 assert len(node_a.orphan_blocks) == 0147 # node_a will receive a message from nowhere...148 node_a.receive_message(149 arrival_time=9.5,150 msg=node_d.main_chain.blocks[-1], # node_a won't know its parent,151 source_id=node_d.node_id152 )153 clock.advance_time(1) # time == 10154 node_a.process_messages()155 assert len(node_a.orphan_blocks) == 1 # as expected, the block is orphan156 assert len(node_a.alternative_chains) == 0 # Nothing changed here157 assert node_a.main_chain.height == 1 # Nothing changed here158 # node_a receives the missing parent159 node_a.receive_message(160 arrival_time=10.5,161 msg=node_d.main_chain.blocks[-2], # this is the orphan's parent162 source_id=node_d.node_id163 )164 clock.advance_time(1) # time == 11165 node_a.process_messages()166 assert len(node_a.orphan_blocks) == 0 # No orphans anymore167 assert len(node_a.alternative_chains) == 1 # Now we have a fork168 assert node_a.main_chain.height == 2 # And did also a re-org169 # Now we want to check that the nodes b & c don't create new tips for the170 # blocks that they already know (they receive the blocks again from node_a).171 # We let pass some time to process all the already pending messages172 clock.advance_time(2)173 node_b.process_messages()174 node_c.process_messages()175 assert len(node_b.incoming_messages) == 0 # All messages are processed.176 assert len(node_c.incoming_messages) == 0177 # And now we send again blocks that the node already knows (main chain)178 node_c.receive_message(179 arrival_time=clock.get_time() + 0.1,180 msg=node_c.main_chain.blocks[-1],181 source_id=42182 )183 node_c.receive_message(184 arrival_time=clock.get_time() + 0.2,185 msg=node_c.main_chain.blocks[-2],186 source_id=42187 )188 node_c.receive_message(189 arrival_time=clock.get_time() + 0.3,190 msg=node_c.main_chain.blocks[-3],191 source_id=42192 )193 clock.advance_time(1)194 assert node_c.process_messages() == 0 # The node does not relay them again.195 assert len(node_c.incoming_messages) == 0196 assert len(node_c.alternative_chains) == 1197 assert node_c.main_chain.height == 2198 # Regression test: And now we send again blocks that the node already knows199 # (from an alternative chain).200 node_c.receive_message(201 arrival_time=clock.get_time() + 0.1,202 msg=node_c.alternative_chains[0].blocks[-1],203 source_id=42204 )205 clock.advance_time(1)206 assert node_c.process_messages() == 0207 assert len(node_c.incoming_messages) == 0...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1import json, os2from azure.storage.queue import (3 QueueService,4 QueueMessageFormat5)6import azure.functions as func7from NewDeclarationInQueue.formular_converter import FormularConverter8from NewDeclarationInQueue.preprocess.document_location import DocumentLocation9from NewDeclarationInQueue.preprocess.ocr_constants import OcrConstants10from NewDeclarationInQueue.preprocess_two_steps import PreProcessTwoSteps11from NewDeclarationInQueue.processfiles.ocr_worker import OcrWorker12from NewDeclarationInQueue.processfiles.process_messages import ProcessMessages13def main(msg: func.QueueMessage) -> None:14 message_str = msg.get_body().decode('utf-8')15 data = json.loads(message_str)16 17 two_steps = PreProcessTwoSteps()18 process_messages = ProcessMessages('OCR Process', msg.id)19 20 ocr_constants = two_steps.get_constats()21 ocr_file, process_messages = two_steps.get_file_info(data, process_messages)22 23 # TODO: this has to be done later, based on what the composite model returns24 # TODO: including when it returns a document it does not recognize25 #formular_converter = FormularConverter()26 #ocr_formular = formular_converter.get_formular_info(ocr_constants, ocr_file)27 28 #TODO: point of divergence, here call a method that uses the composite model29 #process_messages = two_steps.process_document(ocr_file, ocr_constants, ocr_formular, process_messages)30 process_messages = two_steps.process_document_with_custom_model(ocr_file, ocr_constants, process_messages)31 32 two_steps.save_in_output_queue(data, process_messages)33 ...

Full Screen

Full Screen

test_server.py

Source:test_server.py Github

copy

Full Screen

...10 ERROR: 'invalid request'11 }12 correct_dict = {RESPONSE: 200}13 def test_no_action(self):14 self.assertEqual(process_messages(15 {TIME: '2', USER: {ACCOUNT_NAME: 'Client'}}), self.error_dict)16 def test_wrong_action(self):17 self.assertEqual(process_messages(18 {ACTION: 'Some Action', TIME: '2', USER: {ACCOUNT_NAME: 'Client'}}), self.error_dict)19 def test_no_time(self):20 self.assertEqual(process_messages(21 {ACTION: PRESENCE, USER: {ACCOUNT_NAME: 'Client'}}), self.error_dict)22 def test_no_user(self):23 self.assertEqual(process_messages(24 {ACTION: PRESENCE, TIME: '2'}), self.error_dict)25 def test_unknown_user(self):26 self.assertEqual(process_messages(27 {ACTION: PRESENCE, TIME: 2, USER: {ACCOUNT_NAME: 'Guest'}}), self.error_dict)28 def test_correct(self):29 self.assertEqual(process_messages(30 {ACTION: PRESENCE, TIME: 2, USER: {ACCOUNT_NAME: 'Client'}}), self.correct_dict)31if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run prospector automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful