From 7e4fdf37432a86fbc27d0c358e550c343cf143e3 Mon Sep 17 00:00:00 2001 From: Sean Zellmer Date: Thu, 14 Dec 2023 14:24:41 -0500 Subject: [PATCH] fix: Call `this.base.ready()` in `manager.ready()` This will load the keys for the local input & output and ensures the underlying Autobase is ready for the manager. --- index.js | 2 +- tests/basics.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 51a3352..38606cd 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/tests/basics.js b/tests/basics.js index 854d8d6..6364564 100644 --- a/tests/basics.js +++ b/tests/basics.js @@ -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)