feat(ipcclient): Add clientOnly mode to prevent clients from auto-starting servers and improve registration/reconnect behavior

This commit is contained in:
2025-08-29 08:48:38 +00:00
parent fd3fc7518b
commit fa53dcfc4f
8 changed files with 178 additions and 40 deletions

View File

@@ -2,6 +2,10 @@ import { expect, tap } from '@git.zone/tstest/tapbundle';
import * as smartipc from '../ts/index.js';
import * as smartdelay from '@push.rocks/smartdelay';
import * as smartpromise from '@push.rocks/smartpromise';
import * as path from 'path';
import * as os from 'os';
const testSocketPath = path.join(os.tmpdir(), `test-smartipc-${Date.now()}.sock`);
let server: smartipc.IpcServer;
let client1: smartipc.IpcClient;
@@ -11,12 +15,13 @@ let client2: smartipc.IpcClient;
tap.test('should create and start an IPC server', async () => {
server = smartipc.SmartIpc.createServer({
id: 'test-server',
socketPath: '/tmp/test-smartipc.sock',
socketPath: testSocketPath,
autoCleanupSocketFile: true,
heartbeat: true,
heartbeatInterval: 2000
});
await server.start();
await server.start({ readyWhen: 'accepting' });
expect(server.getStats().isRunning).toBeTrue();
});
@@ -24,11 +29,12 @@ tap.test('should create and start an IPC server', async () => {
tap.test('should create and connect a client', async () => {
client1 = smartipc.SmartIpc.createClient({
id: 'test-server',
socketPath: '/tmp/test-smartipc.sock',
socketPath: testSocketPath,
clientId: 'client-1',
metadata: { name: 'Test Client 1' },
autoReconnect: true,
heartbeat: true
heartbeat: true,
clientOnly: true
});
await client1.connect();
@@ -76,9 +82,10 @@ tap.test('should handle request/response pattern', async () => {
tap.test('should handle multiple clients', async () => {
client2 = smartipc.SmartIpc.createClient({
id: 'test-server',
socketPath: '/tmp/test-smartipc.sock',
socketPath: testSocketPath,
clientId: 'client-2',
metadata: { name: 'Test Client 2' }
metadata: { name: 'Test Client 2' },
clientOnly: true
});
await client2.connect();
@@ -296,4 +303,4 @@ tap.test('should cleanup and close all connections', async () => {
expect(client1.getIsConnected()).toBeFalse();
});
export default tap.start();
export default tap.start();