@powersync/service-module-mongodb 0.0.0-dev-20250108084515 → 0.0.0-dev-20250116115804

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,12 @@
1
+ import { mongo } from '@powersync/lib-service-mongodb';
1
2
  import { ActiveCheckpoint, BucketStorageFactory, OpId, SyncRulesBucketStorage } from '@powersync/service-core';
3
+ import { test_utils } from '@powersync/service-core-tests';
2
4
 
3
5
  import { ChangeStream, ChangeStreamOptions } from '@module/replication/ChangeStream.js';
4
6
  import { MongoManager } from '@module/replication/MongoManager.js';
5
7
  import { createCheckpoint } from '@module/replication/MongoRelation.js';
6
8
  import { NormalizedMongoConnectionConfig } from '@module/types/types.js';
7
- import { test_utils } from '@powersync/service-core-tests';
8
- import * as mongo from 'mongodb';
9
+
9
10
  import { TEST_CONNECTION_OPTIONS, clearTestDb } from './util.js';
10
11
 
11
12
  export class ChangeStreamTestContext {
@@ -37,6 +38,7 @@ export class ChangeStreamTestContext {
37
38
  this.abortController.abort();
38
39
  await this.streamPromise?.catch((e) => e);
39
40
  await this.connectionManager.destroy();
41
+ await this.factory[Symbol.asyncDispose]();
40
42
  }
41
43
 
42
44
  async [Symbol.asyncDispose]() {
@@ -156,7 +158,6 @@ export async function getClientCheckpoint(
156
158
  if (cp.lsn && cp.lsn >= lsn) {
157
159
  return cp.checkpoint;
158
160
  }
159
-
160
161
  await new Promise((resolve) => setTimeout(resolve, 30));
161
162
  }
162
163
 
package/test/src/env.ts CHANGED
@@ -3,6 +3,9 @@ import { utils } from '@powersync/lib-services-framework';
3
3
  export const env = utils.collectEnvironmentVariables({
4
4
  MONGO_TEST_URL: utils.type.string.default('mongodb://localhost:27017/powersync_test'),
5
5
  MONGO_TEST_DATA_URL: utils.type.string.default('mongodb://localhost:27017/powersync_test_data'),
6
+ PG_STORAGE_TEST_URL: utils.type.string.default('postgres://postgres:postgres@localhost:5431/powersync_storage_test'),
6
7
  CI: utils.type.boolean.default('false'),
7
- SLOW_TESTS: utils.type.boolean.default('false')
8
+ SLOW_TESTS: utils.type.boolean.default('false'),
9
+ TEST_MONGO_STORAGE: utils.type.boolean.default('true'),
10
+ TEST_POSTGRES_STORAGE: utils.type.boolean.default('true')
8
11
  });
@@ -1,11 +1,12 @@
1
+ import { mongo } from '@powersync/lib-service-mongodb';
2
+ import { SqliteRow, SqlSyncRules } from '@powersync/service-sync-rules';
3
+ import { describe, expect, test } from 'vitest';
4
+
1
5
  import { MongoRouteAPIAdapter } from '@module/api/MongoRouteAPIAdapter.js';
2
6
  import { ChangeStream } from '@module/replication/ChangeStream.js';
3
7
  import { constructAfterRecord } from '@module/replication/MongoRelation.js';
4
- import { SqliteRow, SqlSyncRules } from '@powersync/service-sync-rules';
5
- import * as mongo from 'mongodb';
6
- import { describe, expect, test } from 'vitest';
7
- import { clearTestDb, connectMongoData, TEST_CONNECTION_OPTIONS } from './util.js';
8
8
  import { PostImagesOption } from '@module/types/types.js';
9
+ import { clearTestDb, connectMongoData, TEST_CONNECTION_OPTIONS } from './util.js';
9
10
 
10
11
  describe('mongo data types', () => {
11
12
  async function setupTable(db: mongo.Db) {
package/test/src/setup.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { container } from '@powersync/lib-services-framework';
2
2
  import { test_utils } from '@powersync/service-core-tests';
3
+ import { beforeEach } from 'node:test';
3
4
  import { beforeAll } from 'vitest';
4
5
 
5
6
  beforeAll(async () => {
@@ -8,3 +9,7 @@ beforeAll(async () => {
8
9
 
9
10
  await test_utils.initMetrics();
10
11
  });
12
+
13
+ beforeEach(async () => {
14
+ await test_utils.resetMetrics();
15
+ });
@@ -1,12 +1,14 @@
1
- import { storage } from '@powersync/service-core';
2
- import * as mongo from 'mongodb';
3
1
  import { setTimeout } from 'node:timers/promises';
4
2
  import { describe, expect, test } from 'vitest';
3
+
4
+ import { mongo } from '@powersync/lib-service-mongodb';
5
+ import { storage } from '@powersync/service-core';
6
+
5
7
  import { ChangeStreamTestContext, setSnapshotHistorySeconds } from './change_stream_utils.js';
6
8
  import { env } from './env.js';
7
- import { INITIALIZED_MONGO_STORAGE_FACTORY } from './util.js';
9
+ import { INITIALIZED_MONGO_STORAGE_FACTORY, INITIALIZED_POSTGRES_STORAGE_FACTORY } from './util.js';
8
10
 
9
- describe('change stream slow tests - mongodb', { timeout: 60_000 }, function () {
11
+ describe.skipIf(!env.TEST_MONGO_STORAGE)('change stream slow tests - mongodb', { timeout: 60_000 }, function () {
10
12
  if (env.CI || env.SLOW_TESTS) {
11
13
  defineSlowTests(INITIALIZED_MONGO_STORAGE_FACTORY);
12
14
  } else {
@@ -15,6 +17,15 @@ describe('change stream slow tests - mongodb', { timeout: 60_000 }, function ()
15
17
  }
16
18
  });
17
19
 
20
+ describe.skipIf(!env.TEST_POSTGRES_STORAGE)('change stream slow tests - postgres', { timeout: 60_000 }, function () {
21
+ if (env.CI || env.SLOW_TESTS) {
22
+ defineSlowTests(INITIALIZED_POSTGRES_STORAGE_FACTORY);
23
+ } else {
24
+ // Need something in this file.
25
+ test('no-op', () => {});
26
+ }
27
+ });
28
+
18
29
  function defineSlowTests(factory: storage.TestStorageFactory) {
19
30
  test('replicating snapshot with lots of data', async () => {
20
31
  await using context = await ChangeStreamTestContext.open(factory);
package/test/src/util.ts CHANGED
@@ -1,7 +1,8 @@
1
- import * as types from '@module/types/types.js';
2
-
1
+ import { mongo } from '@powersync/lib-service-mongodb';
3
2
  import * as mongo_storage from '@powersync/service-module-mongodb-storage';
4
- import * as mongo from 'mongodb';
3
+ import * as postgres_storage from '@powersync/service-module-postgres-storage';
4
+
5
+ import * as types from '@module/types/types.js';
5
6
  import { env } from './env.js';
6
7
 
7
8
  export const TEST_URI = env.MONGO_TEST_DATA_URL;
@@ -16,6 +17,10 @@ export const INITIALIZED_MONGO_STORAGE_FACTORY = mongo_storage.MongoTestStorageF
16
17
  isCI: env.CI
17
18
  });
18
19
 
20
+ export const INITIALIZED_POSTGRES_STORAGE_FACTORY = postgres_storage.PostgresTestStorageFactoryGenerator({
21
+ url: env.PG_STORAGE_TEST_URL
22
+ });
23
+
19
24
  export async function clearTestDb(db: mongo.Db) {
20
25
  await db.dropDatabase();
21
26
  }