Skip to content

Commit e5af747

Browse files
committed
Prefix the Lambda function name with an argument
This enables us to run multiple integration tests in parallel on different Linux distributions.
1 parent ea6019e commit e5af747

9 files changed

+56
-23
lines changed

ci/codebuild/amazonlinux-2017.03.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ phases:
99
build:
1010
commands:
1111
- echo Build started on `date`
12-
- ci/codebuild/build.sh -DENABLE_TESTS=ON
13-
- ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun
14-
- ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun-no-glibc
12+
- ci/codebuild/build.sh -DENABLE_TESTS=ON -DTEST_RESOURCE_PREFIX=amzn201703
13+
- ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun amzn201703
14+
- ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun-no-glibc amzn201703
1515
post_build:
1616
commands:
1717
- echo Build completed on `date`

ci/codebuild/run-tests.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ cd $CODEBUILD_SRC_DIR
66
cd build
77
rm -rf *.zip
88
ninja $1
9-
aws s3 cp tests/resources/lambda-test-fun.zip s3://aws-lambda-cpp-tests/lambda-test-fun.zip
9+
aws s3 cp tests/resources/lambda-test-fun.zip s3://aws-lambda-cpp-tests/$2lambda-test-fun.zip
1010
ctest --output-on-failure
1111

ci/codebuild/ubuntu-18.04.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
version: 0.1
22
# This uses the docker image specified in ci/docker/ubuntu-linux-18.04
33
phases:
4+
pre_build:
5+
commands:
6+
- pip install awscli
7+
- ci/codebuild/build-cpp-sdk.sh
48
build:
59
commands:
610
- echo Build started on `date`
7-
- ci/codebuild/build.sh -DCMAKE_CXX_CLANG_TIDY=clang-tidy -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
11+
- ci/codebuild/build.sh -DCMAKE_CXX_CLANG_TIDY=clang-tidy -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DENABLE_TESTS=ON -DTEST_RESOURCE_PREFIX=ubuntu1804
812
- ci/codebuild/format-check.sh
13+
- ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun ubuntu1804
914
post_build:
1015
commands:
1116
- echo Build completed on `date`

ci/docker/amazon-linux-2017.03

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ sh cmake-install --skip-license --prefix=/usr --exclude-subdirectory;
88

99
RUN pip-3.6 install --upgrade pip
1010

11+
RUN git clone https://github.com/aws/aws-sdk-cpp.git
12+

ci/docker/ubuntu-linux-18.04

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
FROM ubuntu:18.04
22

3-
RUN apt-get update; apt-get install git clang clang-tidy clang-format libcurl4-openssl-dev wget ninja-build -y
3+
RUN apt-get update; apt-get install git clang clang-tidy clang-format zlib1g-dev libssl-dev libcurl4-openssl-dev wget \
4+
ninja-build python3-pip zip -y
5+
46

57
RUN wget -O cmake-install https://github.com/Kitware/CMake/releases/download/v3.13.0/cmake-3.13.0-Linux-x86_64.sh; \
68
sh cmake-install --skip-license --prefix=/usr --exclude-subdirectory;
9+
10+
RUN pip3 install --upgrade pip
11+
12+
RUN git clone https://github.com/aws/aws-sdk-cpp.git
13+
14+
RUN update-alternatives --set cc /usr/bin/clang
15+
RUN update-alternatives --set c++ /usr/bin/clang++

tests/CMakeLists.txt

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
project(aws-lambda-runtime-tests LANGUAGES CXX)
22
find_package(AWSSDK COMPONENTS lambda iam)
3-
find_package(GTest REQUIRED)
43

54
add_executable(${PROJECT_NAME}
65
main.cpp
76
runtime_tests.cpp
8-
version_tests.cpp)
7+
version_tests.cpp
8+
gtest/gtest-all.cc)
99

10-
target_link_libraries(${PROJECT_NAME} PRIVATE ${AWSSDK_LINK_LIBRARIES} aws-lambda-runtime GTest::GTest)
10+
target_link_libraries(${PROJECT_NAME} PRIVATE ${AWSSDK_LINK_LIBRARIES} aws-lambda-runtime)
1111

12-
gtest_discover_tests(${PROJECT_NAME}) # requires CMake 3.10 or later
12+
include(GoogleTest)
13+
gtest_discover_tests(${PROJECT_NAME} EXTRA_ARGS "--aws_prefix=${TEST_RESOURCE_PREFIX}") # requires CMake 3.10 or later
1314

1415
add_subdirectory(resources)
1516

tests/main.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <aws/core/Aws.h>
2-
#include <gtest/gtest.h>
32
#include <aws/core/utils/logging/ConsoleLogSystem.h>
3+
#include "gtest/gtest.h"
44

55
std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> GetConsoleLoggerFactory()
66
{
@@ -10,8 +10,23 @@ std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> GetCon
1010
};
1111
}
1212

13+
std::string aws_prefix;
14+
15+
void parse_args(int argc, char** argv)
16+
{
17+
const std::string resourcePrefixOption = "--aws_prefix=";
18+
for (int i = 1; i < argc; i++) {
19+
std::string arg = argv[i];
20+
if (arg.find(resourcePrefixOption) == 0) {
21+
aws_prefix = arg.substr(resourcePrefixOption.length()); // get whatever value after the '='
22+
break;
23+
}
24+
}
25+
}
26+
1327
int main(int argc, char** argv)
1428
{
29+
parse_args(argc, argv);
1530
Aws::SDKOptions options;
1631
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Warn;
1732
options.loggingOptions.logger_create_fn = GetConsoleLoggerFactory();

tests/runtime_tests.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ struct LambdaRuntimeTest : public ::testing::Test {
7070
return {};
7171
}
7272

73-
void create_function(Aws::String const& name)
73+
void create_function(Aws::String const& function_name, Aws::String const& handler_name)
7474
{
7575
Model::CreateFunctionRequest createFunctionRequest;
76-
createFunctionRequest.SetHandler(name);
77-
createFunctionRequest.SetFunctionName(name);
76+
createFunctionRequest.SetHandler(handler_name);
77+
createFunctionRequest.SetFunctionName(function_name);
7878
// I ran into eventual-consistency issues when creating the role dynamically as part of the test.
7979
createFunctionRequest.SetRole(get_role_arn("integration-tests"));
8080
Model::FunctionCode funcode;
@@ -83,16 +83,16 @@ struct LambdaRuntimeTest : public ::testing::Test {
8383
createFunctionRequest.SetRuntime(Aws::Lambda::Model::Runtime::provided);
8484

8585
auto outcome = m_lambda_client.CreateFunction(createFunctionRequest);
86-
ASSERT_TRUE(outcome.IsSuccess()) << "Failed to create function " << name;
86+
ASSERT_TRUE(outcome.IsSuccess()) << "Failed to create function " << function_name;
8787
}
8888

89-
void delete_function(Aws::String const& name, bool assert = true)
89+
void delete_function(Aws::String const& function_name, bool assert = true)
9090
{
9191
Model::DeleteFunctionRequest deleteFunctionRequest;
92-
deleteFunctionRequest.SetFunctionName(name);
92+
deleteFunctionRequest.SetFunctionName(function_name);
9393
auto outcome = m_lambda_client.DeleteFunction(deleteFunctionRequest);
9494
if (assert) {
95-
ASSERT_TRUE(outcome.IsSuccess()) << "Failed to delete function " << name;
95+
ASSERT_TRUE(outcome.IsSuccess()) << "Failed to delete function " << function_name;
9696
}
9797
}
9898
};
@@ -101,7 +101,7 @@ TEST_F(LambdaRuntimeTest, echo_success)
101101
{
102102
Aws::String const funcname = build_resource_name("echo_success");
103103
char const payloadContent[] = "Hello, Lambda!";
104-
create_function(funcname);
104+
create_function(funcname, "echo_success" /*handler_name*/);
105105
Model::InvokeRequest invokeRequest;
106106
invokeRequest.SetFunctionName(funcname);
107107
invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse);
@@ -132,7 +132,7 @@ TEST_F(LambdaRuntimeTest, echo_unicode)
132132
{
133133
Aws::String const funcname = build_resource_name("echo_success"); // re-use the echo method but with Unicode input
134134
char const payloadContent[] = "画像は1000語の価値がある";
135-
create_function(funcname);
135+
create_function(funcname, "echo_success" /*handler_name*/);
136136
Model::InvokeRequest invokeRequest;
137137
invokeRequest.SetFunctionName(funcname);
138138
invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse);
@@ -162,7 +162,7 @@ TEST_F(LambdaRuntimeTest, echo_unicode)
162162
TEST_F(LambdaRuntimeTest, echo_failure)
163163
{
164164
Aws::String const funcname = build_resource_name("echo_failure");
165-
create_function(funcname);
165+
create_function(funcname, "echo_failure" /*handler_name*/);
166166
Model::InvokeRequest invokeRequest;
167167
invokeRequest.SetFunctionName(funcname);
168168
invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse);
@@ -178,7 +178,7 @@ TEST_F(LambdaRuntimeTest, binary_response)
178178
{
179179
Aws::String const funcname = build_resource_name("binary_response");
180180
unsigned long constexpr expected_length = 1451;
181-
create_function(funcname);
181+
create_function(funcname, "binary_response" /*handler_name*/);
182182
Model::InvokeRequest invokeRequest;
183183
invokeRequest.SetFunctionName(funcname);
184184
invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse);
@@ -190,3 +190,4 @@ TEST_F(LambdaRuntimeTest, binary_response)
190190
EXPECT_EQ(expected_length, invokeOutcome.GetResult().GetPayload().tellp());
191191
delete_function(funcname);
192192
}
193+
} // namespace

tests/version_tests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include <gtest/gtest.h>
21
#include <aws/lambda-runtime/version.h>
2+
#include "gtest/gtest.h"
33

44
using namespace aws::lambda_runtime;
55

0 commit comments

Comments
 (0)