def test_run_analytics_task(self):
        """Tests that the each function is called for each filtered observable."""
        mock_inner_each = mock.MagicMock()

        class FakeTask(AnalyticsTask):
            _defaults = {
                "frequency": datetime.timedelta(hours=1),
                "type": "analytics",
                "description": "Dummy analytics",
                "enabled": True,
            }

            acts_on: list[str] = ["hostname"]

            def each(self, observable):
                # Do nothing, except call the mock.
                mock_inner_each(observable.value)

        taskmanager.TaskManager.register_task(FakeTask)
        time.sleep(0.5)
        taskmanager.TaskManager.run_task("FakeTask", TaskParams())
        task = FakeTask.find(name="FakeTask")
        assert task is not None
        self.assertEqual(task.status, TaskStatus.completed, task.status_message)
        self.assertIsNotNone(task.last_run)
        mock_inner_each.assert_has_calls(
            [
                mock.call(self.observable1.value),
                mock.call(self.observable2.value),
                mock.call(self.observable3.value),
            ],
            any_order=True,
        )
        self.assertEqual(mock_inner_each.call_count, 3)
Tests that the each function is called for each filtered observable.
tests/core_tests/tasks.py