Ejemplo n.º 1
0
 async def test_creates_default_companion(self) -> None:
     companion_manager = CompanionManager(companion_path=None,
                                          logger=mock.MagicMock())
     add_companion(companion_manager, TEST_COMPANION)
     async with companion_manager.create_companion_for_target_with_udid(
             None, None) as yielded_companion:
         self.assertEqual(yielded_companion, TEST_COMPANION)
Ejemplo n.º 2
0
 async def test_remove_companion_by_udid(self) -> None:
     companion_manager = CompanionManager(logger=mock.MagicMock())
     add_companion(companion_manager, TEST_COMPANION)
     self.assertEqual(len(companion_manager._udid_companion_map), 1)
     self.assertEqual(len(companion_manager._udid_target_map), 1)
     result = companion_manager.remove_companion(TEST_COMPANION.udid)
     self.assertEqual(result, TEST_COMPANION)
     self.assertEqual(len(companion_manager._udid_companion_map), 0)
     self.assertEqual(len(companion_manager._udid_target_map), 0)
Ejemplo n.º 3
0
 async def test_add_companion_with_host_and_port_adds_companion(
         self) -> None:
     companion_manager = CompanionManager(logger=mock.MagicMock())
     companion_manager.add_companion(
         CompanionInfo(udid="asdasda",
                       host="foohost",
                       port=123,
                       is_local=False))
     assert companion_manager._udid_companion_map["asdasda"]
Ejemplo n.º 4
0
 async def test_remove_companion_by_address(self) -> None:
     companion_manager = CompanionManager(companion_path=None,
                                          logger=mock.MagicMock())
     add_companion(companion_manager, TEST_COMPANION)
     self.assertEqual(len(companion_manager._udid_companion_map), 1)
     self.assertEqual(len(companion_manager._udid_target_map), 1)
     result = companion_manager.remove_companion(
         Address(host=TEST_COMPANION.host, port=TEST_COMPANION.port))
     self.assertEqual(result, TEST_COMPANION)
     self.assertEqual(len(companion_manager._udid_companion_map), 0)
     self.assertEqual(len(companion_manager._udid_target_map), 0)
Ejemplo n.º 5
0
async def start_daemon_server(args: Namespace, logger: Logger) -> Server:
    grpc_port = args.daemon_grpc_port
    notifier_path = args.notifier_path
    companion_manager = CompanionManager(companion_path=notifier_path,
                                         logger=logger)
    boot_manager = BootManager(companion_path=notifier_path)
    grpc_handler = GRPCHandler(companion_manager=companion_manager,
                               boot_manager=boot_manager,
                               logger=logger)
    grpc_server = GRPCServer(handler=grpc_handler, logger=logger)
    await grpc_server.start("localhost", grpc_port)
    servers: List[Server] = [grpc_server]
    if notifier_path:
        companion_tailer = CompanionTailer(notifier_path=notifier_path,
                                           companion_manager=companion_manager)
        await companion_tailer.start()
        servers.append(companion_tailer)
    servers = await plugin.resolve_servers(
        args=args,
        companion_manager=companion_manager,
        boot_manager=boot_manager,
        logger=logger,
        servers=servers,
    )
    logger.debug(f"Started servers {servers}")
    return CompositeServer(servers=servers, logger=logger)
Ejemplo n.º 6
0
 async def test_get_default_companion(self) -> None:
     companion_manager = CompanionManager(logger=mock.MagicMock())
     self.assertFalse(companion_manager.has_default_companion())
     add_companion(companion_manager, TEST_COMPANION)
     self.assertTrue(companion_manager.has_default_companion())
     self.assertEqual(companion_manager.get_default_companion(),
                      TEST_COMPANION)
     companion_manager.add_companion(
         CompanionInfo(
             udid="someOtherUdid",
             host=TEST_COMPANION.host,
             port=TEST_COMPANION.port,
             is_local=TEST_COMPANION.is_local,
         ))
     self.assertFalse(companion_manager.has_default_companion())
Ejemplo n.º 7
0
 async def test_closes_spawner_on_close(self) -> None:
     companion_manager = CompanionManager(companion_path=None,
                                          logger=mock.MagicMock())
     spawner = mock.Mock()
     companion_manager.companion_spawner = spawner
     companion_manager.channel = mock.Mock()
     companion_manager.close()
     spawner.close.assert_called_once()
Ejemplo n.º 8
0
 async def test_closes_spawner_on_close(self) -> None:
     companion_manager = CompanionManager(companion_path=None,
                                          logger=mock.MagicMock())
     spawner = mock.Mock()
     companion_manager.companion_spawner = spawner
     # pyre-fixme[16]: `CompanionManager` has no attribute `channel`.
     companion_manager.channel = mock.Mock()
     companion_manager.close()
     spawner.close.assert_called_once()
Ejemplo n.º 9
0
    async def test_read_stream(self) -> None:
        class StreamMock:
            i = 0
            lines: List[bytes] = [
                json.dumps({
                    "udid": "udid",
                    "state": "state",
                    "type": "type",
                    "name": "name",
                    "os_version": "os_version",
                    "architecture": "architecture",
                }).encode("utf-8"),
                json.dumps({
                    "initial_state_ended": True
                }).encode("utf-8"),
            ]

            async def readline(self) -> bytes:
                result = self.lines[self.i]
                self.i += 1
                return result

        manager = CompanionManager(mock.MagicMock())
        tailer = CompanionTailer("idb_path", manager)
        await tailer._read_stream(StreamMock())  # pyre-ignore
        self.assertEqual(
            manager._udid_target_map,
            {
                "udid":
                TargetDescription(
                    udid="udid",
                    name="name",
                    state="state",
                    target_type="type",
                    os_version="os_version",
                    architecture="architecture",
                    companion_info=None,
                    screen_dimensions=None,
                )
            },
        )
Ejemplo n.º 10
0
 async def test_add_companion_assigns_to_target(self) -> None:
     companion_manager = CompanionManager(logger=mock.MagicMock())
     companion_manager.update_target(
         TargetDescription(
             udid="asdasda",
             name="iPhone",
             state="Booted",
             target_type="simulator",
             os_version="iOS 11.4",
             architecture="x86_64",
             companion_info=None,
             screen_dimensions=None,
         ))
     companion_manager.add_companion(
         CompanionInfo(udid="asdasda",
                       host="foohost",
                       port=123,
                       is_local=False))
     assert companion_manager._udid_target_map["asdasda"].companion_info
Ejemplo n.º 11
0
def add_companion(companion_manager: CompanionManager,
                  companion: CompanionInfo = TEST_COMPANION) -> None:
    companion_manager.add_companion(companion)
Ejemplo n.º 12
0
 async def test_get_existing_companion(self) -> None:
     companion_manager = CompanionManager(logger=mock.MagicMock())
     add_companion(companion_manager, TEST_COMPANION)
     async with companion_manager.create_companion_for_target_with_udid(
             TEST_COMPANION.udid, None) as yielded_compainion:
         self.assertEqual(yielded_compainion, TEST_COMPANION)