#!/bin/bash ##===----------------------------------------------------------------------===## ## ## This source file is part of the SwiftAWSLambdaRuntime open source project ## ## Copyright SwiftAWSLambdaRuntime project authors ## Copyright (c) Amazon.com, Inc. or its affiliates. ## Licensed under Apache License v2.0 ## ## See LICENSE.txt for license information ## See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors ## ## SPDX-License-Identifier: Apache-2.0 ## ##===----------------------------------------------------------------------===## log() { printf -- "** %s\n" "$*" >&2; } error() { printf -- "** ERROR: %s\n" "$*" >&2; } fatal() { error "$@"; exit 1; } export HOST=127.0.0.1 export PORT=7777 export AWS_LAMBDA_RUNTIME_API="$HOST:$PORT" export LOG_LEVEL=error # important, otherwise log becomes a bottleneck DATE_CMD="date" # using gdate on darwin for nanoseconds # gdate is installed by coreutils on macOS if [[ $(uname -s) == "Darwin" ]]; then if ! command -v gdate &> /dev/null; then # shellcheck disable=SC2006 # we explicitly want to use backticks here fatal "gdate could not be found. Please \`brew install coreutils\` to proceed." fi DATE_CMD="gdate" fi echo "⏱️ using $DATE_CMD to count time" if ! command -v "$DATE_CMD" &> /dev/null; then fatal "$DATE_CMD could not be found. Please install $DATE_CMD to proceed." fi echo "🏗️ Building library and test functions" swift build -c release -Xswiftc -g swift build --package-path Examples/HelloWorld -c release -Xswiftc -g swift build --package-path Examples/HelloJSON -c release -Xswiftc -g cleanup() { pkill -9 MockServer && echo "killed previous mock server" # ignore-unacceptable-language } # start a mock server start_mockserver() { if [ $# -ne 2 ]; then fatal "Usage: $0 " fi MODE=$1 INVOCATIONS=$2 pkill -9 MockServer && echo "killed previous mock server" && sleep 1 # ignore-unacceptable-language echo "👨‍🔧 starting server in $MODE mode for $INVOCATIONS invocations" (MAX_INVOCATIONS="$INVOCATIONS" MODE="$MODE" ./.build/release/MockServer) & server_pid=$! sleep 1 kill -0 $server_pid # check server is alive # ignore-unacceptable-language } cold_iterations=100 warm_iterations=1000 results=() #------------------ # string #------------------ MODE=string # Start mock server start_mockserver "$MODE" "$cold_iterations" # cold start echo "🚀❄️ running $MODE mode $cold_iterations cold test" cold=() for (( i=0; i