|
7 | 7 | termFromId, termToId, |
8 | 8 | } from '../src/'; |
9 | 9 | import namespaces from '../src/IRIs'; |
10 | | -import chai from 'chai'; |
| 10 | +import chai, { expect } from 'chai'; |
11 | 11 | import { Readable } from 'readable-stream'; |
12 | 12 | import arrayifyStream from 'arrayify-stream'; |
13 | 13 |
|
@@ -1636,6 +1636,34 @@ describe('Store', () => { |
1636 | 1636 | }); |
1637 | 1637 | }); |
1638 | 1638 | }); |
| 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 | + }); |
1639 | 1667 | }); |
1640 | 1668 |
|
1641 | 1669 | function alwaysTrue() { return true; } |
|
0 commit comments