-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Adds watcher for continuous doc import. Watcher has a timeout of 5 seconds between tries. Adds multi database support. Ignores postgres deadlock errors, and adds retry. Updates e2e tests to: not use two additional containers to push data to CouchDb, that used python to push data not have data in a zipped file, where it's literally invisible to the developer. instead using scalability csv docs, and using cht-conf to generate documents that get uploaded before the test runs. updates test to wait until DBT processing is complete and checks number of results. #107
- Loading branch information
1 parent
c5cb57f
commit 279d8f2
Showing
34 changed files
with
28,229 additions
and
2,781 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ node_modules | |
*/coverage/* | ||
/couch2pg/.nyc_output/ | ||
/.eslintcache | ||
/tests/data/json_docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import * as setup from './setup.js'; | ||
import watcher from './watcher.js'; | ||
import * as db from './db.js'; | ||
import importer from './importer.js'; | ||
|
||
(async() => { | ||
await setup.createDatabase(); | ||
|
||
await importer(db.getCouchDbClient()); | ||
db.couchDbs.forEach(db => watcher(db)); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import importer from './importer.js'; | ||
import * as db from './db.js'; | ||
|
||
const DELAY = 5 * 1000; // 5 seconds | ||
|
||
export default async (dbName) => { | ||
const couchDb = db.getCouchDbClient(dbName); | ||
do { | ||
const processedChanges = await importer(couchDb); | ||
if (!processedChanges) { | ||
await new Promise(r => setTimeout(r, DELAY)); | ||
} | ||
// eslint-disable-next-line no-constant-condition | ||
} while (true); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import '../common.js'; | ||
import sinon from 'sinon'; | ||
import esmock from 'esmock'; | ||
|
||
let clock; | ||
let importer; | ||
let db; | ||
let watcher; | ||
|
||
describe('watcher', () => { | ||
beforeEach(async () => { | ||
clock = sinon.useFakeTimers(); | ||
|
||
db = { getCouchDbClient: sinon.stub() }; | ||
importer = sinon.stub(); | ||
|
||
watcher = await esmock('../../src/watcher', { '../../src/db': db, '../../src/importer': importer }); | ||
}); | ||
|
||
afterEach(() => { | ||
clock.restore(); | ||
sinon.restore(); | ||
}); | ||
|
||
it('should watch proposed database', async () => { | ||
importer.onCall(0).resolves(2); | ||
importer.onCall(1).resolves(3); | ||
importer.onCall(2).resolves(0); | ||
|
||
watcher('this is the db name'); | ||
|
||
expect(db.getCouchDbClient.calledOnceWith('this is the db name')).to.equal(true); | ||
expect(importer.calledOnce).to.equal(true); | ||
await Promise.resolve(); | ||
expect(importer.calledTwice).to.equal(true); | ||
await Promise.resolve(); | ||
expect(importer.calledThrice).to.equal(true); | ||
}); | ||
|
||
it('should wait for 5 seconds after no results are processed', async () => { | ||
importer.onCall(0).resolves(2); | ||
importer.onCall(1).resolves(3); | ||
importer.onCall(2).resolves(0); | ||
importer.onCall(3).resolves(2); | ||
importer.onCall(4).resolves(0); | ||
|
||
watcher('medic-sentinel'); | ||
|
||
expect(db.getCouchDbClient.calledOnceWith('medic-sentinel')).to.equal(true); | ||
expect(importer.calledOnce).to.equal(true); | ||
await Promise.resolve(); | ||
expect(importer.calledTwice).to.equal(true); | ||
await Promise.resolve(); | ||
expect(importer.calledThrice).to.equal(true); | ||
await Promise.resolve(); | ||
expect(importer.calledThrice).to.equal(true); | ||
clock.tick(5 * 1000); | ||
await Promise.resolve(); | ||
expect(importer.callCount).to.equal(4); | ||
await Promise.resolve(); | ||
expect(importer.callCount).to.equal(5); | ||
}); | ||
|
||
it('should stop on errors', async () => { | ||
importer.onCall(0).resolves(2); | ||
importer.onCall(1).resolves(3); | ||
importer.onCall(2).rejects(new Error('boom')); | ||
|
||
await expect(watcher('db')).to.eventually.be.rejectedWith('boom'); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.