def test_create_channel_failure(circuit_pair): cli_circuit, srv_circuit = circuit_pair cid = cli_circuit.new_channel_id() sid = srv_circuit.new_channel_id() cli_channel = ca.ClientChannel('doomed', cli_circuit, cid) srv_channel = ca.ServerChannel('doomed', srv_circuit, sid) # Send and receive CreateChanRequest req = cli_channel.create() cli_circuit.send(req) commands, _ = srv_circuit.recv(bytes(req)) for command in commands: srv_circuit.process_command(command) # Send and receive CreateChFailResponse. res = ca.CreateChFailResponse(req.cid) buffers_to_send = srv_circuit.send(res) assert srv_channel.states[ca.CLIENT] is ca.FAILED assert srv_channel.states[ca.SERVER] is ca.FAILED assert cli_channel.states[ca.CLIENT] is ca.AWAIT_CREATE_CHAN_RESPONSE assert cli_channel.states[ca.SERVER] is ca.SEND_CREATE_CHAN_RESPONSE commands, _ = cli_circuit.recv(*buffers_to_send) for command in commands: cli_circuit.process_command(command) assert cli_channel.states[ca.CLIENT] is ca.FAILED assert cli_channel.states[ca.SERVER] is ca.FAILED
def make_channels(cli_circuit, srv_circuit, data_type, data_count, name='a'): cid = cli_circuit.new_channel_id() sid = srv_circuit.new_channel_id() cli_channel = ca.ClientChannel(name, cli_circuit, cid) srv_channel = ca.ServerChannel(name, srv_circuit, cid) req = cli_channel.create() cli_circuit.send(req) commands, num_bytes_needed = srv_circuit.recv(bytes(req)) for command in commands: srv_circuit.process_command(command) res = srv_channel.create(data_type, data_count, sid) srv_circuit.send(res) commands, num_bytes_needed = cli_circuit.recv(bytes(res)) for command in commands: cli_circuit.process_command(command) return cli_channel, srv_channel