Skip to content

Commit c403f80

Browse files
committed
chore: additional fixes
1 parent de1f2e4 commit c403f80

6 files changed

Lines changed: 28 additions & 21 deletions

File tree

.github/workflows/dockerized-test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ jobs:
5757
- name: Build Lambda artifacts for testing
5858
run: |
5959
mkdir -p test/dockerized/tasks
60-
HANDLERS_TO_BUILD="basic-lambda-concurrent" OUTPUT_DIR="$(pwd)/test/dockerized/tasks" make build-examples
60+
HANDLERS_TO_BUILD="basic-lambda-concurrent invocation-id-concurrent" OUTPUT_DIR="$(pwd)/test/dockerized/tasks" make build-examples
61+
test -x test/dockerized/tasks/basic-lambda-concurrent
62+
test -x test/dockerized/tasks/invocation-id-concurrent
6163
ls -la test/dockerized/tasks/
6264
6365
- name: Build base test image with RIE and custom entrypoint
@@ -68,6 +70,8 @@ jobs:
6870

6971
- name: Run concurrent scenarios
7072
uses: aws/containerized-test-runner-for-aws-lambda@main
73+
env:
74+
CONTAINER_READY_DELAY_SECS: 5
7175
with:
7276
suiteFileArray: '[]'
7377
dockerImageName: 'local/test-base'

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ INTEG_EXTENSIONS := extension-fn extension-trait logs-trait
77
INTEG_ARCH := x86_64-unknown-linux-musl
88
RIE_MAX_CONCURRENCY ?= 4
99
TEST_RUNNER_BRANCH ?= main
10+
CONTAINER_READY_DELAY_SECS ?= 5
1011
OUTPUT_DIR ?= test/dockerized/tasks
1112
HANDLERS_TO_BUILD ?=
1213
HANDLER ?=
@@ -125,7 +126,7 @@ fmt:
125126
cargo +nightly fmt --all
126127

127128
build-examples:
128-
HANDLERS_TO_BUILD=${HANDLERS_TO_BUILD} OUTPUT_DIR=${OUTPUT_DIR} ./scripts/build-examples.sh
129+
HANDLERS_TO_BUILD="$(subst ",,$(HANDLERS_TO_BUILD))" OUTPUT_DIR="$(OUTPUT_DIR)" ./scripts/build-examples.sh
129130

130131
nuke:
131132
docker kill $$(docker ps -q)
@@ -145,6 +146,7 @@ build-test-runner: build-examples
145146
@echo "Building test runner Docker image..."
146147
@docker build -t test-runner:local -f .test-runner/Dockerfile .test-runner
147148

149+
test-dockerized-concurrent: HANDLERS_TO_BUILD := basic-lambda-concurrent invocation-id-concurrent
148150
test-dockerized-concurrent: build-test-runner
149151
@echo "Running concurrent scenarios in Docker..."
150152
@docker network rm concurrent-test-net 2>/dev/null || true
@@ -156,6 +158,7 @@ test-dockerized-concurrent: build-test-runner
156158
-e TASK_FOLDER=./test/dockerized/tasks \
157159
-e GITHUB_WORKSPACE=/workspace \
158160
-e DOCKER_SHARED_NETWORK=concurrent-test-net \
161+
-e CONTAINER_READY_DELAY_SECS=$(CONTAINER_READY_DELAY_SECS) \
159162
-v /var/run/docker.sock:/var/run/docker.sock \
160163
-v "$(CURDIR):/workspace" \
161164
-w /workspace \

examples/invocation-id-concurrent/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use serde::{Deserialize, Serialize};
66

77
#[derive(Deserialize)]
88
struct Request {
9-
command: String,
10-
sleep: u32
9+
#[serde(rename = "command")]
10+
_command: String,
11+
sleep: u32,
1112
}
1213

1314
#[derive(Serialize, Debug, PartialEq)]
@@ -89,7 +90,7 @@ mod tests {
8990
context.invocation_id = Some("inv-456".to_string());
9091

9192
let payload = Request {
92-
command: "test".to_string(),
93+
_command: "test".to_string(),
9394
sleep: 0,
9495
};
9596
let event = LambdaEvent { payload, context };
@@ -111,7 +112,7 @@ mod tests {
111112
// invocation_id defaults to None
112113

113114
let payload = Request {
114-
command: "test".to_string(),
115+
_command: "test".to_string(),
115116
sleep: 0,
116117
};
117118
let event = LambdaEvent { payload, context };

lambda-runtime/src/requests.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,7 @@ where
138138
let body = serde_json::to_vec(&body)?;
139139
let body = Body::from(body);
140140

141-
let mut req = build_request()
142-
.method(Method::POST)
143-
.uri(uri)
144-
.body(body)?;
141+
let mut req = build_request().method(Method::POST).uri(uri).body(body)?;
145142

146143
if let Some(id) = self.invocation_id {
147144
req.headers_mut().insert(LAMBDA_RUNTIME_INVOCATION_ID, id.parse()?);
@@ -346,8 +343,7 @@ mod tests {
346343
let stream_response: StreamResponse<_> = stream.into();
347344
let response = FunctionResponse::StreamingResponse(stream_response);
348345

349-
let req: EventCompletionRequest<'_, _, (), _, _, _> =
350-
EventCompletionRequest::new("id", None, response);
346+
let req: EventCompletionRequest<'_, _, (), _, _, _> = EventCompletionRequest::new("id", None, response);
351347

352348
let http_req = req.into_req().expect("into_req should succeed");
353349

@@ -466,7 +462,7 @@ mod tests {
466462
let stream_response: StreamResponse<_> = stream.into();
467463
let response = FunctionResponse::StreamingResponse(stream_response);
468464

469-
let req: EventCompletionRequest<'_, _, (), _, _, _> = EventCompletionRequest::new("id", response);
465+
let req: EventCompletionRequest<'_, _, (), _, _, _> = EventCompletionRequest::new("id", None, response);
470466

471467
let http_req = req.into_req().expect("into_req should succeed");
472468

lambda-runtime/src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ where
307307

308308
#[cfg(test)]
309309
mod test {
310-
use http::HeaderName;
311310

312311
use super::*;
313312
use crate::Config;
@@ -558,6 +557,8 @@ mod test {
558557
fn context_with_invocation_id_resolves() {
559558
let config = Arc::new(Config::default());
560559
let mut headers = HeaderMap::new();
560+
headers.insert("lambda-runtime-aws-request-id", HeaderValue::from_static("my-id"));
561+
headers.insert("lambda-runtime-deadline-ms", HeaderValue::from_static("123"));
561562

562563
let context = Context::new("id", config, &headers).unwrap();
563564

test/dockerized/scenarios/concurrent_scenarios.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
from containerized_test_runner.models import Request, ConcurrentTest
1010

1111
HANDLER = "basic-lambda-concurrent"
12+
INVOCATION_ID_HANDLER = "invocation-id-concurrent"
1213
IMAGE = os.environ.get("TEST_IMAGE", "local/test-base")
14+
SAME_REQUEST_ID = "shared-request-id"
1315
DEFAULT_CONCURRENCY = 10
1416
TIMEOUT = 5
1517

@@ -23,7 +25,7 @@ def _make_env(concurrency: int = DEFAULT_CONCURRENCY) -> dict:
2325

2426

2527
def _invocation_id_env(concurrency: int = DEFAULT_CONCURRENCY, timeout: int = TIMEOUT) -> dict:
26-
return _make_env | {
28+
return _make_env(concurrency) | {
2729
"AWS_LAMBDA_FUNCTION_TIMEOUT": str(timeout),
2830
}
2931

@@ -71,25 +73,25 @@ def get_concurrent_scenarios():
7173
return scenarios
7274

7375

74-
def invocation_id_scenarios():
76+
def get_invocation_id_scenarios():
7577
batches = [
7678
[Request.create(
77-
payload={"name": "invoke-A", "sleep": TIMEOUT + 2},
79+
payload={"command": "invoke-A", "sleep": TIMEOUT + 2},
7880
assertions=[{"transform": ".errorType", "error": "Sandbox.Timedout"}],
7981
headers={"X-Amzn-RequestId": SAME_REQUEST_ID},
8082
)],
8183
[Request.create(
82-
payload={"name": "invoke-B", "sleep": TIMEOUT - 1},
83-
assertions={"response": {"from": "invoke-B"}},
84+
payload={"command": "invoke-B", "sleep": TIMEOUT - 1},
85+
assertions=[{"transform": ".req_id", "response": SAME_REQUEST_ID}],
8486
headers={"X-Amzn-RequestId": SAME_REQUEST_ID},
8587
)],
8688
]
8789

8890

8991
return [ConcurrentTest(
9092
name="invocation_id",
91-
handler="invocation-id-concurrent",
92-
environment_variables=_invocation_id_env(timeout=1),
93+
handler=INVOCATION_ID_HANDLER,
94+
environment_variables=_invocation_id_env(timeout=TIMEOUT),
9395
request_batches=batches,
9496
image=IMAGE,
9597
)]

0 commit comments

Comments
 (0)