diff --git a/pubnub/endpoints/endpoint.py b/pubnub/endpoints/endpoint.py index 62813672..aee7e370 100644 --- a/pubnub/endpoints/endpoint.py +++ b/pubnub/endpoints/endpoint.py @@ -204,9 +204,6 @@ def callback(params_to_merge): custom_params['pnsdk'] = self.pubnub.sdk_name custom_params['uuid'] = self.pubnub.uuid - for query_key, query_value in self.pubnub._telemetry_manager.operation_latencies().items(): - custom_params[query_key] = query_value - if self.is_auth_required(): if self.pubnub._get_token(): custom_params["auth"] = self.pubnub._get_token() diff --git a/pubnub/enums.py b/pubnub/enums.py index 98d07d6f..1e1c8a43 100644 --- a/pubnub/enums.py +++ b/pubnub/enums.py @@ -127,7 +127,6 @@ class PNOperationType(object): PNRemoveSpaceUsersOperation = 82 PNFetchUserMembershipsOperation = 85 PNFetchSpaceMembershipsOperation = 86 - # NOTE: remember to update PubNub.managers.TelemetryManager.endpoint_name_for_operation() when adding operations class PNHeartbeatNotificationOptions(object): diff --git a/pubnub/managers.py b/pubnub/managers.py index 48683793..a17b344d 100644 --- a/pubnub/managers.py +++ b/pubnub/managers.py @@ -1,22 +1,20 @@ import logging from abc import abstractmethod, ABCMeta -import time -import copy import base64 import random from cbor2 import loads -from . import utils -from .enums import PNStatusCategory, PNReconnectionPolicy, PNOperationType -from .models.consumer.common import PNStatus -from .models.server.subscribe import SubscribeEnvelope -from .dtos import SubscribeOperation, UnsubscribeOperation -from .callbacks import SubscribeCallback, ReconnectionCallback -from .models.subscription_item import SubscriptionItem -from .errors import PNERR_INVALID_ACCESS_TOKEN -from .exceptions import PubNubException +from pubnub import utils +from pubnub.enums import PNStatusCategory, PNReconnectionPolicy +from pubnub.models.consumer.common import PNStatus +from pubnub.models.server.subscribe import SubscribeEnvelope +from pubnub.dtos import SubscribeOperation, UnsubscribeOperation +from pubnub.callbacks import SubscribeCallback, ReconnectionCallback +from pubnub.models.subscription_item import SubscriptionItem +from pubnub.errors import PNERR_INVALID_ACCESS_TOKEN +from pubnub.exceptions import PubNubException logger = logging.getLogger("pubnub") @@ -398,171 +396,6 @@ def get_custom_params(self): return {} -class TelemetryManager: - TIMESTAMP_DIVIDER = 1000 - MAXIMUM_LATENCY_DATA_AGE = 60 - CLEAN_UP_INTERVAL = 1 - CLEAN_UP_INTERVAL_MULTIPLIER = 1000 - - def __init__(self): - self.latencies = {} - - @abstractmethod - def _start_clean_up_timer(self): - pass - - @abstractmethod - def _stop_clean_up_timer(self): - pass - - def operation_latencies(self): - operation_latencies = {} - - for endpoint_name, endpoint_latencies in self.latencies.items(): - latency_key = 'l_' + endpoint_name - - endpoint_average_latency = self.average_latency_from_data(endpoint_latencies) - - if endpoint_average_latency > 0: - operation_latencies[latency_key] = endpoint_average_latency - - return operation_latencies - - def clean_up_telemetry_data(self): - current_timestamp = time.time() - copy_latencies = copy.deepcopy(self.latencies) - - for endpoint_name, endpoint_latencies in copy_latencies.items(): - for latency_information in endpoint_latencies: - if current_timestamp - latency_information["timestamp"] > self.MAXIMUM_LATENCY_DATA_AGE: - self.latencies[endpoint_name].remove(latency_information) - - if len(self.latencies[endpoint_name]) == 0: - del self.latencies[endpoint_name] - - def store_latency(self, latency, operation_type): - if operation_type != PNOperationType.PNSubscribeOperation and latency > 0: - endpoint_name = self.endpoint_name_for_operation(operation_type) - - store_timestamp = time.time() - - if endpoint_name not in self.latencies: - self.latencies[endpoint_name] = [] - - latency_entry = { - "timestamp": store_timestamp, - "latency": latency, - } - - self.latencies[endpoint_name].append(latency_entry) - - @staticmethod - def average_latency_from_data(endpoint_latencies): - total_latency = 0 - - for latency_data in endpoint_latencies: - total_latency += latency_data['latency'] - - return total_latency / len(endpoint_latencies) - - @staticmethod - def endpoint_name_for_operation(operation_type): - endpoint = { - PNOperationType.PNPublishOperation: 'pub', - PNOperationType.PNFireOperation: 'pub', - PNOperationType.PNSendFileNotification: "pub", - - PNOperationType.PNHistoryOperation: 'hist', - PNOperationType.PNHistoryDeleteOperation: 'hist', - PNOperationType.PNMessageCountOperation: 'mc', - - PNOperationType.PNUnsubscribeOperation: 'pres', - PNOperationType.PNWhereNowOperation: 'pres', - PNOperationType.PNHereNowOperation: 'pres', - PNOperationType.PNGetState: 'pres', - PNOperationType.PNSetStateOperation: 'pres', - PNOperationType.PNHeartbeatOperation: 'pres', - - PNOperationType.PNAddChannelsToGroupOperation: 'cg', - PNOperationType.PNRemoveChannelsFromGroupOperation: 'cg', - PNOperationType.PNChannelGroupsOperation: 'cg', - PNOperationType.PNChannelsForGroupOperation: 'cg', - PNOperationType.PNRemoveGroupOperation: 'cg', - - PNOperationType.PNAddPushNotificationsOnChannelsOperation: 'push', - PNOperationType.PNPushNotificationEnabledChannelsOperation: 'push', - PNOperationType.PNRemoveAllPushNotificationsOperation: 'push', - PNOperationType.PNRemovePushNotificationsFromChannelsOperation: 'push', - - PNOperationType.PNAccessManagerAudit: 'pam', - PNOperationType.PNAccessManagerGrant: 'pam', - PNOperationType.PNAccessManagerRevoke: 'pam', - PNOperationType.PNTimeOperation: 'pam', - - PNOperationType.PNAccessManagerGrantToken: 'pamv3', - PNOperationType.PNAccessManagerRevokeToken: 'pamv3', - - PNOperationType.PNSignalOperation: 'sig', - - PNOperationType.PNSetUuidMetadataOperation: 'obj', - PNOperationType.PNGetUuidMetadataOperation: 'obj', - PNOperationType.PNRemoveUuidMetadataOperation: 'obj', - PNOperationType.PNGetAllUuidMetadataOperation: 'obj', - - PNOperationType.PNSetChannelMetadataOperation: 'obj', - PNOperationType.PNGetChannelMetadataOperation: 'obj', - PNOperationType.PNRemoveChannelMetadataOperation: 'obj', - PNOperationType.PNGetAllChannelMetadataOperation: 'obj', - - PNOperationType.PNSetChannelMembersOperation: 'obj', - PNOperationType.PNGetChannelMembersOperation: 'obj', - PNOperationType.PNRemoveChannelMembersOperation: 'obj', - PNOperationType.PNManageChannelMembersOperation: 'obj', - - PNOperationType.PNSetMembershipsOperation: 'obj', - PNOperationType.PNGetMembershipsOperation: 'obj', - PNOperationType.PNRemoveMembershipsOperation: 'obj', - PNOperationType.PNManageMembershipsOperation: 'obj', - - PNOperationType.PNAddMessageAction: 'msga', - PNOperationType.PNGetMessageActions: 'msga', - PNOperationType.PNDeleteMessageAction: 'msga', - - PNOperationType.PNGetFilesAction: 'file', - PNOperationType.PNDeleteFileOperation: 'file', - PNOperationType.PNGetFileDownloadURLAction: 'file', - PNOperationType.PNFetchFileUploadS3DataAction: 'file', - PNOperationType.PNDownloadFileAction: 'file', - PNOperationType.PNSendFileAction: 'file', - - - PNOperationType.PNFetchMessagesOperation: "hist", - - PNOperationType.PNCreateSpaceOperation: "obj", - PNOperationType.PNUpdateSpaceOperation: "obj", - PNOperationType.PNFetchSpaceOperation: "obj", - PNOperationType.PNFetchSpacesOperation: "obj", - PNOperationType.PNRemoveSpaceOperation: "obj", - - PNOperationType.PNCreateUserOperation: "obj", - PNOperationType.PNUpdateUserOperation: "obj", - PNOperationType.PNFetchUserOperation: "obj", - PNOperationType.PNFetchUsersOperation: "obj", - PNOperationType.PNRemoveUserOperation: "obj", - - PNOperationType.PNAddUserSpacesOperation: "obj", - PNOperationType.PNAddSpaceUsersOperation: "obj", - PNOperationType.PNUpdateUserSpacesOperation: "obj", - - PNOperationType.PNUpdateSpaceUsersOperation: "obj", - PNOperationType.PNFetchUserMembershipsOperation: "obj", - PNOperationType.PNFetchSpaceMembershipsOperation: "obj", - - }[operation_type] - - return endpoint - - class TokenManager: def __init__(self): self.token = None diff --git a/pubnub/pubnub.py b/pubnub/pubnub.py index cb4b51aa..c44e48fc 100644 --- a/pubnub/pubnub.py +++ b/pubnub/pubnub.py @@ -19,7 +19,6 @@ - Message queueing and worker thread management - Automatic reconnection handling - Custom request handler support - - Telemetry tracking Usage Example: ```python @@ -71,7 +70,7 @@ from pubnub.endpoints.presence.leave import Leave from pubnub.endpoints.pubsub.subscribe import Subscribe from pubnub.enums import PNStatusCategory, PNHeartbeatNotificationOptions, PNOperationType, PNReconnectionPolicy -from pubnub.managers import SubscriptionManager, PublishSequenceManager, ReconnectionManager, TelemetryManager +from pubnub.managers import SubscriptionManager, PublishSequenceManager, ReconnectionManager from pubnub.models.consumer.common import PNStatus from pubnub.pnconfiguration import PNConfiguration from pubnub.pubnub_core import PubNubCore @@ -127,8 +126,6 @@ def __init__(self, config: PNConfiguration, *, custom_request_handler: Type[Base self._publish_sequence_manager = PublishSequenceManager(PubNubCore.MAX_SEQUENCE) - self._telemetry_manager = NativeTelemetryManager() - def sdk_platform(self) -> str: """Get the SDK platform identifier. @@ -716,9 +713,3 @@ def reset(self): self.result = None self.status = None self.done_event.clear() - - -class NativeTelemetryManager(TelemetryManager): - def store_latency(self, latency, operation_type): - super(NativeTelemetryManager, self).store_latency(latency, operation_type) - self.clean_up_telemetry_data() diff --git a/pubnub/pubnub_asyncio.py b/pubnub/pubnub_asyncio.py index 481f9c7b..df1cfda2 100644 --- a/pubnub/pubnub_asyncio.py +++ b/pubnub/pubnub_asyncio.py @@ -71,7 +71,7 @@ async def main(): from pubnub.request_handlers.base import BaseRequestHandler from pubnub.request_handlers.async_httpx import AsyncHttpxRequestHandler from pubnub.workers import SubscribeMessageWorker -from pubnub.managers import SubscriptionManager, PublishSequenceManager, ReconnectionManager, TelemetryManager +from pubnub.managers import SubscriptionManager, PublishSequenceManager, ReconnectionManager from pubnub import utils from pubnub.enums import PNStatusCategory, PNHeartbeatNotificationOptions, PNOperationType, PNReconnectionPolicy from pubnub.callbacks import SubscribeCallback, ReconnectionCallback @@ -153,7 +153,6 @@ def __init__(self, config, custom_event_loop=None, subscription_manager=None, *, self._subscription_manager = subscription_manager(self) self._publish_sequence_manager = AsyncioPublishSequenceManager(self.event_loop, PubNubCore.MAX_SEQUENCE) - self._telemetry_manager = AsyncioTelemetryManager() @property def _connector(self): @@ -835,23 +834,3 @@ async def wait_for_presence_on(self, *channel_names): continue finally: self.presence_queue.task_done() - - -class AsyncioTelemetryManager(TelemetryManager): - def __init__(self): - TelemetryManager.__init__(self) - self.loop = asyncio.get_event_loop() - self._schedule_next_cleanup() - - def _schedule_next_cleanup(self): - self._timer = self.loop.call_later( - self.CLEAN_UP_INTERVAL * self.CLEAN_UP_INTERVAL_MULTIPLIER / 1000, - self._clean_up_schedule_next - ) - - def _clean_up_schedule_next(self): - self.clean_up_telemetry_data() - self._schedule_next_cleanup() - - def _stop_clean_up_timer(self): - self._timer.cancel() diff --git a/pubnub/pubnub_core.py b/pubnub/pubnub_core.py index 1553d7fa..ff8c60b9 100644 --- a/pubnub/pubnub_core.py +++ b/pubnub/pubnub_core.py @@ -145,7 +145,6 @@ def my_listener(message, event): from pubnub.endpoints.push.remove_channels_from_push import RemoveChannelsFromPush from pubnub.endpoints.push.remove_device import RemoveDeviceFromPush from pubnub.endpoints.push.list_push_provisions import ListPushProvisions -from pubnub.managers import TelemetryManager if TYPE_CHECKING: from pubnub.endpoints.file_operations.send_file_asyncio import AsyncioSendFile @@ -192,7 +191,6 @@ def __init__(self, config: PNConfiguration) -> None: self._subscription_manager = None self._publish_sequence_manager = None - self._telemetry_manager = TelemetryManager() self._base_path_manager = BasePathManager(config) self._token_manager = TokenManager() self._subscription_registry = PNSubscriptionRegistry(self) diff --git a/pubnub/request_handlers/async_aiohttp.py b/pubnub/request_handlers/async_aiohttp.py index 8c7ee4fc..dc3d0a91 100644 --- a/pubnub/request_handlers/async_aiohttp.py +++ b/pubnub/request_handlers/async_aiohttp.py @@ -1,7 +1,6 @@ import aiohttp import asyncio import logging -import time import json # noqa # pylint: disable=W0611 import urllib @@ -98,7 +97,6 @@ async def async_request(self, options_func, cancellation_event): try: if not self._session: await self.create_session() - start_timestamp = time.time() response = await asyncio.wait_for( self._session.request( options.method_string, @@ -205,8 +203,6 @@ async def async_request(self, options_func, cancellation_event): ) ) else: - self.pubnub._telemetry_manager.store_latency(time.time() - start_timestamp, options.operation_type) - return AsyncioEnvelope( result=create_response(data) if not options.non_json_response else create_response(response, data), status=create_status( diff --git a/pubnub/request_handlers/async_httpx.py b/pubnub/request_handlers/async_httpx.py index ea1d5149..acaf574f 100644 --- a/pubnub/request_handlers/async_httpx.py +++ b/pubnub/request_handlers/async_httpx.py @@ -1,7 +1,6 @@ from asyncio import Event import asyncio import logging -import time import httpx import json # noqa # pylint: disable=W0611 import urllib @@ -113,7 +112,6 @@ async def async_request(self, options_func, cancellation_event): try: if not self._session: await self.create_session() - start_timestamp = time.time() response = await asyncio.wait_for( self._session.request(**request_arguments), options.request_timeout @@ -215,8 +213,6 @@ async def async_request(self, options_func, cancellation_event): ) ) else: - self.pubnub._telemetry_manager.store_latency(time.time() - start_timestamp, options.operation_type) - return AsyncioEnvelope( result=create_response(data) if not options.non_json_response else create_response(response, data), status=create_status( diff --git a/requirements-dev.txt b/requirements-dev.txt index 326ccabb..a5e406e4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,7 @@ pytest-cov>=6.0.0 pycryptodomex>=3.21.0 flake8>=7.1.2 pytest>=8.3.5 -pytest-asyncio>=0.24.0,<1.0.0 +pytest-asyncio>=1.0.0 httpx>=0.28 h2>=4.1 requests>=2.32.2 diff --git a/tests/examples/native_sync/test_examples.py b/tests/examples/native_sync/test_examples.py index 8a190f14..0c3b875f 100644 --- a/tests/examples/native_sync/test_examples.py +++ b/tests/examples/native_sync/test_examples.py @@ -1,4 +1,6 @@ # flake8: noqa +import os from examples.native_sync.file_handling import main as test_file_handling +from examples.native_sync.message_reactions import main as test_message_reactions -from examples.native_sync.message_reactions import main as test_message_reactions \ No newline at end of file +os.environ['CI'] = '1' \ No newline at end of file diff --git a/tests/functional/push/test_add_channels_to_push.py b/tests/functional/push/test_add_channels_to_push.py index 59d688ea..9dbd905b 100644 --- a/tests/functional/push/test_add_channels_to_push.py +++ b/tests/functional/push/test_add_channels_to_push.py @@ -11,7 +11,6 @@ from pubnub.endpoints.push.add_channels_to_push import AddChannelsToPush from tests.helper import pnconf, pnconf_env_copy, sdk_name -from pubnub.managers import TelemetryManager from pubnub.enums import PNPushType, PNPushEnvironment @@ -26,7 +25,6 @@ def setUp(self): ) self.pubnub.uuid = "UUID_AddChannelsTest" - self.pubnub._telemetry_manager = TelemetryManager() self.add_channels = AddChannelsToPush(self.pubnub) def test_push_add_single_channel(self): diff --git a/tests/functional/push/test_list_push_provisions.py b/tests/functional/push/test_list_push_provisions.py index 10770547..396bab88 100644 --- a/tests/functional/push/test_list_push_provisions.py +++ b/tests/functional/push/test_list_push_provisions.py @@ -15,7 +15,6 @@ import pubnub.enums from tests.helper import pnconf, sdk_name -from pubnub.managers import TelemetryManager class TestListPushProvisions(unittest.TestCase): @@ -28,7 +27,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_ListChannelsInCGTest" - self.pubnub._telemetry_manager = TelemetryManager() self.list_push = ListPushProvisions(self.pubnub) def test_list_channel_group_apns(self): diff --git a/tests/functional/push/test_remove_channels_from_push.py b/tests/functional/push/test_remove_channels_from_push.py index 3ac6bcb1..af0d6cca 100644 --- a/tests/functional/push/test_remove_channels_from_push.py +++ b/tests/functional/push/test_remove_channels_from_push.py @@ -5,7 +5,6 @@ import pubnub.enums from pubnub.endpoints.push.remove_channels_from_push import RemoveChannelsFromPush from tests.helper import pnconf, sdk_name -from pubnub.managers import TelemetryManager class TestRemoveChannelsFromPush(unittest.TestCase): @@ -19,7 +18,6 @@ def setUp(self): ) self.pubnub.uuid = "UUID_RemoveChannelsTest" - self.pubnub._telemetry_manager = TelemetryManager() self.remove_channels = RemoveChannelsFromPush(self.pubnub) def test_push_remove_single_channel(self): diff --git a/tests/functional/push/test_remove_device_from_push.py b/tests/functional/push/test_remove_device_from_push.py index 7f7e8351..cd8e8bb4 100644 --- a/tests/functional/push/test_remove_device_from_push.py +++ b/tests/functional/push/test_remove_device_from_push.py @@ -11,7 +11,6 @@ from pubnub.endpoints.push.remove_device import RemoveDeviceFromPush from tests.helper import pnconf, sdk_name -from pubnub.managers import TelemetryManager class TestRemoveDeviceFromPush(unittest.TestCase): @@ -25,7 +24,6 @@ def setUp(self): ) self.pubnub.uuid = "UUID_RemoveDeviceTest" - self.pubnub._telemetry_manager = TelemetryManager() self.remove_device = RemoveDeviceFromPush(self.pubnub) def test_remove_push_apns(self): diff --git a/tests/functional/test_add_channel_to_cg.py b/tests/functional/test_add_channel_to_cg.py index 390f6ffd..8f77f2d9 100644 --- a/tests/functional/test_add_channel_to_cg.py +++ b/tests/functional/test_add_channel_to_cg.py @@ -1,7 +1,6 @@ import unittest from pubnub.endpoints.channel_groups.add_channel_to_channel_group import AddChannelToChannelGroup -from pubnub.managers import TelemetryManager try: from mock import MagicMock @@ -22,7 +21,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_AddChannelToCGTest" - self.pubnub._telemetry_manager = TelemetryManager() self.add = AddChannelToChannelGroup(self.pubnub) def test_add_single_channel(self): diff --git a/tests/functional/test_audit.py b/tests/functional/test_audit.py index 042f9ac3..9b0ecbe6 100644 --- a/tests/functional/test_audit.py +++ b/tests/functional/test_audit.py @@ -3,7 +3,6 @@ from pubnub import utils from pubnub.endpoints.access.audit import Audit from pubnub.enums import HttpMethod -from pubnub.managers import TelemetryManager try: from mock import MagicMock @@ -24,7 +23,6 @@ def setUp(self): uuid=None ) self.pubnub.uuid = "UUID_AuditUnitTest" - self.pubnub._telemetry_manager = TelemetryManager() self.audit = Audit(self.pubnub) def test_audit_channel(self): diff --git a/tests/functional/test_get_state.py b/tests/functional/test_get_state.py index 914119d6..08001613 100644 --- a/tests/functional/test_get_state.py +++ b/tests/functional/test_get_state.py @@ -9,7 +9,6 @@ from pubnub.pubnub import PubNub from tests.helper import pnconf, sdk_name -from pubnub.managers import TelemetryManager class TestGetState(unittest.TestCase): @@ -22,7 +21,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_GetStateTest" - self.pubnub._telemetry_manager = TelemetryManager() self.get_state = GetState(self.pubnub) def test_get_state_single_channel(self): diff --git a/tests/functional/test_grant.py b/tests/functional/test_grant.py index 95a5ca3c..ac9385ea 100644 --- a/tests/functional/test_grant.py +++ b/tests/functional/test_grant.py @@ -3,7 +3,6 @@ from pubnub import utils from pubnub.endpoints.access.grant import Grant from pubnub.enums import HttpMethod -from pubnub.managers import TelemetryManager try: from mock import MagicMock @@ -24,7 +23,6 @@ def setUp(self): uuid=None ) self.pubnub.uuid = "UUID_GrantUnitTest" - self.pubnub._telemetry_manager = TelemetryManager() self.grant = Grant(self.pubnub) def test_grant_read_and_write_to_channel(self): diff --git a/tests/functional/test_heartbeat.py b/tests/functional/test_heartbeat.py index 80178aa8..cf144afe 100644 --- a/tests/functional/test_heartbeat.py +++ b/tests/functional/test_heartbeat.py @@ -4,7 +4,6 @@ from unittest.mock import MagicMock from pubnub.endpoints.presence.heartbeat import Heartbeat -from pubnub.managers import TelemetryManager from pubnub.pubnub import PubNub from tests.helper import pnconf, sdk_name, pnconf_copy @@ -19,7 +18,6 @@ def setUp(self): ) self.pubnub.uuid = "UUID_HeartbeatUnitTest" self.hb = Heartbeat(self.pubnub) - self.pubnub._telemetry_manager = TelemetryManager() self.pubnub.config.set_presence_timeout(20) def test_sub_single_channel(self): diff --git a/tests/functional/test_here_now.py b/tests/functional/test_here_now.py index bfb139c1..48be47ea 100644 --- a/tests/functional/test_here_now.py +++ b/tests/functional/test_here_now.py @@ -1,7 +1,6 @@ import unittest from pubnub.endpoints.presence.here_now import HereNow -from pubnub.managers import TelemetryManager try: from mock import MagicMock @@ -21,7 +20,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_HereNowTest" - self.pubnub._telemetry_manager = TelemetryManager() self.here_now = HereNow(self.pubnub) def test_here_now(self): diff --git a/tests/functional/test_history.py b/tests/functional/test_history.py index 0970eaeb..9b0c8a4f 100644 --- a/tests/functional/test_history.py +++ b/tests/functional/test_history.py @@ -8,7 +8,6 @@ from pubnub.endpoints.history import History from pubnub.pubnub import PubNub from tests.helper import pnconf_pam_copy, sdk_name -from pubnub.managers import TelemetryManager pnconf = pnconf_pam_copy() pnconf.secret_key = None @@ -25,7 +24,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_UnitTest" - self.pubnub._telemetry_manager = TelemetryManager() self.history = History(self.pubnub) def test_history_basic(self): diff --git a/tests/functional/test_history_delete.py b/tests/functional/test_history_delete.py index e159e277..1dc463fe 100644 --- a/tests/functional/test_history_delete.py +++ b/tests/functional/test_history_delete.py @@ -8,7 +8,6 @@ from pubnub.endpoints.history_delete import HistoryDelete from pubnub.pubnub import PubNub from tests.helper import pnconf_pam_copy, sdk_name -from pubnub.managers import TelemetryManager pnconf = pnconf_pam_copy() pnconf.secret_key = None @@ -25,7 +24,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_UnitTest" - self.pubnub._telemetry_manager = TelemetryManager() self.history_delete = HistoryDelete(self.pubnub) def test_history_delete_basic(self): diff --git a/tests/functional/test_leave.py b/tests/functional/test_leave.py index c4746ef3..0d56ae8b 100644 --- a/tests/functional/test_leave.py +++ b/tests/functional/test_leave.py @@ -1,7 +1,6 @@ import unittest from pubnub.endpoints.presence.leave import Leave -from pubnub.managers import TelemetryManager try: from mock import MagicMock @@ -22,7 +21,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_SubscribeUnitTest" - self.pubnub._telemetry_manager = TelemetryManager() self.leave = Leave(self.pubnub) def test_leave_single_channel(self): diff --git a/tests/functional/test_list_channels_in_cg.py b/tests/functional/test_list_channels_in_cg.py index bce83039..57269894 100644 --- a/tests/functional/test_list_channels_in_cg.py +++ b/tests/functional/test_list_channels_in_cg.py @@ -1,7 +1,6 @@ import unittest from pubnub.endpoints.channel_groups.list_channels_in_channel_group import ListChannelsInChannelGroup -from pubnub.managers import TelemetryManager try: from mock import MagicMock @@ -22,7 +21,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_ListChannelsInCGTest" - self.pubnub._telemetry_manager = TelemetryManager() self.list = ListChannelsInChannelGroup(self.pubnub) def test_list_channel_group(self): diff --git a/tests/functional/test_publish.py b/tests/functional/test_publish.py index 70da240d..3a8450be 100644 --- a/tests/functional/test_publish.py +++ b/tests/functional/test_publish.py @@ -7,7 +7,6 @@ from pubnub.endpoints.pubsub.publish import Publish from pubnub.pubnub import PubNub from tests.helper import pnconf, sdk_name, url_encode -from pubnub.managers import TelemetryManager class TestPublish(unittest.TestCase): @@ -25,7 +24,6 @@ def setUp(self): ) self.pubnub.uuid = "UUID_PublishUnitTest" - self.pubnub._telemetry_manager = TelemetryManager() self.pub = Publish(self.pubnub) def test_pub_message(self): @@ -122,7 +120,6 @@ def test_pub_with_auth(self): _publish_sequence_manager=self.sm, _get_token=lambda: None ) - pubnub._telemetry_manager = TelemetryManager() pub = Publish(pubnub) message = "hey" encoded_message = url_encode(message) @@ -150,7 +147,6 @@ def test_pub_encrypted_list_message(self): _publish_sequence_manager=self.sm, _get_token=lambda: None ) - pubnub._telemetry_manager = TelemetryManager() pub = Publish(pubnub) message = ["hi", "hi2", "hi3"] diff --git a/tests/functional/test_remove_cg.py b/tests/functional/test_remove_cg.py index e5922e09..cf05653b 100644 --- a/tests/functional/test_remove_cg.py +++ b/tests/functional/test_remove_cg.py @@ -1,7 +1,6 @@ import unittest from pubnub.endpoints.channel_groups.remove_channel_group import RemoveChannelGroup -from pubnub.managers import TelemetryManager try: from mock import MagicMock @@ -22,7 +21,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_ListChannelsInCGTest" - self.pubnub._telemetry_manager = TelemetryManager() self.list = RemoveChannelGroup(self.pubnub) def test_list_channel_group(self): diff --git a/tests/functional/test_remove_channel_from_cg.py b/tests/functional/test_remove_channel_from_cg.py index 47664c39..399b722e 100644 --- a/tests/functional/test_remove_channel_from_cg.py +++ b/tests/functional/test_remove_channel_from_cg.py @@ -9,7 +9,6 @@ from pubnub.pubnub import PubNub from tests.helper import pnconf, sdk_name -from pubnub.managers import TelemetryManager class TestRemoveChannelToChannelGroup(unittest.TestCase): @@ -22,7 +21,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_RemoveChannelToCGTest" - self.pubnub._telemetry_manager = TelemetryManager() self.remove = RemoveChannelFromChannelGroup(self.pubnub) def test_remove_single_channel(self): diff --git a/tests/functional/test_set_state.py b/tests/functional/test_set_state.py index 7b219e36..640f234b 100644 --- a/tests/functional/test_set_state.py +++ b/tests/functional/test_set_state.py @@ -3,7 +3,6 @@ from pubnub.endpoints.presence.set_state import SetState from tests import helper -from pubnub.managers import TelemetryManager try: from mock import MagicMock @@ -24,7 +23,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_SetStateTest" - self.pubnub._telemetry_manager = TelemetryManager() self.set_state = SetState(self.pubnub) self.state = {'name': 'Alex', "count": 5} diff --git a/tests/functional/test_subscribe.py b/tests/functional/test_subscribe.py index 5e831b7d..792d1227 100644 --- a/tests/functional/test_subscribe.py +++ b/tests/functional/test_subscribe.py @@ -4,7 +4,7 @@ from pubnub.endpoints.pubsub.subscribe import Subscribe from pubnub.pubnub import PubNub from tests.helper import pnconf, sdk_name -from pubnub.managers import TelemetryManager, TokenManager +from pubnub.managers import TokenManager class TestSubscribe(unittest.TestCase): @@ -16,7 +16,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.uuid = "UUID_SubscribeUnitTest" - self.pubnub._telemetry_manager = TelemetryManager() self.pubnub._token_manager = TokenManager() self.sub = Subscribe(self.pubnub) diff --git a/tests/functional/test_telemetry_manager.py b/tests/functional/test_telemetry_manager.py deleted file mode 100644 index bcc4495e..00000000 --- a/tests/functional/test_telemetry_manager.py +++ /dev/null @@ -1,36 +0,0 @@ -import time - -from pubnub.managers import TelemetryManager -from pubnub.pubnub import NativeTelemetryManager -from pubnub.enums import PNOperationType - - -def test_cleaning_up_latency_data(): - manager = TelemetryManager() - manager.MAXIMUM_LATENCY_DATA_AGE = 1 - - for i in range(0, 10): - manager.store_latency(i, PNOperationType.PNPublishOperation) - - # await for store timestamp expired - time.sleep(2) - - manager.clean_up_telemetry_data() - print(manager.latencies) - - assert len(manager.operation_latencies()) == 0 - - -def test_native_telemetry_cleanup(): - manager = NativeTelemetryManager() - manager.MAXIMUM_LATENCY_DATA_AGE = 1 - - for i in range(1, 10): - manager.store_latency(i, PNOperationType.PNPublishOperation) - - time.sleep(2) - - for i in range(1, 10): # Latency = 0 is not being stored! - manager.store_latency(i, PNOperationType.PNPublishOperation) - - assert len(manager.latencies["pub"]) == 9 diff --git a/tests/functional/test_where_now.py b/tests/functional/test_where_now.py index 816f3626..3495b0ca 100644 --- a/tests/functional/test_where_now.py +++ b/tests/functional/test_where_now.py @@ -8,7 +8,6 @@ from pubnub.endpoints.presence.where_now import WhereNow from pubnub.pubnub import PubNub from tests.helper import pnconf, sdk_name, pnconf_copy -from pubnub.managers import TelemetryManager class TestWhereNow(unittest.TestCase): @@ -20,7 +19,6 @@ def setUp(self): _get_token=lambda: None ) self.pubnub.config.uuid = "UUID_WhereNowTest" - self.pubnub._telemetry_manager = TelemetryManager() self.where_now = WhereNow(self.pubnub) def test_where_now(self): diff --git a/tests/integrational/asyncio/test_change_uuid.py b/tests/integrational/asyncio/test_change_uuid.py index 90c38ed9..2fb5a0a9 100644 --- a/tests/integrational/asyncio/test_change_uuid.py +++ b/tests/integrational/asyncio/test_change_uuid.py @@ -52,12 +52,12 @@ async def test_change_uuid_no_lock(): assert isinstance(envelope.status, PNStatus) -def test_uuid_validation_at_init(event_loop): +def test_uuid_validation_at_init(_function_event_loop): with pytest.raises(AssertionError) as exception: pnconf = PNConfiguration() pnconf.publish_key = "demo" pnconf.subscribe_key = "demo" - PubNubAsyncio(pnconf, custom_event_loop=event_loop) + PubNubAsyncio(pnconf, custom_event_loop=_function_event_loop) assert str(exception.value) == 'UUID missing or invalid type' @@ -72,7 +72,7 @@ def test_uuid_validation_at_setting(): assert str(exception.value) == 'UUID missing or invalid type' -def test_whitespace_uuid_validation_at_setting(event_loop): +def test_whitespace_uuid_validation_at_setting(): with pytest.raises(AssertionError) as exception: pnconf = PNConfiguration() pnconf.publish_key = "demo" diff --git a/tests/integrational/asyncio/test_message_count.py b/tests/integrational/asyncio/test_message_count.py index 1d5be198..f2f547c2 100644 --- a/tests/integrational/asyncio/test_message_count.py +++ b/tests/integrational/asyncio/test_message_count.py @@ -9,10 +9,10 @@ @pytest.fixture -def pn(event_loop): +def pn(_function_event_loop): config = pnconf_mc_copy() config.enable_subscribe = False - pn = PubNubAsyncio(config, custom_event_loop=event_loop) + pn = PubNubAsyncio(config, custom_event_loop=_function_event_loop) yield pn diff --git a/tests/integrational/asyncio/test_where_now.py b/tests/integrational/asyncio/test_where_now.py index c2eecbc5..a40a1b43 100644 --- a/tests/integrational/asyncio/test_where_now.py +++ b/tests/integrational/asyncio/test_where_now.py @@ -82,8 +82,8 @@ async def test_multiple_channels(): # @pytest.mark.asyncio @pytest.mark.skip(reason="Needs to be reworked to use VCR") -async def test_where_now_super_admin_call(event_loop): - pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=event_loop) +async def test_where_now_super_admin_call(_function_event_loop): + pubnub = PubNubAsyncio(pnconf_pam_copy(), custom_event_loop=_function_event_loop) uuid = 'test-where-now-asyncio-uuid-.*|@' pubnub.config.uuid = uuid diff --git a/tests/unit/test_pubnub_core.py b/tests/unit/test_pubnub_core.py index 48b208ff..4c031d64 100644 --- a/tests/unit/test_pubnub_core.py +++ b/tests/unit/test_pubnub_core.py @@ -55,7 +55,6 @@ def test_basic_initialization(self): self.assertIsNotNone(pubnub._request_handler) self.assertIsInstance(pubnub._request_handler, HttpxRequestHandler) self.assertIsNotNone(pubnub._publish_sequence_manager) - self.assertIsNotNone(pubnub._telemetry_manager) # Verify subscription manager is created when enabled if self.config.enable_subscribe: @@ -226,15 +225,6 @@ def test_publish_sequence_manager_initialization(self): # Verify it has the expected max sequence self.assertEqual(pubnub._publish_sequence_manager.max_sequence, PubNub.MAX_SEQUENCE) - def test_telemetry_manager_initialization(self): - """Test that telemetry manager is properly initialized.""" - pubnub = PubNub(self.config) - - self.assertIsNotNone(pubnub._telemetry_manager) - # Verify it's the native implementation - from pubnub.pubnub import NativeTelemetryManager - self.assertIsInstance(pubnub._telemetry_manager, NativeTelemetryManager) - def test_subscription_manager_initialization_when_enabled(self): """Test subscription manager initialization when enabled.""" self.config.enable_subscribe = True diff --git a/tests/unit/test_telemetry_manager.py b/tests/unit/test_telemetry_manager.py deleted file mode 100644 index 79d44d0e..00000000 --- a/tests/unit/test_telemetry_manager.py +++ /dev/null @@ -1,41 +0,0 @@ -from pubnub.managers import TelemetryManager -from pubnub.enums import PNOperationType - - -def test_average_latency(): - manager = TelemetryManager() - endpointLatencies = [ - {"timestamp": 100, "latency": 10}, - {"timestamp": 100, "latency": 20}, - {"timestamp": 100, "latency": 30}, - {"timestamp": 100, "latency": 40}, - {"timestamp": 100, "latency": 50}, - ] - - averageLatency = manager.average_latency_from_data(endpointLatencies) - - if not 30 == averageLatency: - raise AssertionError() - - -def test_valid_queries(): - manager = TelemetryManager() - - manager.store_latency(1, PNOperationType.PNPublishOperation) - manager.store_latency(2, PNOperationType.PNPublishOperation) - manager.store_latency(3, PNOperationType.PNPublishOperation) - manager.store_latency(4, PNOperationType.PNHistoryOperation) - manager.store_latency(5, PNOperationType.PNHistoryOperation) - manager.store_latency(6, PNOperationType.PNHistoryOperation) - manager.store_latency(7, PNOperationType.PNRemoveGroupOperation) - manager.store_latency(8, PNOperationType.PNRemoveGroupOperation) - manager.store_latency(9, PNOperationType.PNRemoveGroupOperation) - - queries = manager.operation_latencies() - - if not queries['l_pub'] == 2: - raise AssertionError() - if not queries['l_hist'] == 5: - raise AssertionError() - if not queries['l_cg'] == 8: - raise AssertionError()