def test_does_not_block_on_full_inbox():
    config = Config(
        events_max_pending=1
    )  # this sets the size of both the inbox and the outbox to 1
    ep_inbox_holder = [None]
    ep_inbox = None

    def dispatcher_factory(inbox, config, http, diag):
        ep_inbox_holder[
            0] = inbox  # it's an array because otherwise it's hard for a closure to modify a variable
        return None  # the dispatcher object itself doesn't matter, we only manipulate the inbox

    def event_consumer():
        while True:
            message = ep_inbox.get(block=True)
            if message.type == 'stop':
                message.param.set()
                return

    def start_consuming_events():
        Thread(target=event_consumer).start()

    with DefaultEventProcessor(config, mock_http, dispatcher_factory) as ep:
        ep_inbox = ep_inbox_holder[0]
        event1 = {'kind': 'custom', 'key': 'event1', 'user': user}
        event2 = {'kind': 'custom', 'key': 'event2', 'user': user}
        ep.send_event(event1)
        ep.send_event(event2)  # this event should be dropped - inbox is full
        message1 = ep_inbox.get(block=False)
        had_no_more = ep_inbox.empty()
        start_consuming_events()
        assert message1.param == event1
        assert had_no_more
def test_event_payload_id_is_sent():
    with DefaultEventProcessor(Config(sdk_key='SDK_KEY'), mock_http) as ep:
        ep.send_event({'kind': 'identify', 'user': user})
        ep.flush()
        ep._wait_until_inactive()

        headerVal = mock_http.request_headers.get('X-LaunchDarkly-Payload-ID')
        assert headerVal is not None
        # Throws on invalid UUID
        uuid.UUID(headerVal)
def _verify_https_proxy_is_used(server, config):
    server.setup_response(config.events_uri + '/bulk', 200, None)
    with DefaultEventProcessor(config) as ep:
        ep.send_event({'kind': 'identify', 'user': user})
        ep.flush()
        ep._wait_until_inactive()

        # Our simple stub server implementation can't really do HTTPS proxying, so the request will fail, but
        # it can still record that it *got* the request, which proves that the request went to the proxy.
        req = server.require_request()
        assert req.method == 'CONNECT'
def _verify_http_proxy_is_used(server, config):
    server.setup_response(config.events_uri + '/bulk', 200, None)
    with DefaultEventProcessor(config) as ep:
        ep.send_event({'kind': 'identify', 'user': user})
        ep.flush()
        ep._wait_until_inactive()

        # For an insecure proxy request, our stub server behaves enough like the real thing to satisfy the
        # HTTP client, so we should be able to see the request go through. Note that the URI path will
        # actually be an absolute URI for a proxy request.
        req = server.require_request()
        assert req.method == 'POST'
Ejemplo n.º 5
0
 def _set_event_processor(self, config):
     if config.offline or not config.send_events:
         self._event_processor = NullEventProcessor()
         return None
     if not config.event_processor_class:
         diagnostic_id = create_diagnostic_id(config)
         diagnostic_accumulator = None if config.diagnostic_opt_out else _DiagnosticAccumulator(
             diagnostic_id)
         self._event_processor = DefaultEventProcessor(
             config, diagnostic_accumulator=diagnostic_accumulator)
         return diagnostic_accumulator
     self._event_processor = config.event_processor_class(config)
     return None
def test_event_payload_id_changes_between_requests():
    with DefaultEventProcessor(Config(sdk_key = 'SDK_KEY'), mock_http) as ep:
        ep.send_event({ 'kind': 'identify', 'user': user })
        ep.flush()
        ep._wait_until_inactive()

        ep.send_event({ 'kind': 'identify', 'user': user })
        ep.flush()
        ep._wait_until_inactive()

        firstPayloadId = mock_http.recorded_requests[0][0].get('X-LaunchDarkly-Payload-ID')
        secondPayloadId = mock_http.recorded_requests[1][0].get('X-LaunchDarkly-Payload-ID')
        assert firstPayloadId != secondPayloadId
Ejemplo n.º 7
0
def setup_processor(config):
    global ep
    ep = DefaultEventProcessor(config, mock_http)
 def _event_processor_proxy_test(server, config, secure):
     with DefaultEventProcessor(config) as ep:
         ep.send_event({ 'kind': 'identify', 'user': user })
         ep.flush()
         ep._wait_until_inactive()