Skip to content

Commit e05d666

Browse files
authored
Fix integration test failures for multi-tenancy (#8447)
* Fix integration test failures for multi-tenancy * Fix format issue * More changes to fix test failure --------- Co-authored-by: Chengjun Li <>
1 parent 9d48ecc commit e05d666

9 files changed

Lines changed: 87 additions & 47 deletions

File tree

tests/integration/local/invoke/test_integrations_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ def test_function_exception(self):
12771277
stack_trace_lines = [
12781278
"[ERROR] Exception: Lambda is raising an exception",
12791279
"Traceback (most recent call last):",
1280-
'\xa0\xa0File "/var/task/main.py", line 51, in raise_exception',
1280+
'\xa0\xa0File "/var/task/main.py", line 65, in raise_exception',
12811281
'\xa0\xa0\xa0\xa0raise Exception("Lambda is raising an exception")',
12821282
]
12831283

tests/integration/local/start_api/test_start_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,17 @@ def test_invalid_lambda_json_body_response(self):
619619
self.assertEqual(response.json(), {"message": "Internal server error"})
620620
self.assertEqual(response.raw.version, 11)
621621

622+
623+
class TestMultiTenantStartApi(StartApiIntegBaseClass):
624+
"""
625+
Test multi-tenant Lambda functions with start-api
626+
"""
627+
628+
template_path = "/testdata/start_api/template-http-api-multi-tenant.yaml"
629+
630+
def setUp(self):
631+
self.url = "http://127.0.0.1:{}".format(self.port)
632+
622633
@pytest.mark.flaky(reruns=3)
623634
@pytest.mark.timeout(timeout=600, method="thread")
624635
def test_multi_tenant_function_http_api_with_tenant_id(self):

tests/integration/remote/invoke/test_remote_invoke.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ def test_invoke_response_json_output_format(self):
120120
self.assertEqual(response_payload, {"message": "Hello world"})
121121
self.assertEqual(remote_invoke_result_stdout["StatusCode"], 200)
122122

123+
124+
@pytest.mark.xdist_group(name="sam_remote_invoke_multi_tenant")
125+
class TestMultiTenantRemoteInvoke(RemoteInvokeIntegBase):
126+
template = Path("template-multi-tenant.yaml")
127+
128+
@classmethod
129+
def setUpClass(cls):
130+
super().setUpClass()
131+
cls.stack_name = f"{cls.__name__}-{uuid.uuid4().hex}"
132+
cls.create_resources_and_boto_clients()
133+
123134
def test_multi_tenant_function_with_tenant_id(self):
124135
command_list = self.get_command_list(
125136
stack_name=self.stack_name,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
4+
Resources:
5+
MultiTenantFunction:
6+
Type: AWS::Serverless::Function
7+
Properties:
8+
Handler: lambda-fns/main.multi_tenant_handler
9+
Runtime: python3.9
10+
CodeUri: .
11+
Timeout: 600
12+
TenancyConfig:
13+
TenantIsolationMode: PER_TENANT

tests/integration/testdata/remote_invoke/template-single-lambda.yaml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,4 @@ Resources:
88
Properties:
99
Handler: main.default_handler
1010
Runtime: python3.9
11-
CodeUri: ./lambda-fns
12-
13-
MultiTenantFunction:
14-
Type: AWS::Serverless::Function
15-
Properties:
16-
Handler: main.multi_tenant_handler
17-
Runtime: python3.9
18-
CodeUri: ./lambda-fns
19-
TenancyConfig:
20-
TenantIsolationMode: PER_TENANT
11+
CodeUri: ./lambda-fns
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
4+
Resources:
5+
MultiTenantApiFunction:
6+
Type: AWS::Serverless::Function
7+
Properties:
8+
Handler: main.multi_tenant_handler
9+
Runtime: python3.9
10+
CodeUri: .
11+
Timeout: 600
12+
TenancyConfig:
13+
TenantIsolationMode: PER_TENANT
14+
Events:
15+
HttpApi:
16+
Type: HttpApi
17+
Properties:
18+
Path: /multi-tenant-http
19+
Method: get

tests/integration/testdata/start_api/template-http-api.yaml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -359,18 +359,3 @@ Resources:
359359
Properties:
360360
Method: GET
361361
Path: /multipleheadersoverridesheaders
362-
MultiTenantApiFunction:
363-
Type: AWS::Serverless::Function
364-
Properties:
365-
Handler: main.multi_tenant_handler
366-
Runtime: python3.9
367-
CodeUri: .
368-
Timeout: 600
369-
TenancyConfig:
370-
TenantIsolationMode: PER_TENANT
371-
Events:
372-
HttpApi:
373-
Type: HttpApi
374-
Properties:
375-
Path: /multi-tenant-http
376-
Method: get
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
4+
Globals:
5+
Api:
6+
Cors:
7+
AllowMethods: "'*'"
8+
AllowHeaders: "'*'"
9+
AllowOrigin: "'*'"
10+
11+
Resources:
12+
MultiTenantApiFunction:
13+
Type: AWS::Serverless::Function
14+
Properties:
15+
Handler: main.multi_tenant_handler
16+
Runtime: python3.9
17+
CodeUri: .
18+
Timeout: 600
19+
TenancyConfig:
20+
TenantIsolationMode: PER_TENANT
21+
Events:
22+
RestApi:
23+
Type: Api
24+
Properties:
25+
Path: /multi-tenant-rest
26+
Method: get
27+
HttpApi:
28+
Type: HttpApi
29+
Properties:
30+
Path: /multi-tenant-http
31+
Method: get

tests/integration/testdata/start_api/template.yaml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -301,24 +301,3 @@ Resources:
301301
Properties:
302302
Path: /sleepfortensecondszipped
303303
Method: get
304-
305-
MultiTenantApiFunction:
306-
Type: AWS::Serverless::Function
307-
Properties:
308-
Handler: main.multi_tenant_handler
309-
Runtime: python3.9
310-
CodeUri: .
311-
Timeout: 600
312-
TenancyConfig:
313-
TenantIsolationMode: PER_TENANT
314-
Events:
315-
RestApi:
316-
Type: Api
317-
Properties:
318-
Path: /multi-tenant-rest
319-
Method: get
320-
HttpApi:
321-
Type: HttpApi
322-
Properties:
323-
Path: /multi-tenant-http
324-
Method: get

0 commit comments

Comments
 (0)