Skip to content

Commit 7bb9701

Browse files
authored
Merge pull request #29 from smartprocure/daveyarwood/GS-9973-regularly-update-resume-token
0.51.0: Bump mongochangestream to pick up refresh token improvements
2 parents 24e456a + d59744c commit 7bb9701

6 files changed

+70
-39
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 0.51.0
2+
3+
- Latest `mongochangestream` - Performance improvements related to updating the
4+
refresh token more often. See [mongochangestream
5+
changelog](https://github.com/smartprocure/mongochangestream/blob/master/CHANGELOG.md#0590)
6+
17
# 0.50.0
28

39
- Remove try/catch and rely on retry logic in `mongochangestream`.

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,16 @@ const options = { batchSize: 1000 }
4040
const initialScan = await sync.runInitialScan(options)
4141
initialScan.start()
4242
```
43+
44+
## Run the tests locally
45+
46+
Create a .env file with the following variables set to the appropriate values:
47+
48+
```
49+
MONGO_CONN="mongodb+srv://..."
50+
ELASTIC_NODE='https://elastic-node-url-here.com'
51+
ELASTIC_USERNAME="username-here"
52+
ELASTIC_PASSWORD="password-here"
53+
```
54+
55+
Then run `npm test` to run the tests.

package-lock.json

+22-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongo2elastic",
3-
"version": "0.50.0",
3+
"version": "0.51.0",
44
"description": "Sync MongoDB collections to Elasticsearch",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -47,7 +47,7 @@
4747
"@types/node": "^22.10.2",
4848
"@typescript-eslint/eslint-plugin": "^8.19.0",
4949
"globals": "^15.14.0",
50-
"mongochangestream-testing": "^0.1.0",
50+
"mongochangestream-testing": "^0.5.0",
5151
"ms": "^2.1.3",
5252
"prettier": "^3.4.2",
5353
"typescript": "^5.7.2",
@@ -64,16 +64,20 @@
6464
"lodash": "^4.17.21",
6565
"make-error": "^1.3.6",
6666
"minimatch": "^10.0.1",
67-
"mongochangestream": "^0.58.0",
67+
"mongochangestream": "^0.59.0",
6868
"obj-walker": "^2.4.0",
6969
"prom-utils": "^0.14.0"
7070
},
7171
"prettier": {
7272
"semi": false,
7373
"singleQuote": true,
7474
"trailingComma": "es5",
75-
"plugins": ["@trivago/prettier-plugin-sort-imports"],
76-
"importOrder": ["^[./]"],
75+
"plugins": [
76+
"@trivago/prettier-plugin-sort-imports"
77+
],
78+
"importOrder": [
79+
"^[./]"
80+
],
7781
"importOrderSortSpecifiers": true,
7882
"importOrderCaseInsensitive": true,
7983
"importOrderSeparation": true

src/syncData.test.ts

+19-15
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import elasticsearch from '@elastic/elasticsearch'
2+
import debug from 'debug'
23
import Redis from 'ioredis'
34
import _ from 'lodash/fp.js'
45
import {
6+
assertEventually,
57
initState as initRedisAndMongoState,
68
numDocs,
79
} from 'mongochangestream-testing'
810
import { type Db, MongoClient } from 'mongodb'
911
import ms from 'ms'
1012
import { setTimeout } from 'node:timers/promises'
11-
import { describe, expect, test } from 'vitest'
12-
import debug from 'debug'
13+
import { describe, test } from 'vitest'
14+
15+
import { initSync, SyncOptions } from './index.js'
1316

1417
// Output via console.info (stdout) instead of stderr.
1518
// Without this debug statements are swallowed by vitest.
1619
debug.log = console.info.bind(console)
1720

18-
import { initSync, SyncOptions } from './index.js'
19-
2021
const index = 'testing'
2122

2223
const getConns = _.memoize(async () => {
@@ -79,13 +80,14 @@ describe.sequential('syncCollection', () => {
7980
await initElasticState(sync, db)
8081

8182
const initialScan = await sync.runInitialScan()
82-
// Wait for initial scan to complete
8383
await initialScan.start()
84-
await setTimeout(ms('1s'))
84+
// Test that all of the records are eventually synced.
85+
await assertEventually(async () => {
86+
const countResponse = await elasticClient.count({ index })
87+
return countResponse.count == numDocs
88+
}, `Less than ${numDocs} records were processed`)
8589
// Stop
8690
await initialScan.stop()
87-
const countResponse = await elasticClient.count({ index })
88-
expect(countResponse.count).toBe(numDocs)
8991
})
9092
test('should process records via change stream', async () => {
9193
const { coll, db, elasticClient } = await getConns()
@@ -95,18 +97,20 @@ describe.sequential('syncCollection', () => {
9597

9698
const changeStream = await sync.processChangeStream()
9799
changeStream.start()
100+
// Give change stream time to connect.
98101
await setTimeout(ms('1s'))
99102
const date = new Date()
100103
// Update records
101104
coll.updateMany({}, { $set: { createdAt: date } })
102-
// Wait for the change stream events to be processed
103-
await setTimeout(ms('2s'))
104-
const countResponse = await elasticClient.count({
105-
index,
106-
query: { range: { createdAt: { gte: date } } },
107-
})
105+
// Test that all of the records are eventually synced.
106+
await assertEventually(async () => {
107+
const countResponse = await elasticClient.count({
108+
index,
109+
query: { range: { createdAt: { gte: date } } },
110+
})
111+
return countResponse.count == numDocs
112+
}, `Less than ${numDocs} records were processed`)
108113
// Stop
109114
await changeStream.stop()
110-
expect(countResponse.count).toBe(numDocs)
111115
})
112116
})

vitest.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import { defineConfig } from 'vitest/config'
44
export default defineConfig(({ mode }) => ({
55
test: {
66
env: loadEnv(mode, process.cwd(), ''),
7-
testTimeout: 30000,
7+
testTimeout: 60000,
88
},
99
}))

0 commit comments

Comments
 (0)