Skip to content

Commit

Permalink
fix: Ensure we actuallu use the passed in store (#449)
Browse files Browse the repository at this point in the history
There was a bug where we ignored the passed in experiementKVStore.
  • Loading branch information
arv authored Aug 10, 2021
1 parent 246d8f4 commit 502531c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
50 changes: 50 additions & 0 deletions src/replicache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
dbsToDrop,
} from './test-util.js';
import {sleep} from './sleep.js';
import {MemStore} from './kv/mem-store.js';

let clock: SinonFakeTimers;
setup(function () {
Expand Down Expand Up @@ -2887,3 +2888,52 @@ test('overlapping open/close', async () => {
await p2;
}
});

test('experiment KV Store', async () => {
let readCount = 0;
let writeCount = 0;
let closeCount = 0;

class MyMemStore {
readonly store = new MemStore();
read() {
readCount++;
return this.store.read();
}
write() {
writeCount++;
return this.store.write();
}
async close() {
closeCount++;
}
}

const store = new MyMemStore();

const rep = await replicacheForTesting('experiment-kv-store', {
experimentalKVStore: store,
mutators: {addData},
});

expect(readCount).to.equal(3);
expect(writeCount).to.equal(3);
expect(closeCount).to.equal(0);

const b = await rep.query(tx => tx.has('foo'));
expect(b).to.be.false;

expect(readCount).to.equal(4);
expect(writeCount).to.equal(3);
expect(closeCount).to.equal(0);

await rep.mutate.addData({foo: 'bar'});
expect(readCount).to.equal(4);
expect(writeCount).to.equal(4);
expect(closeCount).to.equal(0);

await rep.close();
expect(readCount).to.equal(4);
expect(writeCount).to.equal(4);
expect(closeCount).to.equal(1);
});
5 changes: 2 additions & 3 deletions src/replicache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,8 @@ export class Replicache<MD extends MutatorDefs = {}>
this.puller = puller;
this.pusher = pusher;
this._store =
experimentalKVStore || this._useMemstore
? new MemStore()
: new IDBStore(this.name);
experimentalKVStore ||
(this._useMemstore ? new MemStore() : new IDBStore(this.name));

// Use a promise-resolve pair so that we have a promise to use even before
// we call the Open RPC.
Expand Down

3 comments on commit 502531c

@arv
Copy link
Contributor Author

@arv arv commented on 502531c Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: 502531c Previous: 246d8f4 Ratio
create index 1024x5000 0.78 ops/sec (±51.0%) 1.41 ops/sec (±1.8%) 1.81

This comment was automatically generated by workflow using github-action-benchmark.

@aboodman
Copy link
Contributor

@aboodman aboodman commented on 502531c Aug 10, 2021 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arv
Copy link
Contributor Author

@arv arv commented on 502531c Aug 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at https://rocicorp.github.io/replicache/perf/ it does not seem real

Please sign in to comment.