1- import { Metrics , storage } from '@powersync/service-core' ;
2- import { putOp , removeOp } from '@powersync/service-core-tests' ;
1+ import { ReplicationMetricType , storage } from '@powersync/service-core' ;
2+ import { 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' ;
@@ -35,9 +35,10 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
3535
3636 await context . replicateSnapshot ( ) ;
3737
38- const startRowCount = ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_rows_replicated_total' ) ) ?? 0 ;
38+ const startRowCount =
39+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
3940 const startTxCount =
40- ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_transactions_replicated_total' ) ) ?? 0 ;
41+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
4142
4243 context . startStreaming ( ) ;
4344 const testId = uuid ( ) ;
@@ -47,9 +48,9 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
4748 const data = await context . getBucketData ( 'global[]' ) ;
4849
4950 expect ( data ) . toMatchObject ( [ putOp ( 'test_data' , { id : testId , description : 'test1' , num : 1152921504606846976n } ) ] ) ;
50- const endRowCount = ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_rows_replicated_total' ) ) ?? 0 ;
51+ const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
5152 const endTxCount =
52- ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_transactions_replicated_total' ) ) ?? 0 ;
53+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
5354 expect ( endRowCount - startRowCount ) . toEqual ( 1 ) ;
5455 expect ( endTxCount - startTxCount ) . toEqual ( 1 ) ;
5556 } ) ;
@@ -68,9 +69,10 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
6869
6970 await context . replicateSnapshot ( ) ;
7071
71- const startRowCount = ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_rows_replicated_total' ) ) ?? 0 ;
72+ const startRowCount =
73+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
7274 const startTxCount =
73- ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_transactions_replicated_total' ) ) ?? 0 ;
75+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
7476
7577 context . startStreaming ( ) ;
7678
@@ -80,9 +82,9 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
8082 const data = await context . getBucketData ( 'global[]' ) ;
8183
8284 expect ( data ) . toMatchObject ( [ putOp ( 'test_DATA' , { id : testId , description : 'test1' } ) ] ) ;
83- const endRowCount = ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_rows_replicated_total' ) ) ?? 0 ;
85+ const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
8486 const endTxCount =
85- ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_transactions_replicated_total' ) ) ?? 0 ;
87+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
8688 expect ( endRowCount - startRowCount ) . toEqual ( 1 ) ;
8789 expect ( endTxCount - startTxCount ) . toEqual ( 1 ) ;
8890 } ) ;
@@ -172,10 +174,15 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
172174 const testId = uuid ( ) ;
173175 await connectionManager . query ( `INSERT INTO test_data(id, description) VALUES('${ testId } ','test1')` ) ;
174176
177+ const startRowCount =
178+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
179+
175180 await context . replicateSnapshot ( ) ;
176181
182+ const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
177183 const data = await context . getBucketData ( 'global[]' ) ;
178184 expect ( data ) . toMatchObject ( [ putOp ( 'test_data' , { id : testId , description : 'test1' } ) ] ) ;
185+ expect ( endRowCount - startRowCount ) . toEqual ( 1 ) ;
179186 } ) ;
180187
181188 test ( 'snapshot with date values' , async ( ) => {
@@ -227,9 +234,10 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
227234
228235 await context . replicateSnapshot ( ) ;
229236
230- const startRowCount = ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_rows_replicated_total' ) ) ?? 0 ;
237+ const startRowCount =
238+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
231239 const startTxCount =
232- ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_transactions_replicated_total' ) ) ?? 0 ;
240+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
233241
234242 context . startStreaming ( ) ;
235243
@@ -256,9 +264,9 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
256264 timestamp : '2023-03-06T15:47:00.000Z'
257265 } )
258266 ] ) ;
259- const endRowCount = ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_rows_replicated_total' ) ) ?? 0 ;
267+ const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
260268 const endTxCount =
261- ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_transactions_replicated_total' ) ) ?? 0 ;
269+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
262270 expect ( endRowCount - startRowCount ) . toEqual ( 2 ) ;
263271 expect ( endTxCount - startTxCount ) . toEqual ( 2 ) ;
264272 } ) ;
@@ -272,19 +280,20 @@ function defineBinlogStreamTests(factory: storage.TestStorageFactory) {
272280
273281 await context . replicateSnapshot ( ) ;
274282
275- const startRowCount = ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_rows_replicated_total' ) ) ?? 0 ;
283+ const startRowCount =
284+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
276285 const startTxCount =
277- ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_transactions_replicated_total' ) ) ?? 0 ;
286+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
278287
279288 context . startStreaming ( ) ;
280289
281290 await connectionManager . query ( `INSERT INTO test_donotsync(id, description) VALUES('${ uuid ( ) } ','test1')` ) ;
282291 const data = await context . getBucketData ( 'global[]' ) ;
283292
284293 expect ( data ) . toMatchObject ( [ ] ) ;
285- const endRowCount = ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_rows_replicated_total' ) ) ?? 0 ;
294+ const endRowCount = ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . ROWS_REPLICATED_TOTAL ) ) ?? 0 ;
286295 const endTxCount =
287- ( await Metrics . getInstance ( ) . getMetricValueForTests ( 'powersync_transactions_replicated_total' ) ) ?? 0 ;
296+ ( await METRICS_HELPER . getMetricValueForTests ( ReplicationMetricType . TRANSACTIONS_REPLICATED_TOTAL ) ) ?? 0 ;
288297
289298 // There was a transaction, but we should not replicate any actual data
290299 expect ( endRowCount - startRowCount ) . toEqual ( 0 ) ;
0 commit comments