-
Notifications
You must be signed in to change notification settings - Fork 526
fix(stack): include recent service output in startup failure errors #6791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+244
−43
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a1b83c2
fix(stack): include recent service output in startup failure errors
avallete b8ee477
Merge remote-tracking branch 'origin/develop' into avallete/startup-f…
avallete 86b2e37
fix(stack): keep separate bounded stdout and stderr startup tails
avallete 6fa6ad3
fix(stack): avoid splitting surrogate pairs when clipping startup output
avallete d5cf676
Merge branch 'develop' into avallete/startup-failure-output-08dd39
avallete 335be8a
Merge remote-tracking branch 'origin/develop' into avallete/startup-f…
avallete 559d360
test(stack): implement prepareImage in the startup container fixture
avallete 4de0ef2
Merge remote-tracking branch 'origin/avallete/startup-failure-output-…
avallete File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
packages/stack/src/services/ProcessRecipe.integration.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| import { NodeHttpClient, NodeServices } from "@effect/platform-node"; | ||
| import { describe, expect, it } from "@effect/vitest"; | ||
| import { Crypto, Deferred, Effect, Fiber, FileSystem, Layer, Path, Sink, Stream } from "effect"; | ||
| import { TestClock } from "effect/testing"; | ||
| import { HttpClient } from "effect/unstable/http"; | ||
| import { ChildProcessSpawner } from "effect/unstable/process"; | ||
| import type { ContainerRuntime } from "../runtime/Container.ts"; | ||
| import { makeService } from "../Service.ts"; | ||
| import { makeProcessRecipe } from "./ProcessRecipe.ts"; | ||
| import * as Realtime from "./Realtime.ts"; | ||
|
|
||
| const encode = (text: string) => new TextEncoder().encode(text); | ||
|
|
||
| const poolTimeout = | ||
| "** (DBConnection.ConnectionError) connection not available and request was dropped from queue"; | ||
|
|
||
| const postgrexFailure = | ||
| '[error] Postgrex.Protocol ("db_conn_1") failed to connect: ** (DBConnection.ConnectionError) tcp connect (host.docker.internal:54322): network is unreachable - :enetunreach'; | ||
|
|
||
| const startupContainer = (tool: { | ||
| readonly stdout: Stream.Stream<string>; | ||
| readonly stderr: Stream.Stream<string>; | ||
| readonly exitCode: Effect.Effect<number>; | ||
| }): ContainerRuntime => ({ | ||
| prepare: () => Effect.void, | ||
| prepareImage: (image) => Effect.succeed(image), | ||
| launch: () => Effect.die("the main process must not launch after a failed startup"), | ||
| launchTool: () => | ||
| Effect.succeed({ | ||
| id: "startup-tool", | ||
| ports: {}, | ||
| stdout: tool.stdout.pipe(Stream.map(encode)), | ||
| stderr: tool.stderr.pipe(Stream.map(encode)), | ||
| exitCode: tool.exitCode, | ||
| stdin: Sink.drain, | ||
| stop: Effect.void, | ||
| discard: Effect.void, | ||
| kill: Effect.void, | ||
| remove: Effect.void, | ||
| }), | ||
| }); | ||
|
|
||
| const realtimeService = Effect.fn(function* (container: ContainerRuntime) { | ||
| const creation: Realtime.Creation = { | ||
| service: "realtime", | ||
| config: { databaseUrl: "postgresql://postgres:postgres@host.docker.internal:54322/postgres" }, | ||
| }; | ||
| const recipe = yield* makeProcessRecipe( | ||
| creation, | ||
| { | ||
| stackId: "process-recipe-test", | ||
| instanceId: "instance", | ||
| root: "/unused", | ||
| cacheRoot: "/unused/cache", | ||
| runtime: "docker", | ||
| }, | ||
| { | ||
| fs: yield* FileSystem.FileSystem, | ||
| path: yield* Path.Path, | ||
| crypto: yield* Crypto.Crypto, | ||
| client: yield* HttpClient.HttpClient, | ||
| spawner: yield* ChildProcessSpawner.ChildProcessSpawner, | ||
| container, | ||
| }, | ||
| Realtime.makeSpec(), | ||
| ); | ||
| return yield* makeService(recipe.definition, { id: "realtime", config: creation }); | ||
| }); | ||
|
|
||
| const platform = Layer.merge(NodeServices.layer, NodeHttpClient.layerNodeHttp); | ||
|
|
||
| describe("process recipe startup", () => { | ||
| it.effect("reports the startup process's recent stdout and stderr when it exits non-zero", () => | ||
| Effect.scoped( | ||
| Effect.gen(function* () { | ||
| const realtime = yield* realtimeService( | ||
| startupContainer({ | ||
| stdout: Stream.make( | ||
| "[info] Running migrations\n", | ||
| postgrexFailure.slice(0, 60), | ||
| `${postgrexFailure.slice(60)}\n`, | ||
| ), | ||
| stderr: Stream.make(`${poolTimeout}\n`), | ||
| exitCode: Effect.succeed(1), | ||
| }), | ||
| ); | ||
|
|
||
| const error = yield* Effect.flip(realtime.start); | ||
|
|
||
| expect(error.message).toContain("realtime startup exited with 1"); | ||
| expect(error.message).toContain(postgrexFailure); | ||
| expect(error.message).toContain(poolTimeout); | ||
| }), | ||
| ).pipe(Effect.provide(platform)), | ||
| ); | ||
|
|
||
| it.effect("keeps the stderr error when later stdout exceeds the tail", () => | ||
| Effect.scoped( | ||
| Effect.gen(function* () { | ||
| const stderrWritten = yield* Deferred.make<void>(); | ||
| const noise = Array.from({ length: 30 }, (_, index) => `[info] shutdown step ${index}\n`); | ||
| const realtime = yield* realtimeService( | ||
| startupContainer({ | ||
| stdout: Stream.fromEffectDrain(Deferred.await(stderrWritten)).pipe( | ||
| Stream.concat(Stream.fromIterable(noise)), | ||
| ), | ||
| stderr: Stream.make(`${poolTimeout}\n`).pipe( | ||
| Stream.concat(Stream.fromEffectDrain(Deferred.succeed(stderrWritten, undefined))), | ||
| ), | ||
| exitCode: Effect.succeed(1), | ||
| }), | ||
| ); | ||
|
|
||
| const error = yield* Effect.flip(realtime.start); | ||
|
|
||
| expect(error.message).toContain(poolTimeout); | ||
| expect(error.message).toContain("[info] shutdown step 29"); | ||
| expect(error.message).not.toContain("[info] shutdown step 9\n"); | ||
| }), | ||
| ).pipe(Effect.provide(platform)), | ||
| ); | ||
|
|
||
| it.effect( | ||
| "reports the startup process's recent output, including an unterminated line, when it never exits", | ||
| () => | ||
| Effect.scoped( | ||
| Effect.gen(function* () { | ||
| const running = yield* Deferred.make<void>(); | ||
| const realtime = yield* realtimeService( | ||
| startupContainer({ | ||
| stdout: Stream.make( | ||
| `${postgrexFailure}\n`, | ||
| "[info] ", | ||
| "😀".repeat(2_500), | ||
| " Retrying database connection", | ||
| ).pipe( | ||
| Stream.concat(Stream.fromEffectDrain(Deferred.succeed(running, undefined))), | ||
| Stream.concat(Stream.never), | ||
| ), | ||
| stderr: Stream.never, | ||
| exitCode: Effect.never, | ||
| }), | ||
| ); | ||
|
|
||
| const failure = yield* realtime.start.pipe(Effect.flip, Effect.forkChild); | ||
| yield* Deferred.await(running); | ||
| yield* Effect.yieldNow; | ||
| yield* TestClock.adjust("60 seconds"); | ||
| const error = yield* Fiber.join(failure); | ||
|
|
||
| expect(error.message).toContain("realtime startup timed out after 60 seconds"); | ||
| expect(error.message).toContain(postgrexFailure); | ||
| expect(error.message).toContain("😀 Retrying database connection"); | ||
| expect(error.message).not.toContain("[info] 😀"); | ||
| expect(error.message).not.toMatch(/…[\uDC00-\uDFFF]/); | ||
| expect(error.message.length).toBeLessThan(2_000); | ||
| }), | ||
| ).pipe(Effect.provide(platform)), | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.