Skip to content
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

test(client-presence): old collateral connection and stale connection tests #23351

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

WillieHabi
Copy link
Contributor

@WillieHabi WillieHabi commented Dec 17, 2024

Description

There are 6 tests that are added (and disabled) in this PR.

The first test is to verify that old collateral connections do not effect the connection status of remote attendees. This scenario was written as an edge case to old solution where old connection information sent in a join response would result in the attendee connection status being set to 'Disconnected'.

The next five have to do with stale remote attendee's connection status upon local client reconnect scenarios:

Presence
  PresenceManager
    when connected
      attendee
        that is joining
          - as collateral with old connection info and connected is NOT announced via `attendeeJoined
        that is already known
          and has their connection removed
            - updates stale attendee status to 'Disconnected' after 30s delay upon reconnection
            - does not update stale attendee status if local client does not reconnect
            - does not update stale attendee status if local client reconnection lasts less than 30s
            - does not update attendee status to 'Disconnected' if stale attendee becomes active
            - updates stale attendee status to 'Disconnected' only 30s after most recent reconnection

I added connect() and disconnect() function to MockEphemeralRuntime that manipulates the connection state of the local client.

@Copilot Copilot bot review requested due to automatic review settings December 17, 2024 22:31
@github-actions github-actions bot added area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct base: main PRs targeted against main branch labels Dec 17, 2024
@WillieHabi WillieHabi changed the title initial commit test(client-presence): collateral connection and stale connection tests Dec 17, 2024

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

packages/framework/presence/src/internalTypes.ts:54

  • The event names 'connected' and 'disconnected' should be consistent with the rest of the codebase.
export interface EphemeralRuntimeEvents extends IEvent {

packages/framework/presence/src/test/mockEphemeralRuntime.ts:121

  • The removal of the 'on' and 'off' methods from 'MockEphemeralRuntime' might break existing code that relies on these methods. Confirm if this change was intentional and if it might cause any issues.
public clientId: string | undefined;

packages/framework/presence/src/test/mockEphemeralRuntime.ts:71

  • [nitpick] Ensure that the new event handling mechanism is consistent with the rest of the codebase and aligns with existing conventions.
extends TypedEventEmitter<EphemeralRuntimeEvents>
@WillieHabi WillieHabi changed the title test(client-presence): collateral connection and stale connection tests test(client-presence): old collateral connection and stale connection tests Dec 17, 2024
@WillieHabi WillieHabi requested a review from jason-ha December 17, 2024 23:15
@WillieHabi
Copy link
Contributor Author

Updated the tests a bit from our last discussion, looking for some guidance around better ways to simulate reconnect since I now know we want to move away from TypedEventEmitter @jason-ha

Copy link
Contributor

@jason-ha jason-ha left a comment

Choose a reason for hiding this comment

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

I like a lot - still have notes :)

Comment on lines 525 to 527
});

it.skip("updates stale attendees status to 'Disconnected' afer multiple reconnects", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

between these cases I am curious what happens after local connect is disconnected again. Do the stale connections ever become disconnected?
And what about the case where local disconnects, connects, and we hear from one of the stale connections?

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 added a few other test cases to the existing ones:

  • stale attendee status is not updated to 'Disconnected' if local client does not reconnect
  • stale attendee status is not updated to 'Disconnected' if local client reconnection lasts less than 30s
  • attendee status is not updated to 'Disconnected' if stale attendee becomes active

@WillieHabi WillieHabi requested a review from jason-ha December 19, 2024 17:51
Copy link
Contributor

@jason-ha jason-ha left a comment

Choose a reason for hiding this comment

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

few more suggestions

Comment on lines +456 to +457
});
it("is announced via `attendeeDisconnected`", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Should have a blank line in here

Comment on lines +462 to 470
assert.strictEqual(
disconnectedAttendees.length,
1,
"Exactly one attendee should be announced as disconnected",
);
assert(
disconnectedAttendee !== undefined,
disconnectedAttendees[0] !== undefined,
"No attendee was disconnected during `removeMember`",
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Second assert is not useful.

Comment on lines +541 to +542
// Verify - stale attendee should still be 'Connected' after 30 seconds
clock.tick(30_001);
Copy link
Contributor

Choose a reason for hiding this comment

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

the tick is part of the action
you can use a larger number (a much larger number)
in the other cases the time past is 31,002.

Comment on lines +559 to +566
clock.tick(15_001); // Wait another 15 seconds (30s total since reconnection)

// Verify - stale attendee should still be 'Connected' after 30s post-reconnection
assert.strictEqual(
knownAttendee.getConnectionStatus(),
SessionClientStatus.Connected,
"Stale attendee should still be 'Connected' after 30s",
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can use a larger number here as well. There is no time that is too large as should never disconnect.

Comment on lines +580 to +585
// Verify
assert.strictEqual(
knownAttendee.getConnectionStatus(),
SessionClientStatus.Connected,
"Active attendee should still be 'Connected' 30s after reconnection",
);
Copy link
Contributor

Choose a reason for hiding this comment

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

And also doesn't raise an attendeeJoined event

Comment on lines 445 to -376
describe("and has their connection removed", () => {
it("is announced via `attendeeDisconnected`", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized the grammar of what these cases are saying after rereading the PR description. Thank for putting the test list in there. If you read the "sentence" down you get:
PresenceManager , when connected, attendee that is already known and has their connection removed...
In that situation "their" refers to "attendee". But you mean to refer to this local client.

Comment on lines +569 to +577
it.skip("does not update attendee status to 'Disconnected' if stale attendee becomes active", () => {
assert(knownAttendee !== undefined, "No attendee was set in beforeEach");

// Act - disconnect, reconnect, then process rejoin signal from known attendee after 15s
runtime.disconnect();
clock.tick(1000);
runtime.connect("client6");
clock.tick(15_001);
processJoinSignals([rejoinAttendeeSignal]);
Copy link
Contributor

Choose a reason for hiding this comment

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

How else might a stale attendee become active. This sounds like situation where the other was also disconnected but has rejoined. What about if the other had always stayed connected?

@jason-ha jason-ha self-requested a review December 20, 2024 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct base: main PRs targeted against main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants