Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions src/mapeo-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { getFastifyServerAddress } from './fastify-plugins/utils.js'
import { LocalPeers } from './local-peers.js'
import { InviteApi } from './invite/invite-api.js'
import { LocalDiscovery } from './discovery/local-discovery.js'
import { Roles } from './roles.js'
import { Roles, BLOCKED_ROLE } from './roles.js'
import { Logger } from './logger.js'
import {
kSyncState,
Expand Down Expand Up @@ -792,6 +792,7 @@ export class MapeoManager extends TypedEmitter {
// in the config store - defining the name of the project.
// TODO: Enforce adding a project name in the invite method
const isConfigSynced = configState.want === 0 && configState.have > 0
if (ownRole === BLOCKED_ROLE && isAuthSynced) return true
if (
isRoleSynced &&
isProjectSettingsSynced &&
Expand All @@ -803,6 +804,7 @@ export class MapeoManager extends TypedEmitter {
this.#l.log(
'Pending initial sync: role %s, projectSettings %o, auth %o, config %o',
isRoleSynced,
isProjectSettingsSynced,
isAuthSynced,
isConfigSynced
)
Expand All @@ -816,7 +818,7 @@ export class MapeoManager extends TypedEmitter {
return
}
project.$sync[kSyncState].off('state', onSyncState)
resolve(this.#waitForInitialSync(project, { timeoutMs }))
this.#waitForInitialSync(project, { timeoutMs }).then(resolve, reject)
}
const onTimeout = () => {
project.$sync[kSyncState].off('state', onSyncState)
Expand Down
2 changes: 1 addition & 1 deletion src/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const CREATOR_ROLE = {
/**
* @type {Role<typeof BLOCKED_ROLE_ID>}
*/
const BLOCKED_ROLE = {
export const BLOCKED_ROLE = {
roleId: BLOCKED_ROLE_ID,
name: 'Blocked',
docs: mapObject(currentSchemaVersions, (key) => {
Expand Down
15 changes: 8 additions & 7 deletions test-e2e/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,8 @@ test('no sync capabilities === no namespaces sync apart from auth', async (t) =>
const [invitor, invitee, blocked] = managers
const disconnect1 = connectPeers(managers)

t.after(() => disconnect1())

const projectId = await invitor.createProject({ name: 'Mapeo' })

await invite({
Expand All @@ -919,6 +921,8 @@ test('no sync capabilities === no namespaces sync apart from auth', async (t) =>
managers.map((m) => m.getProject(projectId))
)

t.after(() => Promise.all(projects.map((p) => p.close())))

const [invitorProject, inviteeProject] = projects

assert.equal(
Expand Down Expand Up @@ -955,18 +959,15 @@ test('no sync capabilities === no namespaces sync apart from auth', async (t) =>
assert.equal(blockedState.data.localState.have, 0) // no data docs synced

for (const ns of NAMESPACES) {
assert.equal(invitorState[ns].coreCount, 3, ns)
assert.equal(inviteeState[ns].coreCount, 3, ns)
assert.equal(blockedState[ns].coreCount, 3, ns)
assert.equal(invitorState[ns].coreCount, 3, `invitor got cores for ${ns}`)
assert.equal(inviteeState[ns].coreCount, 3, `invitee got cores for ${ns}`)
assert.equal(blockedState[ns].coreCount, 3, `blocked got cores for ${ns}`)
assert.deepEqual(
invitorState[ns].localState,
inviteeState[ns].localState,
ns
`invitor/invitee have same local state for ${ns}`
)
}

await disconnect1()
await Promise.all(projects.map((p) => p.close()))
})

test('Sync state emitted when starting and stopping sync', async function (t) {
Expand Down