Skip to content

Commit

Permalink
Prefix the Lambda function name with an argument
Browse files Browse the repository at this point in the history
This enables us to run multiple integration tests in parallel on
different Linux distributions.
  • Loading branch information
marcomagdy committed Jun 25, 2019
1 parent ea6019e commit e5af747
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 23 deletions.
6 changes: 3 additions & 3 deletions ci/codebuild/amazonlinux-2017.03.yml
Expand Up @@ -9,9 +9,9 @@ phases:
build:
commands:
- echo Build started on `date`
- ci/codebuild/build.sh -DENABLE_TESTS=ON
- ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun
- ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun-no-glibc
- ci/codebuild/build.sh -DENABLE_TESTS=ON -DTEST_RESOURCE_PREFIX=amzn201703
- ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun amzn201703
- ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun-no-glibc amzn201703
post_build:
commands:
- echo Build completed on `date`
Expand Down
2 changes: 1 addition & 1 deletion ci/codebuild/run-tests.sh
Expand Up @@ -6,6 +6,6 @@ cd $CODEBUILD_SRC_DIR
cd build
rm -rf *.zip
ninja $1
aws s3 cp tests/resources/lambda-test-fun.zip s3://aws-lambda-cpp-tests/lambda-test-fun.zip
aws s3 cp tests/resources/lambda-test-fun.zip s3://aws-lambda-cpp-tests/$2lambda-test-fun.zip
ctest --output-on-failure

7 changes: 6 additions & 1 deletion ci/codebuild/ubuntu-18.04.yml
@@ -1,11 +1,16 @@
version: 0.1
# This uses the docker image specified in ci/docker/ubuntu-linux-18.04
phases:
pre_build:
commands:
- pip install awscli
- ci/codebuild/build-cpp-sdk.sh
build:
commands:
- echo Build started on `date`
- ci/codebuild/build.sh -DCMAKE_CXX_CLANG_TIDY=clang-tidy -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
- ci/codebuild/build.sh -DCMAKE_CXX_CLANG_TIDY=clang-tidy -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DENABLE_TESTS=ON -DTEST_RESOURCE_PREFIX=ubuntu1804
- ci/codebuild/format-check.sh
- ci/codebuild/run-tests.sh aws-lambda-package-lambda-test-fun ubuntu1804
post_build:
commands:
- echo Build completed on `date`
Expand Down
2 changes: 2 additions & 0 deletions ci/docker/amazon-linux-2017.03
Expand Up @@ -8,3 +8,5 @@ sh cmake-install --skip-license --prefix=/usr --exclude-subdirectory;

RUN pip-3.6 install --upgrade pip

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

11 changes: 10 additions & 1 deletion ci/docker/ubuntu-linux-18.04
@@ -1,6 +1,15 @@
FROM ubuntu:18.04

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


RUN wget -O cmake-install https://github.com/Kitware/CMake/releases/download/v3.13.0/cmake-3.13.0-Linux-x86_64.sh; \
sh cmake-install --skip-license --prefix=/usr --exclude-subdirectory;

RUN pip3 install --upgrade pip

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

RUN update-alternatives --set cc /usr/bin/clang
RUN update-alternatives --set c++ /usr/bin/clang++
9 changes: 5 additions & 4 deletions tests/CMakeLists.txt
@@ -1,15 +1,16 @@
project(aws-lambda-runtime-tests LANGUAGES CXX)
find_package(AWSSDK COMPONENTS lambda iam)
find_package(GTest REQUIRED)

add_executable(${PROJECT_NAME}
main.cpp
runtime_tests.cpp
version_tests.cpp)
version_tests.cpp
gtest/gtest-all.cc)

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

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

add_subdirectory(resources)

17 changes: 16 additions & 1 deletion tests/main.cpp
@@ -1,6 +1,6 @@
#include <aws/core/Aws.h>
#include <gtest/gtest.h>
#include <aws/core/utils/logging/ConsoleLogSystem.h>
#include "gtest/gtest.h"

std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> GetConsoleLoggerFactory()
{
Expand All @@ -10,8 +10,23 @@ std::function<std::shared_ptr<Aws::Utils::Logging::LogSystemInterface>()> GetCon
};
}

std::string aws_prefix;

void parse_args(int argc, char** argv)
{
const std::string resourcePrefixOption = "--aws_prefix=";
for (int i = 1; i < argc; i++) {
std::string arg = argv[i];
if (arg.find(resourcePrefixOption) == 0) {
aws_prefix = arg.substr(resourcePrefixOption.length()); // get whatever value after the '='
break;
}
}
}

int main(int argc, char** argv)
{
parse_args(argc, argv);
Aws::SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Warn;
options.loggingOptions.logger_create_fn = GetConsoleLoggerFactory();
Expand Down
23 changes: 12 additions & 11 deletions tests/runtime_tests.cpp
Expand Up @@ -70,11 +70,11 @@ struct LambdaRuntimeTest : public ::testing::Test {
return {};
}

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

auto outcome = m_lambda_client.CreateFunction(createFunctionRequest);
ASSERT_TRUE(outcome.IsSuccess()) << "Failed to create function " << name;
ASSERT_TRUE(outcome.IsSuccess()) << "Failed to create function " << function_name;
}

void delete_function(Aws::String const& name, bool assert = true)
void delete_function(Aws::String const& function_name, bool assert = true)
{
Model::DeleteFunctionRequest deleteFunctionRequest;
deleteFunctionRequest.SetFunctionName(name);
deleteFunctionRequest.SetFunctionName(function_name);
auto outcome = m_lambda_client.DeleteFunction(deleteFunctionRequest);
if (assert) {
ASSERT_TRUE(outcome.IsSuccess()) << "Failed to delete function " << name;
ASSERT_TRUE(outcome.IsSuccess()) << "Failed to delete function " << function_name;
}
}
};
Expand All @@ -101,7 +101,7 @@ TEST_F(LambdaRuntimeTest, echo_success)
{
Aws::String const funcname = build_resource_name("echo_success");
char const payloadContent[] = "Hello, Lambda!";
create_function(funcname);
create_function(funcname, "echo_success" /*handler_name*/);
Model::InvokeRequest invokeRequest;
invokeRequest.SetFunctionName(funcname);
invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse);
Expand Down Expand Up @@ -132,7 +132,7 @@ TEST_F(LambdaRuntimeTest, echo_unicode)
{
Aws::String const funcname = build_resource_name("echo_success"); // re-use the echo method but with Unicode input
char const payloadContent[] = "画像は1000語の価値がある";
create_function(funcname);
create_function(funcname, "echo_success" /*handler_name*/);
Model::InvokeRequest invokeRequest;
invokeRequest.SetFunctionName(funcname);
invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse);
Expand Down Expand Up @@ -162,7 +162,7 @@ TEST_F(LambdaRuntimeTest, echo_unicode)
TEST_F(LambdaRuntimeTest, echo_failure)
{
Aws::String const funcname = build_resource_name("echo_failure");
create_function(funcname);
create_function(funcname, "echo_failure" /*handler_name*/);
Model::InvokeRequest invokeRequest;
invokeRequest.SetFunctionName(funcname);
invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse);
Expand All @@ -178,7 +178,7 @@ TEST_F(LambdaRuntimeTest, binary_response)
{
Aws::String const funcname = build_resource_name("binary_response");
unsigned long constexpr expected_length = 1451;
create_function(funcname);
create_function(funcname, "binary_response" /*handler_name*/);
Model::InvokeRequest invokeRequest;
invokeRequest.SetFunctionName(funcname);
invokeRequest.SetInvocationType(Model::InvocationType::RequestResponse);
Expand All @@ -190,3 +190,4 @@ TEST_F(LambdaRuntimeTest, binary_response)
EXPECT_EQ(expected_length, invokeOutcome.GetResult().GetPayload().tellp());
delete_function(funcname);
}
} // namespace
2 changes: 1 addition & 1 deletion tests/version_tests.cpp
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include <aws/lambda-runtime/version.h>
#include "gtest/gtest.h"

using namespace aws::lambda_runtime;

Expand Down

0 comments on commit e5af747

Please sign in to comment.