Skip to content

Fix integration tests #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 38 additions & 28 deletions test/integration/local_lambda/end-to-end-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
cmds_to_delete_images = ["docker rm -f envvarcheck", "docker rm -f testing", "docker rm -f timeout", "docker rm -f exception"]
cmds_to_delete_images = [
"docker rm -f envvarcheck",
"docker rm -f twoinvokes",
"docker rm -f customarn",
"docker rm -f arnexists",
"docker rm -f timeout",
"docker rm -f exception",
"docker rm -f remainingtimethree",
"docker rm -f remainingtimeten",
"docker rm -f remainingtimedefault",
]

for cmd in cmds_to_delete_images:
Popen(cmd.split(' ')).communicate()
Expand All @@ -36,113 +46,113 @@ def tearDownClass(cls):


def test_env_var_with_eqaul_sign(self):
cmd = f"docker run --name envvarcheck -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9003:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.check_env_var_handler"
cmd = f"docker run --name envvarcheck -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.check_env_var_handler"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9003/2015-03-31/functions/function/invocations", json={})
r = requests.post("http://localhost:9000/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'"4=4"', r.content)

def test_two_invokes(self):
cmd = f"docker run --name testing -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler"
cmd = f"docker run --name twoinvokes -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9001:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9000/2015-03-31/functions/function/invocations", json={})
r = requests.post("http://localhost:9001/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'"My lambda ran succesfully"', r.content)

# Make sure we can invoke the function twice
r = requests.post("http://localhost:9000/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'"My lambda ran succesfully"', r.content)
r = requests.post("http://localhost:9001/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'"My lambda ran succesfully"', r.content)

def test_lambda_function_arn_exists(self):
cmd = f"docker run --name testing -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context"
cmd = f"docker run --name arnexists -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9002:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9000/2015-03-31/functions/function/invocations", json={})
r = requests.post("http://localhost:9002/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'"My lambda ran succesfully"', r.content)

def test_lambda_function_arn_exists_with_defining_custom_name(self):
cmd = f"docker run --name testing --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context"
cmd = f"docker run --name customarn --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9003:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_lambda_arn_in_context"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9000/2015-03-31/functions/function/invocations", json={})
r = requests.post("http://localhost:9003/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'"My lambda ran succesfully"', r.content)


def test_timeout_invoke(self):
cmd = f"docker run --name timeout -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=1 -v {self.path_to_binary}:/local-lambda-runtime-server -p 9001:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.sleep_handler"
cmd = f"docker run --name timeout -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=1 -v {self.path_to_binary}:/local-lambda-runtime-server -p 9004:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.sleep_handler"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9001/2015-03-31/functions/function/invocations", json={})
r = requests.post("http://localhost:9004/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b"Task timed out after 1.00 seconds", r.content)

def test_exception_returned(self):
cmd = f"docker run --name exception -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9002:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.exception_handler"
cmd = f"docker run --name exception -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9005:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.exception_handler"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9002/2015-03-31/functions/function/invocations", json={})
r = requests.post("http://localhost:9005/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'{"errorMessage": "Raising an exception", "errorType": "Exception", "stackTrace": [" File \\"/var/task/main.py\\", line 13, in exception_handler\\n raise Exception(\\"Raising an exception\\")\\n"]}', r.content)

def test_context_get_remaining_time_in_three_seconds(self):
cmd = f"docker run --name remainingtimethree -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=3 -v {self.path_to_binary}:/local-lambda-runtime-server -p 9004:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"
cmd = f"docker run --name remainingtimethree -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=3 -v {self.path_to_binary}:/local-lambda-runtime-server -p 9006:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"

Popen(cmd.split(' ')).communicate()

r = requests.post("http://localhost:9004/2015-03-31/functions/function/invocations", json={})

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9006/2015-03-31/functions/function/invocations", json={})
# Executation time is not decided, 1.0s ~ 3.0s is a good estimation
self.assertLess(int(r.content), 3000)
self.assertGreater(int(r.content), 1000)


def test_context_get_remaining_time_in_ten_seconds(self):
cmd = f"docker run --name remainingtimeten -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=10 -v {self.path_to_binary}:/local-lambda-runtime-server -p 9005:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"
cmd = f"docker run --name remainingtimeten -d --env AWS_LAMBDA_FUNCTION_TIMEOUT=10 -v {self.path_to_binary}:/local-lambda-runtime-server -p 9007:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"

Popen(cmd.split(' ')).communicate()

r = requests.post("http://localhost:9005/2015-03-31/functions/function/invocations", json={})

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9007/2015-03-31/functions/function/invocations", json={})
# Executation time is not decided, 8.0s ~ 10.0s is a good estimation
self.assertLess(int(r.content), 10000)
self.assertGreater(int(r.content), 8000)


def test_context_get_remaining_time_in_default_deadline(self):
cmd = f"docker run --name remainingtimedefault -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9006:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"
cmd = f"docker run --name remainingtimedefault -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9008:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.check_remaining_time_handler"

Popen(cmd.split(' ')).communicate()

r = requests.post("http://localhost:9006/2015-03-31/functions/function/invocations", json={})

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9008/2015-03-31/functions/function/invocations", json={})
# Executation time is not decided, 298.0s ~ 300.0s is a good estimation
self.assertLess(int(r.content), 300000)
self.assertGreater(int(r.content), 298000)
Expand All @@ -164,15 +174,15 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
cmds_to_delete_images = ["docker rm -f testing", "docker rm -f assert-overwritten"]
cmds_to_delete_images = ["docker rm -f api-runtime", "docker rm -f assert-overwritten"]

for cmd in cmds_to_delete_images:
Popen(cmd.split(' ')).communicate()

Popen(f"docker rmi {cls.image_name}".split(' ')).communicate()

def test_invoke_with_pre_runtime_api_runtime(self):
cmd = f"docker run --name testing -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler"
cmd = f"docker run --name api-runtime -d -v {self.path_to_binary}:/local-lambda-runtime-server -p 9000:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.success_handler"

Popen(cmd.split(' ')).communicate()

Expand All @@ -183,14 +193,14 @@ def test_invoke_with_pre_runtime_api_runtime(self):
self.assertEqual(b'"My lambda ran succesfully"', r.content)

def test_function_name_is_overriden(self):
cmd = f"docker run --name assert-overwritten -d --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -v {self.path_to_binary}:/local-lambda-runtime-server -p 9009:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_env_var_is_overwritten"
cmd = f"docker run --name assert-overwritten -d --env AWS_LAMBDA_FUNCTION_NAME=MyCoolName -v {self.path_to_binary}:/local-lambda-runtime-server -p 9001:8080 --entrypoint /local-lambda-runtime-server/aws-lambda-rie {self.image_name} {DEFAULT_1P_ENTRYPOINT} main.assert_env_var_is_overwritten"

Popen(cmd.split(' ')).communicate()

# sleep 1s to give enough time for the endpoint to be up to curl
time.sleep(SLEEP_TIME)

r = requests.post("http://localhost:9009/2015-03-31/functions/function/invocations", json={})
r = requests.post("http://localhost:9001/2015-03-31/functions/function/invocations", json={})
self.assertEqual(b'"My lambda ran succesfully"', r.content)


Expand Down