示例#1
0
 def test_existing_pid(self) -> None:
     config = Config(LABBY_CONFIG_YAML)
     with patch_file_contents(".labby/pid", "12345"):
         server = Server(config)
         server_info = server.start()
         self.assertTrue(server_info.existing)
         self.assertEqual(server_info.pid, 12345)
示例#2
0
 def test_parent_process_on_start(self, makedirs: MagicMock,
                                  _fork_mock: MagicMock) -> None:
     config = Config(LABBY_CONFIG_YAML)
     with patch_file_contents(".labby/pid") as pidfile:
         server = Server(config)
         server_info = server.start()
         self.assertFalse(server_info.existing)
         self.assertEqual(server_info.pid, FAKE_PID)
         makedirs.assert_called_with(".labby", exist_ok=True)
         pidfile.write.assert_called_once_with(str(FAKE_PID))
示例#3
0
    def test_child_process_on_start(
        self,
        rep0_mock: MagicMock,
        remove_mock: MagicMock,
        _makedirs: MagicMock,
        _fork_mock: MagicMock,
    ) -> None:
        config = Config(LABBY_CONFIG_YAML)
        with patch_file_contents(".labby/pid"):
            rep0_mock.return_value.__enter__.return_value.recv.return_value = (
                b"HaltRequest:" + cast(bytes, HaltRequest().to_msgpack())
            )

            server = Server(config)
            with self.assertRaises(SystemExit):
                server.start()
        remove_mock.assert_called_once_with(".labby/pid")
示例#4
0
文件: server.py 项目: motte/labby
    def main(self, args: ServerArgumentParser) -> int:
        if args.command == "start":
            server = Server(self.config)
            server.start()
            return 0

        if args.command == "status":
            response = self.get_client().hello()
            if response == "Hello world":
                msg.good("Active")
                return 0
            msg.fail("Invalid response")
            msg.text(
                "Server replied with an invalid response. This is probably a bug."
            )
            return 1

        if args.command == "stop":
            self.get_client().halt()
            return 0

        raise Exception(f"Unknown server command {args.command}")
示例#5
0
    def setUp(self) -> None:
        auto_discover_drivers()
        config: Config = Config(LABBY_CONFIG_YAML)
        server: Server = Server(config)

        def _handle(msg: EncodedData) -> None:
            response_bytes = ServerRequest.handle_from_msgpack(server, msg)
            self.req_mock.return_value.recv.return_value = response_bytes

        self.req_patch = patch("labby.client.Req0")
        self.req_mock = self.req_patch.start()
        self.req_mock.return_value.send.side_effect = _handle

        self.client = Client("foobar")
示例#6
0
 def handle(self, server: Server) -> ExperimentStatusResponse:
     return ExperimentStatusResponse(
         sequence_status=server.get_experiment_sequence_status()
     )
示例#7
0
 def handle(self, server: Server) -> None:
     server.stop()