Exemple #1
0
 async def do_server_test(self, server_command):
     if self.server == None:
         print("No server. Start Cra[ server")
         try:
             self.server = await playground.create_server(
                 lambda: self.server_test_protocol,
                 port=self.my_server_port,
                 family="crap")
         except Exception as e:
             raise Exception("Could not create server to execute command")
     if server_command == "accept":
         self.server_test_protocol = DummyProtocol()
         self.transport.write(
             autograder_packets.AutogradeCommandAck().__serialize__())
         await self.server_test_protocol.connected
         if self.server_test_protocol.transport and not self.server_test_protocol.transport.is_closing(
         ):
             self.server_test_protocol.transport.close()
     elif server_command == "echo":
         self.server_test_protocol = DummyEchoProtocol()
         self.transport.write(
             autograder_packets.AutogradeCommandAck().__serialize__())
         await self.server_test_protocol.disconnected
         print("Server test disconnected. Close transport.",
               self.server_test_protocol.transport)
         if self.server_test_protocol.transport and not self.server_test_protocol.transport.is_closing(
         ):
             self.server_test_protocol.transport.close()
 async def do_client_test(self, client_command):
     print("client test got command {}".format(client_command))
     self.transport.write(autograder_packets.AutogradeCommandAck().__serialize__())
     print("Wrote ack")
     try:
         transport, protocol = await playground.create_connection(
             DummyProtocol,
             host="crap://{}".format(self.server_addr), 
             port=self.server_port)
     except Exception as e:
         raise Exception("Could not connect to server to execute command")
     if client_command == "connect":
         # just disconnect now
         if not transport.is_closing():
             transport.close()