Skip to content

Commit

Permalink
Merge branch 'main' into fix-test-invite-race-conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn authored Sep 25, 2024
2 parents 1b03ac0 + e8764c4 commit 8f7f94f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
11 changes: 11 additions & 0 deletions test-e2e/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,17 @@ test('no sync capabilities === no namespaces sync apart from auth', async (t) =>
)
const [invitorProject, inviteeProject] = projects

assert.equal(
(await invitorProject.$member.getById(blocked.deviceId)).role.roleId,
BLOCKED_ROLE_ID,
'invitor sees blocked participant as part of the project'
)
assert.equal(
(await inviteeProject.$member.getById(blocked.deviceId)).role.roleId,
BLOCKED_ROLE_ID,
'invitee sees blocked participant as part of the project'
)

const generatedDocs = (await seedDatabases([inviteeProject])).flat()
const configDocsCount = generatedDocs.filter(
(doc) => doc.schemaName !== 'observation'
Expand Down
22 changes: 13 additions & 9 deletions test-e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,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

0 comments on commit 8f7f94f

Please sign in to comment.