-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(client-presence): disabled (failing) attendees unit tests #23113
base: main
Are you sure you want to change the base?
Conversation
const isAttendeeConnected = | ||
audienceMembers.has(clientConnectionId) || | ||
senderConnectionId === clientConnectionId || | ||
connectedAttendees.has(attendee); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a pretty complicated state system. I feel like I'll be able to break it. :)
This line in particular needs more explanation. The other two make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments here for each condition, but willing to change if one does not seem reasonable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commentary that is interesting to capture is why the first two checks aren't sufficient.
And perhaps make the statement less strong. Really, we consider the attendee connected if the audience says so. And we override audience when sender id matches (which we want comments for somewhere).
I believe the last case is saying: attendee is connected if any of the connection ids for the attendee are current/connected. As we process in a list this check provides if any of the past connection ids were connected. If none are to this point then we'll set disconnected and should any later connection be found connected status will be set to connected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok yes this makes sense, will add a more detailed comment along these lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to also add that I did not make any assumptions based on the ordering of connection IDs received from the remote datastore. That is, I did not write the code with the guarantee that previous connection IDs will appear first, and more recent ones will appear later. The last check is not necessary if that is a guarantee that we enforce, and I think this function can be written without the connectedAttendees
set.
attendee.setConnectionId(clientConnectionId); | ||
isNew = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- add comments
- maybe
isNew
could use a rename likeisNewConnection
. - an overall comment that all updated attendees will have their connection status set to Connected seems worthy.... as it is up to the caller to reset if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think isJoining
(the session) is the best name here, since it dictates if we announce attendeeJoined event. If a known attendee is connected and we receive a new connectionId, we should set the new connectionId but they are not necessarily joining the session and should not be announced. If known attendee is disconnected then it makes sense to announce new connection, since they are (re)joining the session.
Brought back updateStatus to setConnectionId, so we can update connectionId here and handle connection status in processUpdate()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't set connection status here where should setConnectionId
be called to silently update the status?
(Silence is bad. With something as tricky as the connection status seems to be anything that updates the status should be very clear and explicit. Default param is worst. Having it be a boolean is secondarily unfortunate.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment #23113 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Coverage Summary
↑ packages.framework.presence.src:
Line Coverage Change: 0.04% Branch Coverage Change: 0.56%
Metric Name | Baseline coverage | PR coverage | Coverage Diff |
---|---|---|---|
Branch Coverage | 88.57% | 89.13% | ↑ 0.56% |
Line Coverage | 73.96% | 74.00% | ↑ 0.04% |
Baseline commit: d3bf90c
Baseline build: 308876
Happy Coding!!
Code coverage comparison check passed!!
⯅ @fluid-example/bundle-size-tests: +245 Bytes
Baseline commit: d3bf90c |
// If attendee is connected, update their connection ID and status. | ||
connectedAttendees.add(attendee); | ||
if (attendee.getConnectionStatus() === SessionClientStatus.Disconnected) { | ||
attendee.setConnectionId(clientConnectionId); | ||
} | ||
if (isNew) { | ||
// If the attendee is both new and in audience (i.e. currently connected), emit an attendeeJoined event. | ||
postUpdateActions.push(() => this.events.emit("attendeeJoined", attendee)); | ||
attendee.setConnectionId(clientConnectionId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't ensureAttendee
already do connection ID update?
Why are any of the clientConnectionIds that happen to be associated with the attendee okay to set as the current connection id.
I guess we need a test case where early connection ID is in audience, but a later one processed is not in the audience. Result should be that the early actual connected ID is the one that is should be provided by getConnectionId().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ensureAttendee
makes sure that the correct connection ID is set (updateStatus is set to false), but this function is responsible for making sure the attendees connection status is set to 'Connected'. I updated with a new function setConnected()
to make this intent explicit and to avoid unnecessarily messing around with assigning correct connectionID's here.
Description
A few unit tests were added disabled as current implementation does not meet expectations. This PR enable these tests and updates implementation: