Skip to content

Integration test: RedisSemaphore / create_netbox_semaphore #2401

@berendt

Description

@berendt

Part of #2400. Follow-up to the integration-test foundation (#2368).

What

Cover osism.utils.RedisSemaphore and the create_netbox_semaphore helper (osism/utils/__init__.py:109 and :472) against the live Redis from the integration job.

The semaphore is implemented on top of Redis sorted sets (zadd / zcard / zremrangebyscore). This is exactly the kind of behaviour a fakeredis-based unit test can get wrong, so it belongs in the integration suite.

Scope

  • Acquire up to maxsize holders successfully.
  • An additional acquire(timeout=...) beyond maxsize returns False after the timeout.
  • release() frees a slot so a subsequent acquire() succeeds.
  • Expired holders (score older than 60s) are cleaned up by zremrangebyscore and free a slot — seed an aged entry directly via the Redis client to exercise this deterministically.
  • Context-manager usage (with sem:) acquires and releases; TimeoutError is raised when it cannot acquire.
  • create_netbox_semaphore(url, max_connections=...) builds a semaphore on the expected semaphore:netbox:<url> key with the expected maxsize.

Where

New file tests/integration/test_semaphore.py, pytestmark = pytest.mark.integration. Use unique keys (uuid) per test to stay independent of prior runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions