1- import { ReplicationMetricType , storage } from '@powersync/service-core' ;
1+ import { storage } from '@powersync/service-core' ;
22import { METRICS_HELPER , putOp , removeOp } from '@powersync/service-core-tests' ;
33import { v4 as uuid } from 'uuid' ;
44import { describe , expect , test } from 'vitest' ;
55import { BinlogStreamTestContext } from './BinlogStreamUtils.js' ;
66import { env } from './env.js' ;
77import { INITIALIZED_MONGO_STORAGE_FACTORY , INITIALIZED_POSTGRES_STORAGE_FACTORY } from './util.js' ;
8+ import { ReplicationMetric } from '@powersync/service-types' ;
89
910const BASIC_SYNC_RULES = `
1011bucket_definitions:
@@ -35,10 +36,9 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
3536
3637 await context . replicateSnapshot ( ) ;
3738
38- const startRowCount =
39- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
39+ const startRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
4040 const startTxCount =
41- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
41+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
4242
4343 context . startStreaming ( ) ;
4444 const testId = uuid ( ) ;
@@ -48,9 +48,9 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
4848 const data = await context . getBucketData ( 'global[]' ) ;
4949
5050 expect ( data ) . toMatchObject ( [ putOp ( 'test_data' , { id : testId , description : 'test1' , num : 1152921504606846976n } ) ] ) ;
51- const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
51+ const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
5252 const endTxCount =
53- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
53+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
5454 expect ( endRowCount - startRowCount ) . toEqual ( 1 ) ;
5555 expect ( endTxCount - startTxCount ) . toEqual ( 1 ) ;
5656 } ) ;
@@ -69,10 +69,9 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
6969
7070 await context . replicateSnapshot ( ) ;
7171
72- const startRowCount =
73- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
72+ const startRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
7473 const startTxCount =
75- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
74+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
7675
7776 context . startStreaming ( ) ;
7877
@@ -82,9 +81,9 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
8281 const data = await context . getBucketData ( 'global[]' ) ;
8382
8483 expect ( data ) . toMatchObject ( [ putOp ( 'test_DATA' , { id : testId , description : 'test1' } ) ] ) ;
85- const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
84+ const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
8685 const endTxCount =
87- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
86+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
8887 expect ( endRowCount - startRowCount ) . toEqual ( 1 ) ;
8988 expect ( endTxCount - startTxCount ) . toEqual ( 1 ) ;
9089 } ) ;
@@ -174,12 +173,11 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
174173 const testId = uuid ( ) ;
175174 await connectionManager . query ( `INSERT INTO test_data(id, description) VALUES('${ testId } ','test1')` ) ;
176175
177- const startRowCount =
178- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
176+ const startRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
179177
180178 await context . replicateSnapshot ( ) ;
181179
182- const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
180+ const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
183181 const data = await context . getBucketData ( 'global[]' ) ;
184182 expect ( data ) . toMatchObject ( [ putOp ( 'test_data' , { id : testId , description : 'test1' } ) ] ) ;
185183 expect ( endRowCount - startRowCount ) . toEqual ( 1 ) ;
@@ -234,10 +232,9 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
234232
235233 await context . replicateSnapshot ( ) ;
236234
237- const startRowCount =
238- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
235+ const startRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
239236 const startTxCount =
240- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
237+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
241238
242239 context . startStreaming ( ) ;
243240
@@ -264,9 +261,9 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
264261 timestamp : '2023-03-06T15:47:00.000Z'
265262 } )
266263 ] ) ;
267- const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
264+ const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
268265 const endTxCount =
269- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
266+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
270267 expect ( endRowCount - startRowCount ) . toEqual ( 2 ) ;
271268 expect ( endTxCount - startTxCount ) . toEqual ( 2 ) ;
272269 } ) ;
@@ -280,20 +277,19 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
280277
281278 await context . replicateSnapshot ( ) ;
282279
283- const startRowCount =
284- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
280+ const startRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
285281 const startTxCount =
286- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
282+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
287283
288284 context . startStreaming ( ) ;
289285
290286 await connectionManager . query ( `INSERT INTO test_donotsync(id, description) VALUES('${ uuid ( ) } ','test1')` ) ;
291287 const data = await context . getBucketData ( 'global[]' ) ;
292288
293289 expect ( data ) . toMatchObject ( [ ] ) ;
294- const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
290+ const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
295291 const endTxCount =
296- ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
292+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetric . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
297293
298294 // There was a transaction, but we should not replicate any actual data
299295 expect ( endRowCount - startRowCount ) . toEqual ( 0 ) ;
0 commit comments