Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omnicore.ApiClient() leaving a open socket #2

Open
geanceretta opened this issue Jun 3, 2023 · 0 comments
Open

Omnicore.ApiClient() leaving a open socket #2

geanceretta opened this issue Jun 3, 2023 · 0 comments

Comments

@geanceretta
Copy link

OmniCore.ApiClient() seams to be leaving a open socket.

Using version 1.7.4 of OmniCore's Python SDK

Example of OmniCore.ApiClient() usage:

def device_exists_on_omnicore(self, omnicore_configuration, subscription_id, device_mac, device_type) -> bool:
        device_exists: bool
        with OmniCore.ApiClient(omnicore_configuration) as api_client:
            api_instance = OmniCore.DeviceApi(api_client)
            registry_id = self.get_registry(device_type=device_type)
            device_id = self.get_device_id(device_mac=device_mac, device_type=device_type)
            
            try:
                device = api_instance.get_device(subscription_id, registry_id, device_id)
                device_exists = device.id == device_id
            except:
                device_exists = False
        return device_exists

Testing it:

def test_device_exists_on_omnicore(self):
        omnicore_configuration = self.register_device.get_omnicore_configuration(
            api_key=OMNICORE_API_KEY,
            client_id=OMNICORE_CLIENT_ID,
            client_secret=OMNICORE_CLIENT_SECRET
        )
        device_exists = self.register_device.device_exists_on_omnicore(
            omnicore_configuration=omnicore_configuration,
            subscription_id=OMNICORE_SUBSCRIPTION_ID,
            device_mac='aabbccddeeff',
            device_type='mydevicetype'
        )
        self.assertTrue(device_exists)

the test passes successfully, although generates the following warning by Unittest :

test_register_device.py:57: ResourceWarning: unclosed <ssl.SSLSocket fd=5, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.19.0.2', 57792), raddr=('104.18.27.73', 443)>
   device_exists = self.register_device.device_exists_on_omnicore(
 ResourceWarning: Enable tracemalloc to get the object allocation traceback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant