Skip to content

Commit ad91e35

Browse files
jeswrRubenVerborgh
authored andcommitted
test: Add tests for concurrent read/write behavior.
1 parent 86ee67c commit ad91e35

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

test/N3Store-test.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
termFromId, termToId,
88
} from '../src/';
99
import namespaces from '../src/IRIs';
10-
import chai from 'chai';
10+
import chai, { expect } from 'chai';
1111
import { Readable } from 'readable-stream';
1212
import arrayifyStream from 'arrayify-stream';
1313

@@ -1636,6 +1636,34 @@ describe('Store', () => {
16361636
});
16371637
});
16381638
});
1639+
1640+
describe('handles concurrent read/write', () => {
1641+
let store;
1642+
beforeEach(() => {
1643+
store = new Store([
1644+
new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')),
1645+
new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o3')),
1646+
]);
1647+
});
1648+
1649+
it('should include added elements in match if iteration has not yet started', () => {
1650+
const m = store.match(null, null, null, null);
1651+
store.add(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o2')));
1652+
[...m].should.have.length(3);
1653+
[...store.match(null, null, null, null)].should.have.length(3);
1654+
});
1655+
1656+
it('should still include results of original match after iterating while adding new data', () => {
1657+
const m = store.match(null, null, null, null)[Symbol.iterator]();
1658+
m.next().value.should.deep.equal(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o1')));
1659+
store.add(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o0')));
1660+
store.add(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o2')));
1661+
store.add(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o4')));
1662+
m.next().value.should.deep.equal(new Quad(new NamedNode('s1'), new NamedNode('p1'), new NamedNode('o3')));
1663+
m.next().done.should.be.true;
1664+
[...store.match(null, null, null, null)].should.have.length(5);
1665+
});
1666+
});
16391667
});
16401668

16411669
function alwaysTrue() { return true; }

0 commit comments

Comments
 (0)