Skip to content

Update Edge responses support#110

Merged
emdobrin merged 27 commits intoadobe:devfrom
emdobrin:responsehandler
Jan 10, 2021
Merged

Update Edge responses support#110
emdobrin merged 27 commits intoadobe:devfrom
emdobrin:responsehandler

Conversation

@emdobrin
Copy link
Copy Markdown
Contributor

@emdobrin emdobrin commented Nov 18, 2020

Description

  • Removed usage of ResponseHandler
  • Updated public API to include optional completion handler sendEvent(experienceEvent: ExperienceEvent, _ completion: (([EdgeEventHandle]) -> Void)? = nil)
  • Made EdgeEventHandle public to be used in the completion handler
  • Test updates, new unit tests
  • More context Revisit EdgeResponseHandler #90

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
Copy Markdown

codecov bot commented Nov 18, 2020

Codecov Report

Merging #110 (460be70) into dev (d545bf8) will increase coverage by 1.35%.
The diff coverage is 92.86%.

@@            Coverage Diff             @@
##              dev     #110      +/-   ##
==========================================
+ Coverage   91.19%   92.54%   +1.35%     
==========================================
  Files          17       18       +1     
  Lines         590      603      +13     
==========================================
+ Hits          538      558      +20     
+ Misses         52       45       -7     

source: Constants.EventSource.REQUEST_CONTENT,
data: eventData)

ResponseCallbackHandler.shared.registerCompletionHandler(requestEventId: event.id.uuidString, completionHandler: completion)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it would be easier if we use the EdgeResponseHandler here. Just need to define a EdgeResponseHandler which caches all the responses and error, and then call the completion on complete.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I kept the two separated in case we want to stick with one or the other. If we keep the completion handler then we can remove EdgeResponseHandler altogether.

@emdobrin emdobrin linked an issue Dec 15, 2020 that may be closed by this pull request
// Note: ExEdge does not return eventIndex when there is only one event in the request.
// The event handles and errrors are associated to that request event, so defaulting to 0 here.
let index = forEventIndex ?? 0
guard index >= 0, index < requestEventIdsList.count else {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed 🐛 where the response was not returned in the callback when eventIndex was missing in the response.

@emdobrin
Copy link
Copy Markdown
Contributor Author

I pushed a few more tests to support these changes and the related #95

@emdobrin emdobrin linked an issue Dec 23, 2020 that may be closed by this pull request
@emdobrin
Copy link
Copy Markdown
Contributor Author

emdobrin commented Jan 5, 2021

Based on our discussion we decided to:

  • only keep one public API with completion handler
  • not return the error information in the completion handler, it will still be dispatched as an event through event hub
    @nporter-adbe @kevinlind please take a look at the updated code.

/// - Parameters:
/// - forRequestEventId: unique event identifier for which the completion handler is registered; should not be empty
/// - completionHandler: the completion handler that needs to be registered, should not be nil
func registerCompletionHandler(forRequestEventId: String, completion: (([EdgeEventHandle]) -> Void)?) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible to potentially register a completion handler twice for a single request id? I don't think there's a use case for this but I wonder if we should be safe and check if an existing completion handler is already mapped to the request id.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since this API is internal and used when sendEvent is called and a new Event is created, I think it is safe to say that there will not be multiple completion handlers associated with the same request id.

@emdobrin
Copy link
Copy Markdown
Contributor Author

emdobrin commented Jan 8, 2021

@kevinlind let me now if you have any additional comments, I would like to merge by the end of the day.

@emdobrin emdobrin merged commit 0cf353e into adobe:dev Jan 10, 2021
@emdobrin emdobrin deleted the responsehandler branch January 10, 2021 19:59
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.

Write functional tests with response callback Revisit EdgeResponseHandler

4 participants