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: be more exact when waiting for peers #866

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions test-e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,21 @@ export async function invite({
*/
export const waitForPeers = (managers, { waitForDeviceInfo = false } = {}) =>
new Promise((res) => {
const expectedCount = managers.length - 1
const deviceIds = new Set(managers.map((m) => m.deviceId))

const isDone = () =>
managers.every((manager) => {
const { peers } = manager[kRPC]
const connectedPeers = peers.filter(
({ status }) => status === 'connected'
)
return (
connectedPeers.length === expectedCount &&
(!waitForDeviceInfo || connectedPeers.every(({ name }) => !!name))
)
const unconnectedDeviceIds = new Set(deviceIds)
unconnectedDeviceIds.delete(manager.deviceId)
for (const peer of manager[kRPC].peers) {
if (
peer.status === 'connected' &&
(!waitForDeviceInfo || peer.name)
) {
unconnectedDeviceIds.delete(peer.deviceId)
}
}
return unconnectedDeviceIds.size === 0
})

if (isDone()) {
Expand Down
Loading