예제 #1
0
async def test_timeout(client):
    # Arrange
    # setup dds / csc
    salobj.set_random_lsst_dds_partition_prefix()
    next(index_gen)
    csc = salobj.TestCsc(index=1, config_dir=None, initial_state=salobj.State.ENABLED)
    await csc.start_task

    # build data
    csc.make_random_scalars_dict()
    data = json.loads(
        json.dumps(
            {
                "csc": "Test",
                "salindex": 1,
                "cmd": "cmd_wait",
                "params": {
                    "duration": -11,
                    "ack": salobj.SalRetCode.CMD_COMPLETE.value,
                },
            },
            cls=NumpyEncoder,
        )
    )

    # Act
    response = await client.post("/cmd", json=data)

    # Assert status
    await response.json()

    assert response.status == 504
    await csc.close()
    async def check_executable(self, script_path):
        """Check that an executable script can be launched.

        Parameter
        ---------
        script_path : `str`
            Full path to script.
        """
        salobj.set_random_lsst_dds_partition_prefix()

        index = self.next_index()

        script_path = pathlib.Path(script_path).resolve()

        assert script_path.is_file()

        async with salobj.Domain() as domain, salobj.Remote(
                domain=domain, name="Script", index=index) as remote:

            initial_path = os.environ["PATH"]
            try:
                os.environ["PATH"] = str(
                    script_path.parent) + ":" + initial_path
                process = await asyncio.create_subprocess_exec(
                    str(script_path), str(index))

                state = await remote.evt_state.next(flush=False,
                                                    timeout=MAKE_TIMEOUT)
                assert state.state == Script.ScriptState.UNCONFIGURED
            finally:
                process.terminate()
                os.environ["PATH"] = initial_path
예제 #3
0
async def test_successful_command(client):
    # Arrange
    # setup dds / csc
    salobj.set_random_lsst_dds_partition_prefix()
    next(index_gen)
    csc = salobj.TestCsc(index=1, config_dir=None, initial_state=salobj.State.ENABLED)
    await csc.start_task

    # build data
    cmd_data = csc.make_random_scalars_dict()
    data = json.loads(
        json.dumps(
            {
                "csc": "Test",
                "salindex": 1,
                "cmd": "cmd_setScalars",
                "params": cmd_data,
            },
            cls=NumpyEncoder,
        )
    )

    # Act
    response = await client.post("/cmd", json=data)

    # Assert status
    assert response.status == 200

    # Assert content
    response_data = await response.json()
    assert response_data == {"ack": "Done"}

    await csc.close()
예제 #4
0
async def test_all_topic_names(client):
    """Test the get topic_names response."""
    salobj.set_random_lsst_dds_partition_prefix()
    async with salobj.Domain() as domain:
        domain = salobj.Domain()
        available_idl_files = list(domain.idl_dir.glob(idl_glob))
        names = [
            file.name.split("_", )[-1].replace(".idl", "")
            for file in available_idl_files
        ]
        names = names[:conftest.REMOTES_LEN_LIMIT]

        response = await client.get("/salinfo/topic-names")

        assert response.status == 200

        response_data = await response.json()

        for name, data in response_data.items():
            # assert name in names
            assert "command_names" in data
            assert "event_names" in data
            assert "telemetry_names" in data
            assert type(data["command_names"]) == list
            assert type(data["event_names"]) == list
            assert type(data["telemetry_names"]) == list
예제 #5
0
    def run(self, result=None):
        """Override `run` to insert mocks for every test.

        https://stackoverflow.com/a/11180583
        """
        salobj.set_random_lsst_dds_partition_prefix()
        with salkafka.mocks.insert_all_mocks():
            super().run(result)
예제 #6
0
    def run(self, result: typing.Any) -> None:
        """Override `run` to set a random LSST_DDS_PARTITION_PREFIX
        and set LSST_SITE=test for every test.

        https://stackoverflow.com/a/11180583
        """
        salobj.set_random_lsst_dds_partition_prefix()
        with utils.modify_environ(LSST_SITE="test"):
            super().run(result)
예제 #7
0
 def test_set_random_lsst_dds_partition_prefix(self) -> None:
     random.seed(42)
     NumToTest = 1000
     names = set()
     for i in range(NumToTest):
         salobj.set_random_lsst_dds_partition_prefix()
         name = os.environ.get("LSST_DDS_PARTITION_PREFIX")
         assert name
         names.add(name)
         assert "." not in name  # type: ignore
     # any duplicate names will reduce the size of names
     assert len(names) == NumToTest
    async def make_script(self,
                          log_level=logging.INFO,
                          timeout=MAKE_TIMEOUT,
                          verbose=False):
        """Create a Script.

        The script is accessed as ``self.script``.

        Parameters
        ----------
        name : `str`
            Name of SAL component.
        log_level : `int` (optional)
            Logging level, such as `logging.INFO`.
        timeout : `float`
            Timeout (sec) for waiting for ``item.start_task`` and
            ``item.close()`` for each item returned by `basic_make_script`,
            and `self.close`.
        verbose : `bool`
            Log data? This can be helpful for setting ``timeout``.
        """
        salobj.set_random_lsst_dds_partition_prefix()

        items_to_await = await self.wait_for(
            self.basic_make_script(index=self.next_index()),
            timeout=timeout,
            description="self.basic_make_script()",
            verbose=verbose,
        )
        try:
            await self.wait_for(
                asyncio.gather(*[item.start_task for item in items_to_await]),
                timeout=timeout,
                description=f"item.start_task for {len(items_to_await)} items",
                verbose=verbose,
            )
            yield
        finally:
            await self.wait_for(
                self.close(),
                timeout=timeout,
                description="self.close()",
                verbose=verbose,
            )
            await self.wait_for(
                asyncio.gather(*[item.close() for item in items_to_await]),
                timeout=timeout,
                description=f"item.close() for {len(items_to_await)} items",
                verbose=verbose,
            )
예제 #9
0
    def setUp(self):
        salobj.set_random_lsst_dds_partition_prefix()
        self.data_dir = pathlib.Path(
            __file__).parent / "data" / "topic_names_sets"

        broker_url = "test.kafka:9000"
        registry_url = "https://registry.test.kafka/"
        partitions = 2
        replication_factor = 3
        wait_for_ack = 1

        self.kafka_config = salkafka.KafkaConfiguration(
            broker_url=broker_url,
            registry_url=registry_url,
            partitions=partitions,
            replication_factor=replication_factor,
            wait_for_ack=wait_for_ack,
        )
예제 #10
0
async def test_some_topic_names(client):
    """Test the use of query params to get only some of the topic_names."""
    salobj.set_random_lsst_dds_partition_prefix()
    async with salobj.Domain() as domain:
        domain = salobj.Domain()
        available_idl_files = list(domain.idl_dir.glob(idl_glob))
        names = [
            file.name.split("_", )[-1].replace(".idl", "")
            for file in available_idl_files
        ]
        names = names[:conftest.REMOTES_LEN_LIMIT]

        # Get all combinations of categories:
        categories = ["command", "event", "telemetry"]
        combs = chain.from_iterable(
            combinations(categories, r) for r in range(len(categories) + 1))

        for comb in combs:
            # Get categories to be requested and not to be requested
            requested = list(comb)
            non_req = list(set(categories) - set(requested))
            query_param = "-".join(requested)
            # Requeste them
            response = await client.get("/salinfo/topic-names?categories=" +
                                        query_param)
            assert response.status == 200
            response_data = await response.json()

            # If query_params is empty no filtering is applied:
            if len(requested) == 0:
                requested = categories
                non_req = []

            for _, data in response_data.items():
                # Assert that requested categories are in the response
                for r in requested:
                    key = r + "_names"
                    assert key in data
                    assert type(data[key]) == list
                # Assert that non-requested categories are NOT in the response
                for nr in non_req:
                    key = nr + "_names"
                    assert key not in data
예제 #11
0
async def test_metadata(client):
    """Test the get metadata response."""
    salobj.set_random_lsst_dds_partition_prefix()
    async with salobj.Domain() as domain:
        domain = salobj.Domain()
        available_idl_files = list(domain.idl_dir.glob(idl_glob))
        names = [
            file.name.split("_", )[-1].replace(".idl", "")
            for file in available_idl_files
        ]
        names = names[:conftest.REMOTES_LEN_LIMIT]

        response = await client.get("/salinfo/metadata")

        assert response.status == 200

        response_data = await response.json()

        for name, data in response_data.items():
            # assert name in names
            assert "sal_version" in data
            assert "xml_version" in data
            assert data["sal_version"].count(".") == 2
            assert data["xml_version"].count(".") == 2
예제 #12
0
 def setUp(self):
     salobj.set_random_lsst_dds_partition_prefix()
예제 #13
0
 def setUp(self) -> None:
     salobj.set_random_lsst_dds_partition_prefix()
     self.datadir = pathlib.Path(__file__).resolve().parent / "data"
     self.index = next(index_gen)
예제 #14
0
 async def asyncSetUp(self) -> None:
     salobj.set_random_lsst_dds_partition_prefix()
예제 #15
0
파일: test_csc.py 프로젝트: lsst-ts/ts_dsm
 def setUp(self):
     salobj.set_random_lsst_dds_partition_prefix()
     self.telemetry_directory = ""
예제 #16
0
 def setUp(self) -> None:
     salobj.set_random_lsst_dds_partition_prefix()
     self.index = next(index_gen)