Skip to content
New issue

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

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

Already on GitHub? # to your account

Dispatch 'complete' event when streaming connection closed #383

Merged
merged 14 commits into from
Aug 24, 2023

Conversation

timkimadobe
Copy link
Contributor

@timkimadobe timkimadobe commented Aug 22, 2023

Description

Paired with Android implementation adobe/aepsdk-edge-android#83
This PR updates:

  1. The NetworkResponseHandler to add a new method processResponseOnComplete which handles the sending of "complete" events
  2. Test app to include new button that sends a request content event with the sendCompletion flag set to true
  3. Unit and functional tests
  4. Event reference docs to include new flag and dispatched event

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Aug 22, 2023

Codecov Report

Merging #383 (4d10753) into dev (a630ae1) will increase coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              dev     #383      +/-   ##
==========================================
+ Coverage   96.73%   96.77%   +0.04%     
==========================================
  Files          27       27              
  Lines        1653     1671      +18     
==========================================
+ Hits         1599     1617      +18     
  Misses         54       54              

Add more functional test cases for onComplete behavior
@timkimadobe timkimadobe marked this pull request as ready for review August 22, 2023 21:22
Correct the documentation for response content as a fallback to error response content
Alphabetize items
Reorganize view to move scrollable data view to the top and not truncate text
Add visual indicators to scrollable data view
Copy link
Contributor

@kevinlind kevinlind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Added comments for a few minor issues.

@@ -64,10 +64,10 @@ class NetworkResponseHandler {
/// Remove the requestId in the internal `sentEventsWaitingResponse` along with the associated list of events.
/// - Parameter requestId: batch request id
/// - Returns: the list of unique event ids associated with the requestId that were removed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment to state it returns the events.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

Comment on lines 1443 to 1447
XCTAssertEqual(1, dispatchedEvents.count)

let flattenedData = flattenDictionary(dict: dispatchedEvents.first?.data ?? [:])
XCTAssertEqual(1, flattenedData.count)
XCTAssertEqual(requestID, flattenedData["requestId"] as? String)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use assertResponseCompleteEventWithData here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Updated


### Edge response content

This event is a response to an [Edge request content](#edge-request-content) event.
This event is a fallback to an [Edge error response content](#edge-error-response-content) event.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically the fallback when a network response handle doesn't define a type, not for errors. I've updated the Android definition to state this event include the Edge Network response handles and com.adobe.eventSource.responseContent is used if the response handle doesn't define a type. I'm not sure if we want to include that specific of information, however.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for clarifying! I've updated to align with the updates you've made on the Android side. I think it could be helpful to include in the off chance someone runs into this event case and uses the reference

Comment on lines 173 to 182
The `sendCompletion` flag is used within the Edge request to indicate whether a "complete" event should be dispatched once the streaming connection is closed. This flag is part of the `request` object, which is at the same hierarchical level as the `data` and `xdm` objects in the Edge Experience Event.

```json
{
"xdm": { ... },
"request": { "sendCompletion" : true }
}
```

When the `sendCompletion` flag in the request is set to `true`, the Edge extension will dispatch a *paired* response event. This event notifies the caller that the connection has been closed and that no further streaming response handles will be dispatched. The [response event](#edge-content-complete) includes only the `requestId` in its data, for debugging purposes. The `parentID` of this event corresponds to the UUID of the originating request event.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this write up, however these parameters are only send in the request content events. Having a separate flags section seems to imply that any of the request event could contain the sendCompletion flag. In the Android PR, I've split this information to include the request parameter in the request content section, while adding the sendCompletion in the content complete section. Having all this under the request content section is a good option too. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that having the flags section separate could be confusing; I like the way that you've organized the information! Updated to align this doc with the latest Android changes

Copy link
Contributor Author

@timkimadobe timkimadobe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @kevinlind! Updated based on feedback

@@ -64,10 +64,10 @@ class NetworkResponseHandler {
/// Remove the requestId in the internal `sentEventsWaitingResponse` along with the associated list of events.
/// - Parameter requestId: batch request id
/// - Returns: the list of unique event ids associated with the requestId that were removed
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

Comment on lines 1443 to 1447
XCTAssertEqual(1, dispatchedEvents.count)

let flattenedData = flattenDictionary(dict: dispatchedEvents.first?.data ?? [:])
XCTAssertEqual(1, flattenedData.count)
XCTAssertEqual(requestID, flattenedData["requestId"] as? String)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Updated


### Edge response content

This event is a response to an [Edge request content](#edge-request-content) event.
This event is a fallback to an [Edge error response content](#edge-error-response-content) event.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for clarifying! I've updated to align with the updates you've made on the Android side. I think it could be helpful to include in the off chance someone runs into this event case and uses the reference

Comment on lines 173 to 182
The `sendCompletion` flag is used within the Edge request to indicate whether a "complete" event should be dispatched once the streaming connection is closed. This flag is part of the `request` object, which is at the same hierarchical level as the `data` and `xdm` objects in the Edge Experience Event.

```json
{
"xdm": { ... },
"request": { "sendCompletion" : true }
}
```

When the `sendCompletion` flag in the request is set to `true`, the Edge extension will dispatch a *paired* response event. This event notifies the caller that the connection has been closed and that no further streaming response handles will be dispatched. The [response event](#edge-content-complete) includes only the `requestId` in its data, for debugging purposes. The `parentID` of this event corresponds to the UUID of the originating request event.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that having the flags section separate could be confusing; I like the way that you've organized the information! Updated to align this doc with the latest Android changes

@kevinlind kevinlind merged commit 7cce7fc into adobe:dev Aug 24, 2023
@timkimadobe timkimadobe deleted the send-completion-event branch August 24, 2023 21:08
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants