-
Notifications
You must be signed in to change notification settings - Fork 196
chore(tests): add LMI e2e suite and run-scoped shared capacity provider #5465
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
Open
svozza
wants to merge
23
commits into
main
Choose a base branch
from
feat/lmi-e2e-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4f0a8f2
chore(tests): add e2e test for logger InvokeStore isolation on Lambda…
svozza a308964
chore(tests): capture LMI e2e logs via stdout interception instead of…
svozza cae8d13
chore(tests): run LMI e2e suite unconditionally and filter captured l…
svozza f54675d
chore(tests): raise vitest worker cap for logger e2e runs
svozza 9970bc1
Revert "chore(tests): raise vitest worker cap for logger e2e runs"
svozza 87d71f4
chore(tests): add run-scoped shared LMI capacity provider CLI
svozza 6783759
fix(tests): validate LMI CLI run-id to prevent path traversal
svozza b5e9d4d
fix(tests): validate constructed assembly path stays within tmpdir
svozza e70faea
refactor(tests): extract LMI capacity-provider attachment helpers
svozza d4d4306
refactor(tests): replace LMI CLI with TestStack-based workflow scripts
svozza 813e50e
refactor(tests): run LMI e2e suites in a dedicated job gated on the s…
svozza d8199a3
refactor(tests): deploy and destroy LMI capacity provider stacks conc…
svozza b87de6a
refactor(tests): pass architecture explicitly instead of mutating pro…
svozza 3ba1f85
fix(tests): disambiguate architectures in shared capacity provider pr…
svozza 90752a7
chore(tests): add phase markers to LMI e2e suite output
svozza f2b3c0f
docs(tests): clarify retry semantics for LMI vs non-LMI e2e jobs
svozza ed214b5
chore(tests): invoke LMI capacity provider scripts via npm scripts
svozza f7ca73d
fix(tests): opt out of clobberEnv to make concurrent CDK synths safe
svozza ba28594
fix(tests): sweep orphaned LMI function stacks before deleting providers
svozza c07bee8
fix(tests): set publishToLatestPublished on the construct attach path
svozza b40b226
refactor(tests): drop unused includeTailLogs invoke option
svozza 7894356
chore(tests): fix logger e2e SDK dependencies
svozza e0d809c
fix(tests): log the real stack name in deploy/destroy progress
svozza 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,79 @@ | ||
| import { randomUUID } from 'node:crypto'; | ||
| import { setTimeout } from 'node:timers/promises'; | ||
| import { Logger } from '@aws-lambda-powertools/logger'; | ||
| import type { Context } from 'aws-lambda'; | ||
|
|
||
| // Module scope: identifies the execution environment across invocations | ||
| const executionEnvId = randomUUID(); | ||
|
|
||
| // Capture the log lines the Logger emits so they can be returned in the | ||
| // response payload: on LMI the Invoke API does not support Tail logs and | ||
| // CloudWatch delivery is asynchronous, so returning the logs is the only | ||
| // fully deterministic way for the test to read them. In production mode the | ||
| // Logger writes each log line as a single atomic write to process.stdout | ||
| // (via its own Console instance, bypassing Lambda's patched global console), | ||
| // so intercepting the stream captures the real production write path. | ||
| const capturedLogs: Array<Record<string, unknown>> = []; | ||
| const originalWrite = process.stdout.write.bind(process.stdout); | ||
| process.stdout.write = ((chunk: string | Uint8Array, ...rest: unknown[]) => { | ||
| try { | ||
| capturedLogs.push(JSON.parse(chunk.toString())); | ||
| } catch { | ||
| // not a JSON log line, ignore | ||
| } | ||
| // @ts-expect-error - passing through the remaining overloaded args as-is | ||
| return originalWrite(chunk, ...rest); | ||
| }) as typeof process.stdout.write; | ||
|
|
||
| const logger = new Logger(); | ||
|
|
||
| // Invocations multiplexed into the same execution environment share this | ||
| // module-scoped state, which lets us prove a genuine overlap: every | ||
| // invocation blocks until a second invocation is in flight in the same | ||
| // environment (or times out reporting that it stayed alone) | ||
| let inFlight = 0; | ||
| let barrier = Promise.withResolvers<void>(); | ||
|
|
||
| export const handler = async ( | ||
| event: { invocationId: string; role: 'warmup' | 'test' }, | ||
| context: Context | ||
| ) => { | ||
| logger.addContext(context); | ||
| logger.appendKeys({ invocationKey: event.invocationId }); | ||
|
|
||
| let sawPeer = false; | ||
| if (event.role === 'test') { | ||
| inFlight++; | ||
| if (inFlight >= 2) { | ||
| barrier.resolve(); | ||
| } | ||
| sawPeer = await Promise.race([ | ||
| barrier.promise.then(() => true), | ||
| setTimeout(15_000, false), | ||
| ]); | ||
| inFlight--; | ||
| if (inFlight === 0) { | ||
| barrier = Promise.withResolvers<void>(); | ||
| } | ||
| } | ||
|
|
||
| logger.info('LMI isolation test'); | ||
| logger.resetKeys(); | ||
|
|
||
| return { | ||
| invocationId: event.invocationId, | ||
| executionEnvId, | ||
| sawPeer, | ||
| initializationType: process.env.AWS_LAMBDA_INITIALIZATION_TYPE ?? 'unset', | ||
| maxConcurrency: process.env.AWS_LAMBDA_MAX_CONCURRENCY ?? 'unset', | ||
| // Only the lines this invocation emitted, selected by the request id | ||
| // stamped on them. Under LMI multiplexing this only works because | ||
| // addContext scopes the lambda context per invocation via the | ||
| // InvokeStore (#5430) — an empty logs array here is the signature of | ||
| // that scoping regressing. The invocationKey assertion in the test | ||
| // then verifies appendKeys isolation on independently-selected lines. | ||
| logs: capturedLogs.filter( | ||
| (log) => log.function_request_id === context.awsRequestId | ||
| ), | ||
| }; | ||
| }; |
Oops, something went wrong.
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.