def should_accept_client_and_boot_client_on_stop(): ip = 'localhost' port = 5000 # engine = Engine(mtu=MTU) receiver = Receiver() # # step: start rail_line_console = RailLineConsole() rail_h = 'test/line_console' rail_line_console.zero( rail_h=rail_h, cb_line_console_connect=receiver.on_line_console_connect, cb_line_console_condrop=receiver.on_line_console_condrop, cb_line_console_command=receiver.on_line_console_command, engine=engine) rail_line_console.start(ip=ip, port=port) # # verify engine.cycle() assert rail_line_console.is_server_listening() == True assert rail_line_console.is_accept_connected() == False # # step: client connects client = engine.init_spin(construct=SpinBasicTcpClient) client.start(addr=ip, port=port) # # verify engine.cycle() assert rail_line_console.is_server_listening() == False assert rail_line_console.is_accept_connected() == True assert client.is_connected() == True # # step: server is stopped with client attached rail_line_console.stop() # # confirm effects engine.cycle() assert rail_line_console.is_server_listening() == False assert rail_line_console.is_accept_connected() == False assert client.is_connected() == False # return True
def should_transfer_of_text(): ip = 'localhost' port = 5000 # engine = Engine(mtu=MTU) receiver = Receiver() # # step: start it rail_line_console = RailLineConsole() rail_h = 'test/line_console' rail_line_console.zero( rail_h=rail_h, cb_line_console_connect=receiver.on_line_console_connect, cb_line_console_condrop=receiver.on_line_console_condrop, cb_line_console_command=receiver.on_line_console_command, engine=engine) rail_line_console.start(ip=ip, port=port) # # verify engine.cycle() assert rail_line_console.is_server_listening() == True assert rail_line_console.is_accept_connected() == False # # step: client connects client = engine.init_spin(construct=SpinBasicTcpClient) client.start(addr=ip, port=port) # # verify engine.cycle() assert rail_line_console.is_server_listening() == False assert rail_line_console.is_accept_connected() == True assert client.is_connected() == True # # step: client sends text that does not have a newline client.send(msg="abc def") # emphasis: no newline # # verify: we should not have received a line engine.cycle() assert 0 == len(receiver.sb) # # step: now send a new line and some overflow client.send(msg="\noverflow") client.send(msg="/second half") # # verify: we should have seen our first line engine.cycle() assert 1 == len(receiver.sb) assert receiver.sb[0] == ['abc', 'def'] # # step: another line ending client.send(msg='\n') # # verify engine.cycle() assert 2 == len(receiver.sb) assert receiver.sb[-1] == ['overflow/second', 'half'] # # step: multiple lines in one pass client.send(msg="three\nfour\n") # # verify engine.cycle() assert 4 == len(receiver.sb) assert receiver.sb[-2] == [ 'three', ] assert receiver.sb[-1] == [ 'four', ] # # step: we write to client s = "here is some text\n" rail_line_console.send(msg=s) # # verify engine.cycle() assert 1 == len(client.sb) assert client.sb[-1] == s # return True