@powersync/service-module-mysql 0.12.1 → 0.12.3
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.
- package/CHANGELOG.md +19 -0
- package/dist/replication/BinLogReplicationJob.d.ts +1 -1
- package/dist/replication/BinLogReplicationJob.js +1 -1
- package/dist/replication/BinLogReplicationJob.js.map +1 -1
- package/dist/replication/BinLogReplicator.d.ts +0 -1
- package/dist/replication/BinLogReplicator.js +0 -22
- package/dist/replication/BinLogReplicator.js.map +1 -1
- package/dist/replication/BinLogStream.d.ts +3 -11
- package/dist/replication/BinLogStream.js +13 -32
- package/dist/replication/BinLogStream.js.map +1 -1
- package/package.json +7 -7
- package/src/replication/BinLogReplicationJob.ts +1 -1
- package/src/replication/BinLogReplicator.ts +0 -25
- package/src/replication/BinLogStream.ts +15 -31
- package/test/src/BinLogListener.test.ts +27 -20
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -13,7 +13,7 @@ import { getMySQLVersion, qualifiedMySQLTable, satisfiesVersion } from '@module/
|
|
|
13
13
|
import crypto from 'crypto';
|
|
14
14
|
import { TablePattern } from '@powersync/service-sync-rules';
|
|
15
15
|
|
|
16
|
-
describe('BinlogListener tests', () => {
|
|
16
|
+
describe('BinlogListener tests', { timeout: 60_000 }, () => {
|
|
17
17
|
const MAX_QUEUE_CAPACITY_MB = 1;
|
|
18
18
|
const BINLOG_LISTENER_CONNECTION_OPTIONS = {
|
|
19
19
|
...TEST_CONNECTION_OPTIONS,
|
|
@@ -73,14 +73,14 @@ describe('BinlogListener tests', () => {
|
|
|
73
73
|
await binLogListener.start();
|
|
74
74
|
|
|
75
75
|
// Wait for listener to stop due to queue reaching capacity
|
|
76
|
-
await vi.waitFor(() => expect(stopSpy).toHaveBeenCalled(), { timeout:
|
|
76
|
+
await vi.waitFor(() => expect(stopSpy).toHaveBeenCalled(), { timeout: 10_000 });
|
|
77
77
|
|
|
78
78
|
expect(binLogListener.isQueueOverCapacity()).toBeTruthy();
|
|
79
79
|
// Resume event processing
|
|
80
80
|
eventHandler.unpause!();
|
|
81
81
|
const restartSpy = vi.spyOn(binLogListener, 'start');
|
|
82
82
|
|
|
83
|
-
await vi.waitFor(() => expect(eventHandler.rowsWritten).equals(ROW_COUNT), { timeout:
|
|
83
|
+
await vi.waitFor(() => expect(eventHandler.rowsWritten).equals(ROW_COUNT), { timeout: 10_000 });
|
|
84
84
|
await binLogListener.stop();
|
|
85
85
|
// Confirm resume was called after unpausing
|
|
86
86
|
expect(restartSpy).toHaveBeenCalled();
|
|
@@ -106,7 +106,7 @@ describe('BinlogListener tests', () => {
|
|
|
106
106
|
test('Keepalive event', async () => {
|
|
107
107
|
binLogListener.options.keepAliveInactivitySeconds = 1;
|
|
108
108
|
await binLogListener.start();
|
|
109
|
-
await vi.waitFor(() => expect(eventHandler.lastKeepAlive).toBeDefined(), { timeout:
|
|
109
|
+
await vi.waitFor(() => expect(eventHandler.lastKeepAlive).toBeDefined(), { timeout: 10_000 });
|
|
110
110
|
await binLogListener.stop();
|
|
111
111
|
expect(eventHandler.lastKeepAlive).toEqual(binLogListener.options.startGTID.comparable);
|
|
112
112
|
});
|
|
@@ -114,7 +114,7 @@ describe('BinlogListener tests', () => {
|
|
|
114
114
|
test('Schema change event: Rename table', async () => {
|
|
115
115
|
await binLogListener.start();
|
|
116
116
|
await connectionManager.query(`ALTER TABLE test_DATA RENAME test_DATA_new`);
|
|
117
|
-
await
|
|
117
|
+
await waitForSchemaChanges(1);
|
|
118
118
|
await binLogListener.stop();
|
|
119
119
|
assertSchemaChange(
|
|
120
120
|
eventHandler.schemaChanges[0],
|
|
@@ -133,7 +133,7 @@ describe('BinlogListener tests', () => {
|
|
|
133
133
|
test_DATA TO test_DATA_new,
|
|
134
134
|
test_DATA_new TO test_DATA
|
|
135
135
|
`);
|
|
136
|
-
await
|
|
136
|
+
await waitForSchemaChanges(2);
|
|
137
137
|
await binLogListener.stop();
|
|
138
138
|
assertSchemaChange(
|
|
139
139
|
eventHandler.schemaChanges[0],
|
|
@@ -156,7 +156,7 @@ describe('BinlogListener tests', () => {
|
|
|
156
156
|
test('Schema change event: Truncate table', async () => {
|
|
157
157
|
await binLogListener.start();
|
|
158
158
|
await connectionManager.query(`TRUNCATE TABLE test_DATA`);
|
|
159
|
-
await
|
|
159
|
+
await waitForSchemaChanges(1);
|
|
160
160
|
await binLogListener.stop();
|
|
161
161
|
assertSchemaChange(
|
|
162
162
|
eventHandler.schemaChanges[0],
|
|
@@ -169,8 +169,7 @@ describe('BinlogListener tests', () => {
|
|
|
169
169
|
test('Schema change event: Drop table', async () => {
|
|
170
170
|
await binLogListener.start();
|
|
171
171
|
await connectionManager.query(`DROP TABLE test_DATA`);
|
|
172
|
-
await
|
|
173
|
-
await vi.waitFor(() => expect(eventHandler.schemaChanges.length).toBe(1), { timeout: 5000 });
|
|
172
|
+
await waitForSchemaChanges(1);
|
|
174
173
|
await binLogListener.stop();
|
|
175
174
|
assertSchemaChange(
|
|
176
175
|
eventHandler.schemaChanges[0],
|
|
@@ -183,7 +182,7 @@ describe('BinlogListener tests', () => {
|
|
|
183
182
|
test('Schema change event: Drop column', async () => {
|
|
184
183
|
await binLogListener.start();
|
|
185
184
|
await connectionManager.query(`ALTER TABLE test_DATA DROP COLUMN description`);
|
|
186
|
-
await
|
|
185
|
+
await waitForSchemaChanges(1);
|
|
187
186
|
await binLogListener.stop();
|
|
188
187
|
assertSchemaChange(
|
|
189
188
|
eventHandler.schemaChanges[0],
|
|
@@ -196,7 +195,7 @@ describe('BinlogListener tests', () => {
|
|
|
196
195
|
test('Schema change event: Add column', async () => {
|
|
197
196
|
await binLogListener.start();
|
|
198
197
|
await connectionManager.query(`ALTER TABLE test_DATA ADD COLUMN new_column VARCHAR(255)`);
|
|
199
|
-
await
|
|
198
|
+
await waitForSchemaChanges(1);
|
|
200
199
|
await binLogListener.stop();
|
|
201
200
|
assertSchemaChange(
|
|
202
201
|
eventHandler.schemaChanges[0],
|
|
@@ -209,7 +208,7 @@ describe('BinlogListener tests', () => {
|
|
|
209
208
|
test('Schema change event: Modify column', async () => {
|
|
210
209
|
await binLogListener.start();
|
|
211
210
|
await connectionManager.query(`ALTER TABLE test_DATA MODIFY COLUMN description TEXT`);
|
|
212
|
-
await
|
|
211
|
+
await waitForSchemaChanges(1);
|
|
213
212
|
await binLogListener.stop();
|
|
214
213
|
assertSchemaChange(
|
|
215
214
|
eventHandler.schemaChanges[0],
|
|
@@ -222,7 +221,7 @@ describe('BinlogListener tests', () => {
|
|
|
222
221
|
test('Schema change event: Rename column via change statement', async () => {
|
|
223
222
|
await binLogListener.start();
|
|
224
223
|
await connectionManager.query(`ALTER TABLE test_DATA CHANGE COLUMN description description_new MEDIUMTEXT`);
|
|
225
|
-
await
|
|
224
|
+
await waitForSchemaChanges(1);
|
|
226
225
|
await binLogListener.stop();
|
|
227
226
|
assertSchemaChange(
|
|
228
227
|
eventHandler.schemaChanges[0],
|
|
@@ -237,7 +236,7 @@ describe('BinlogListener tests', () => {
|
|
|
237
236
|
if (!isMySQL57) {
|
|
238
237
|
await binLogListener.start();
|
|
239
238
|
await connectionManager.query(`ALTER TABLE test_DATA RENAME COLUMN description TO description_new`);
|
|
240
|
-
await
|
|
239
|
+
await waitForSchemaChanges(1);
|
|
241
240
|
await binLogListener.stop();
|
|
242
241
|
assertSchemaChange(
|
|
243
242
|
eventHandler.schemaChanges[0],
|
|
@@ -254,7 +253,7 @@ describe('BinlogListener tests', () => {
|
|
|
254
253
|
await connectionManager.query(
|
|
255
254
|
`ALTER TABLE test_DATA DROP COLUMN description, ADD COLUMN new_description TEXT, MODIFY COLUMN id VARCHAR(50)`
|
|
256
255
|
);
|
|
257
|
-
await
|
|
256
|
+
await waitForSchemaChanges(3);
|
|
258
257
|
await binLogListener.stop();
|
|
259
258
|
assertSchemaChange(
|
|
260
259
|
eventHandler.schemaChanges[0],
|
|
@@ -289,7 +288,7 @@ describe('BinlogListener tests', () => {
|
|
|
289
288
|
await binLogListener.start();
|
|
290
289
|
await connectionManager.query(`ALTER TABLE test_constraints ADD PRIMARY KEY (id)`);
|
|
291
290
|
await connectionManager.query(`ALTER TABLE test_constraints DROP PRIMARY KEY`);
|
|
292
|
-
await
|
|
291
|
+
await waitForSchemaChanges(2);
|
|
293
292
|
await binLogListener.stop();
|
|
294
293
|
// Event for the add
|
|
295
294
|
assertSchemaChange(
|
|
@@ -318,7 +317,7 @@ describe('BinlogListener tests', () => {
|
|
|
318
317
|
await binLogListener.start();
|
|
319
318
|
await connectionManager.query(`ALTER TABLE test_constraints ADD UNIQUE (description)`);
|
|
320
319
|
await connectionManager.query(`ALTER TABLE test_constraints DROP INDEX description`);
|
|
321
|
-
await
|
|
320
|
+
await waitForSchemaChanges(2);
|
|
322
321
|
await binLogListener.stop();
|
|
323
322
|
// Event for the creation
|
|
324
323
|
assertSchemaChange(
|
|
@@ -347,7 +346,7 @@ describe('BinlogListener tests', () => {
|
|
|
347
346
|
await binLogListener.start();
|
|
348
347
|
await connectionManager.query(`CREATE UNIQUE INDEX description_idx ON test_constraints (description)`);
|
|
349
348
|
await connectionManager.query(`DROP INDEX description_idx ON test_constraints`);
|
|
350
|
-
await
|
|
349
|
+
await waitForSchemaChanges(2);
|
|
351
350
|
await binLogListener.stop();
|
|
352
351
|
// Event for the creation
|
|
353
352
|
assertSchemaChange(
|
|
@@ -398,7 +397,7 @@ describe('BinlogListener tests', () => {
|
|
|
398
397
|
|
|
399
398
|
await binLogListener.start();
|
|
400
399
|
|
|
401
|
-
await
|
|
400
|
+
await waitForSchemaChanges(4);
|
|
402
401
|
await binLogListener.stop();
|
|
403
402
|
expect(eventHandler.schemaChanges[0].type).toBe(SchemaChangeType.ALTER_TABLE_COLUMN);
|
|
404
403
|
expect(eventHandler.schemaChanges[1].type).toBe(SchemaChangeType.REPLICATION_IDENTITY);
|
|
@@ -466,12 +465,20 @@ describe('BinlogListener tests', () => {
|
|
|
466
465
|
await connectionManager.query(`INSERT INTO ${testTable}(id, description) VALUES('${uuid()}','test')`);
|
|
467
466
|
await connectionManager.query(`DROP TABLE ${testTable}`);
|
|
468
467
|
|
|
469
|
-
await
|
|
468
|
+
await waitForSchemaChanges(1);
|
|
470
469
|
await binLogListener.stop();
|
|
471
470
|
expect(eventHandler.rowsWritten).toBe(2);
|
|
472
471
|
assertSchemaChange(eventHandler.schemaChanges[0], SchemaChangeType.DROP_TABLE, 'multi_schema', 'test_DATA_multi');
|
|
473
472
|
});
|
|
474
473
|
|
|
474
|
+
async function waitForSchemaChanges(count: number) {
|
|
475
|
+
try {
|
|
476
|
+
await vi.waitFor(() => expect(eventHandler.schemaChanges.length).equals(count), { timeout: 30_000 });
|
|
477
|
+
} catch (error) {
|
|
478
|
+
throw new Error(`Timeout while waiting for [${count}] schema changes.`);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
475
482
|
function assertSchemaChange(
|
|
476
483
|
change: SchemaChange,
|
|
477
484
|
type: SchemaChangeType,
|