Skip to content

fix: send a single completed event in oadrDistributeEvent (#175) - #202

Open
fahad-ee wants to merge 1 commit into
OpenLEADR:mainfrom
fahad-ee:fix/175-request-event-single-completed-event
Open

fahad-ee wants to merge 1 commit into
OpenLEADR:mainfrom
fahad-ee:fix/175-request-event-single-completed-event

Conversation

@fahad-ee

Copy link
Copy Markdown

Fixes #175

The problem

When a VEN polls and the VTN holds exactly one event for it, and that event is completed, the oadrDistributeEvent response contains an empty events list. The VEN never learns that the event is completed (the reporter's TypeScript client even fails on the empty list).

Cause

In EventService.request_event, utils.order_events(self.events[ven_id]) returns the very same list object when there is only one event (it short circuits for len(events) == 1). The loop then pops the completed event from self.events[ven_id], which is the same list as events, so the list used for the response is emptied too. With two or more events order_events builds new lists, so this was not visible.

The fix

Build the response from a copy: utils.order_events(list(self.events[ven_id])), as suggested in the issue, with a short comment explaining why.

Tests

Added to test/test_event_distribution.py:

  • a single completed event is in the response and then removed from the queue
  • a single active event is sent and stays queued
  • a completed and an active event together
  • the same single completed event case through a real VTN and VEN (client): the first poll returns the event, the second returns oadrResponse

The first and last tests fail without the fix and pass with it. The full test suite (without test/conformance) passes, and flake8 is clean for the changed code.

)

When the VEN has exactly one event and it is completed, order_events returns the list it was given. Popping the completed event from self.events then also emptied the list used for the response, so the VEN received no event. The response is now built from a copy. Adds regression tests.

Fixes OpenLEADR#175

Signed-off-by: Engr. Muhammad Fahad <muhammadfahadx2.0@gmail.com>

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

event_service.py request_event not working for only one event

1 participant