Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/skip-test-connection-replication-metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/service-module-postgres': patch
---

Skip the PostgreSQL replication-byte metrics recorder in `test-connection` mode so the command can run without `DATA_REPLICATED_BYTES`.
2 changes: 1 addition & 1 deletion modules/module-postgres/src/module/PostgresModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class PostgresModule extends replication.ReplicationModule<types.Postgres

async onInitialized(context: system.ServiceContextContainer): Promise<void> {
// Record replicated bytes using global jpgwire metrics. Only registered if this module is replicating
if (context.replicationEngine) {
if (context.replicationEngine && context.serviceMode !== system.ServiceContextMode.TEST_CONNECTION) {
jpgwire.setMetricsRecorder({
addBytesRead(bytes) {
context.metricsEngine.getCounter(ReplicationMetric.DATA_REPLICATED_BYTES).add(bytes);
Expand Down
40 changes: 40 additions & 0 deletions modules/module-postgres/test/src/metrics_recorder.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { system } from '@powersync/service-core';
import * as jpgwire from '@powersync/service-jpgwire';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { PostgresModule } from '../../src/module/PostgresModule.js';

describe('PostgresModule metrics recorder', () => {
afterEach(() => {
vi.restoreAllMocks();
});

it('does not install a jpgwire recorder in TEST_CONNECTION mode', async () => {
const spy = vi.spyOn(jpgwire, 'setMetricsRecorder');
const mod = new PostgresModule();
await mod.onInitialized({
replicationEngine: {},
serviceMode: system.ServiceContextMode.TEST_CONNECTION,
metricsEngine: {
getCounter() {
throw new Error('DATA_REPLICATED_BYTES should not be read in test-connection');
}
}
} as unknown as system.ServiceContextContainer);

expect(spy).not.toHaveBeenCalled();
});

it('installs a jpgwire recorder when replication metrics are available', async () => {
const spy = vi.spyOn(jpgwire, 'setMetricsRecorder');
const mod = new PostgresModule();
await mod.onInitialized({
replicationEngine: {},
serviceMode: system.ServiceContextMode.UNIFIED,
metricsEngine: {
getCounter: () => ({ add() {} })
}
} as unknown as system.ServiceContextContainer);

expect(spy).toHaveBeenCalledTimes(1);
});
});
Loading