Skip to content

Commit

Permalink
fix: Call this.base.ready() in manager.ready()
Browse files Browse the repository at this point in the history
This will load the keys for the local input & output and ensures the
underlying Autobase is ready for the manager.
  • Loading branch information
lejeunerenard committed Dec 14, 2023
1 parent a061b9a commit 7e4fdf3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class AutobaseManager extends EventEmitter {
this._streams = []

// Load storage
this._ready = Promise.resolve().then(() => {
this._ready = this.base.ready().then(() => {
const coresToLoad = []

// Load local cores first
Expand Down
28 changes: 28 additions & 0 deletions tests/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,34 @@ async function create (storage) {
return [store, base]
}

test('basic usage', (t) => {
t.test('manager.ready()', (t) => {
t.test('calls base.ready', async (t) => {
const store = new Corestore(RAM)
await store.ready()

const core = store.get({ name: 'my-input' })
const coreOut = store.get({ name: 'my-output' })
const base = new Autobase({
inputs: [core],
localInput: core,
outputs: [coreOut],
localOutput: coreOut,
autostart: true,
eagerUpdate: true
})

const manager = new AutobaseManager(base, () => true,
store.get.bind(store), store.storage)
await manager.ready()

t.ok(core.key, 'input key is defined')
t.ok(coreOut.key, 'outupt key is defined')
t.end()
})
})
})

test('full replicate', (t) => {
t.test('adds localInputs between autobases', async (t) => {
t.plan(1)
Expand Down

0 comments on commit 7e4fdf3

Please sign in to comment.