Skip to content

Commit 94672a1

Browse files
committed
chore: additional fixes
1 parent de1f2e4 commit 94672a1

7 files changed

Lines changed: 23 additions & 34 deletions

File tree

.github/workflows/dockerized-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ 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
6161
ls -la test/dockerized/tasks/
6262
6363
- name: Build base test image with RIE and custom entrypoint

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fmt:
125125
cargo +nightly fmt --all
126126

127127
build-examples:
128-
HANDLERS_TO_BUILD=${HANDLERS_TO_BUILD} OUTPUT_DIR=${OUTPUT_DIR} ./scripts/build-examples.sh
128+
HANDLERS_TO_BUILD="$(HANDLERS_TO_BUILD)" OUTPUT_DIR="$(OUTPUT_DIR)" ./scripts/build-examples.sh
129129

130130
nuke:
131131
docker kill $$(docker ps -q)
@@ -145,6 +145,7 @@ build-test-runner: build-examples
145145
@echo "Building test runner Docker image..."
146146
@docker build -t test-runner:local -f .test-runner/Dockerfile .test-runner
147147

148+
test-dockerized-concurrent: HANDLERS_TO_BUILD := basic-lambda-concurrent invocation-id-concurrent
148149
test-dockerized-concurrent: build-test-runner
149150
@echo "Running concurrent scenarios in Docker..."
150151
@docker network rm concurrent-test-net 2>/dev/null || true

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

Lines changed: 3 additions & 2 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)]

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/runtime.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -716,27 +716,15 @@ mod endpoint_tests {
716716
requests::{EventCompletionRequest, EventErrorRequest, IntoRequest, NextEventRequest},
717717
BoxFuture, Config, Diagnostic, Error, Runtime,
718718
};
719-
use bytes::Bytes;
720-
use http::{HeaderValue, Method, Request, Response, StatusCode};
721-
use http_body_util::{BodyExt, Full};
719+
use http::{HeaderValue, StatusCode};
720+
use http_body_util::BodyExt;
722721
use httpmock::prelude::*;
723722

724-
use hyper::{body::Incoming, service::service_fn};
725-
use hyper_util::{
726-
rt::{tokio::TokioIo, TokioExecutor},
727-
server::conn::auto::Builder as ServerBuilder,
728-
};
729723
use lambda_runtime_api_client::PooledClient as Client;
730724
use std::{
731-
convert::Infallible,
732725
env,
733-
sync::{
734-
atomic::{AtomicUsize, Ordering},
735-
Arc,
736-
},
737-
time::Duration,
726+
sync::Arc,
738727
};
739-
use tokio::{net::TcpListener, sync::Notify};
740728
use tokio_stream::StreamExt;
741729

742730
#[tokio::test]

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)