refactor(server): use Duration for bootstrap timeout
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
f8bf1b3c7a
commit
de238add41
2 files changed
+15
-10
No files matched your search
@@ -74,7 +74,9 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
(fd) => Effect.sync(() => NodeFS.closeSync(fd)),
|
||||
);
|
||||
|
||||
const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { timeoutMs: 100 });
|
||||
const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeout: Duration.millis(100),
|
||||
});
|
||||
assertSome(payload, {
|
||||
mode: "desktop",
|
||||
});
|
||||
@@ -100,7 +102,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
openSyncInterceptor.failPath = `/proc/self/fd/${fd}`;
|
||||
try {
|
||||
const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeoutMs: 100,
|
||||
timeout: Duration.millis(100),
|
||||
}).pipe(Effect.provideService(HostProcessPlatform, "linux"));
|
||||
assertSome(payload, {
|
||||
mode: "desktop",
|
||||
@@ -125,7 +127,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
openSyncInterceptor.errorCode = "EIO";
|
||||
try {
|
||||
const error = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeoutMs: 100,
|
||||
timeout: Duration.millis(100),
|
||||
}).pipe(Effect.provideService(HostProcessPlatform, "linux"), Effect.flip);
|
||||
|
||||
assert.instanceOf(error, BootstrapInputStreamOpenError);
|
||||
@@ -149,7 +151,9 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
const fd = NodeFS.openSync("/dev/null", "r");
|
||||
NodeFS.closeSync(fd);
|
||||
|
||||
const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, { timeoutMs: 100 });
|
||||
const payload = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeout: Duration.millis(100),
|
||||
});
|
||||
assertNone(payload);
|
||||
}),
|
||||
);
|
||||
@@ -164,7 +168,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
fstatSyncInterceptor.failFd = fd;
|
||||
try {
|
||||
const error = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeoutMs: 100,
|
||||
timeout: Duration.millis(100),
|
||||
}).pipe(Effect.flip);
|
||||
|
||||
assert.instanceOf(error, BootstrapFdStatError);
|
||||
@@ -188,7 +192,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
(fd) => Effect.sync(() => NodeFS.closeSync(fd)),
|
||||
);
|
||||
const error = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeoutMs: 100,
|
||||
timeout: Duration.millis(100),
|
||||
}).pipe(Effect.flip);
|
||||
|
||||
assert.instanceOf(error, BootstrapEnvelopeDecodeError);
|
||||
@@ -227,7 +231,7 @@ it.layer(NodeServices.layer)("readBootstrapEnvelope", (it) => {
|
||||
);
|
||||
|
||||
const fiber = yield* readBootstrapEnvelope(TestEnvelopeSchema, fd, {
|
||||
timeoutMs: 100,
|
||||
timeout: Duration.millis(100),
|
||||
}).pipe(Effect.forkScoped);
|
||||
|
||||
yield* Effect.yieldNow;
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as NodeNet from "node:net";
|
||||
import * as NodeReadline from "node:readline";
|
||||
import type * as NodeStream from "node:stream";
|
||||
|
||||
import * as Duration from "effect/Duration";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
import * as Predicate from "effect/Predicate";
|
||||
@@ -75,7 +76,7 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function
|
||||
schema: Schema.Codec<A, I>,
|
||||
fd: number,
|
||||
options?: {
|
||||
timeoutMs?: number;
|
||||
readonly timeout?: Duration.Duration;
|
||||
},
|
||||
): Effect.fn.Return<Option.Option<A>, BootstrapError> {
|
||||
const fdReady = yield* isFdReady(fd);
|
||||
@@ -83,7 +84,7 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function
|
||||
|
||||
const stream = yield* makeBootstrapInputStream(fd);
|
||||
|
||||
const timeoutMs = options?.timeoutMs ?? 1000;
|
||||
const timeout = options?.timeout ?? Duration.seconds(1);
|
||||
|
||||
return yield* Effect.callback<
|
||||
Option.Option<A>,
|
||||
@@ -142,7 +143,7 @@ export const readBootstrapEnvelope = Effect.fn("readBootstrapEnvelope")(function
|
||||
input.once("close", handleClose);
|
||||
|
||||
return Effect.sync(cleanup);
|
||||
}).pipe(Effect.timeoutOption(timeoutMs), Effect.map(Option.flatten));
|
||||
}).pipe(Effect.timeoutOption(timeout), Effect.map(Option.flatten));
|
||||
});
|
||||
|
||||
const isUnavailableBootstrapFdError = Predicate.compose(
|
||||
|
||||
Reference in new issue
Block a user