Skip to content
Merged
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
10 changes: 10 additions & 0 deletions packages/pic/src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ export class TopologyValidationError extends Error {
}
}

export class InvalidTtlError extends Error {
override name = 'InvalidTtlError';

constructor(ttl: number) {
super(
`Invalid ttl value ${ttl}. The ttl must be a non-negative integer representing seconds.`,
);
}
}

export class RetryableError extends Error {
override name: string = 'RetryableError';
}
Expand Down
8 changes: 8 additions & 0 deletions packages/pic/src/pocket-ic-server-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ export interface StartServerOptions {
* otherwise the binary downloaded by this package's install script.
*/
binPath?: string;

/**
* Time to live of the server in seconds since the last completed operation,
* after which the server shuts down gracefully.
* Must be a non-negative integer.
* If not provided, the server's default time to live is used.
*/
ttl?: number;
}
12 changes: 11 additions & 1 deletion packages/pic/src/pocket-ic-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BinStartError,
BinStartMacOSArmError,
BinTimeoutError,
InvalidTtlError,
} from './error';
import {
exists,
Expand Down Expand Up @@ -70,7 +71,16 @@ export class PocketIcServer {
const picFilePrefix = `pocket_ic_${pid}`;
const portFilePath = tmpFile(`${picFilePrefix}.port`);

const serverProcess = spawn(binPath, ['--port-file', portFilePath]);
const serverArgs = ['--port-file', portFilePath];
if (options.ttl !== undefined) {
if (!Number.isInteger(options.ttl) || options.ttl < 0) {
throw new InvalidTtlError(options.ttl);
}

serverArgs.push('--ttl', options.ttl.toString());
}

const serverProcess = spawn(binPath, serverArgs);
Comment thread
Kamirus marked this conversation as resolved.

if (options.showRuntimeLogs) {
serverProcess.stdout.pipe(process.stdout);
Expand Down
Loading