Skip to content

Commit 642d877

Browse files
authored
Test coverage (#406)
- add test coverage - Updated the localhost for http/2 to be setup from builder instead. - trivial updates for the localhost port to avoid conflict with other local server.
1 parent 89429eb commit 642d877

File tree

12 files changed

+70
-36
lines changed

12 files changed

+70
-36
lines changed

.builder/action/aws-c-http-test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ def run(self, env):
3333
os.chdir('../../aws-c-http')
3434

3535
actions.append(['ctest', '--output-on-failure'])
36+
# generate the test coverage report whenever possible, will be ignored by ctest if there is no test coverage data available.
37+
actions.append(['ctest', '-T', 'coverage'])
3638

3739
return Builder.Script(actions, name='aws-c-http-test')
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
Setup local server for tests
3+
"""
4+
5+
import Builder
6+
7+
import os
8+
import sys
9+
import subprocess
10+
import atexit
11+
12+
13+
class LocalServerSetup(Builder.Action):
14+
"""
15+
Set up this machine for running the local h2 server test.
16+
To run the local server related test, use `--cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON` from builder.
17+
Not running local server tests for every CI as it takes a while.
18+
19+
This action should be run in the 'pre_build_steps' or 'build_steps' stage.
20+
"""
21+
22+
def run(self, env):
23+
self.env = env
24+
python_path = sys.executable
25+
# Install dependency for mock server.
26+
# Okay to fail, and if it fails, you will know when you enable the localhost tests.
27+
# We don't need it to succeed on every platform we have.
28+
result = self.env.shell.exec(python_path,
29+
'-m', 'pip', 'install', 'h2')
30+
if result.returncode != 0:
31+
print(
32+
"Could not install python HTTP/2 server." +
33+
" The localhost integration tests will fail if you run them.", file=sys.stderr)
34+
return
35+
36+
base_dir = os.path.dirname(os.path.realpath(__file__))
37+
dir = os.path.join(base_dir, "..", "..", "tests", "py_localhost")
38+
os.chdir(dir)
39+
40+
p_server = subprocess.Popen([python_path, "server.py"])
41+
p_non_tls_server = subprocess.Popen([python_path, "non_tls_server.py"])
42+
43+
@atexit.register
44+
def close_local_server():
45+
p_server.terminate()
46+
p_non_tls_server.terminate()

.github/workflows/ci.yml

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- 'main'
77

88
env:
9-
BUILDER_VERSION: v0.9.26
9+
BUILDER_VERSION: v0.9.29
1010
BUILDER_SOURCE: releases
1111
BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net
1212
PACKAGE_NAME: aws-c-http
@@ -155,12 +155,6 @@ jobs:
155155
steps:
156156
- name: Checkout
157157
uses: actions/checkout@v3
158-
- name: Configure local host
159-
run: |
160-
python3 -m pip install h2
161-
cd ./tests/py_localhost/
162-
python3 server.py &
163-
python3 non_tls_server.py &
164158
- name: Build and test
165159
run: |
166160
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
@@ -171,12 +165,6 @@ jobs:
171165
steps:
172166
- name: Checkout
173167
uses: actions/checkout@v3
174-
- name: Configure local host
175-
run: |
176-
python3 -m pip install h2
177-
cd ./tests/py_localhost/
178-
python3 server.py &
179-
python3 non_tls_server.py &
180168
- name: Build and test
181169
run: |
182170
python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
@@ -187,13 +175,7 @@ jobs:
187175
steps:
188176
- name: Checkout
189177
uses: actions/checkout@v3
190-
- name: Configure local host
191-
run: |
192-
python -m pip install h2
193178
- name: Build and test
194179
run: |
195-
cd ./tests/py_localhost/
196-
Start-Process -NoNewWindow python .\server.py
197-
Start-Process -NoNewWindow python .\non_tls_server.py
198180
python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')"
199181
python builder.pyz build -p aws-c-http --cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON

builder.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
{ "name": "aws-c-mqtt" },
1616
{ "name": "aws-c-s3" }
1717
],
18+
"pre_build_steps": ["local-server-setup"],
1819
"test_steps": [
1920
"aws-c-http-test",
2021
["{python}", "{source_dir}/integration-testing/http_client_test.py", "{install_dir}/bin/elasticurl{exe}"]

codebuild/linux-integration-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ phases:
1010
pre_build:
1111
commands:
1212
- export CC=gcc-7
13-
- export BUILDER_VERSION=v0.9.12
13+
- export BUILDER_VERSION=v0.9.29
1414
- export BUILDER_SOURCE=releases
1515
- export BUILDER_HOST=https://d19elf31gohf1l.cloudfront.net
1616
build:
@@ -19,7 +19,7 @@ phases:
1919
- aws s3 cp s3://aws-crt-test-stuff/setup_proxy_test_env_h2.sh /tmp/setup_proxy_test_env.sh
2020
- chmod a+xr /tmp/setup_proxy_test_env.sh
2121
- python3 -c "from urllib.request import urlretrieve; urlretrieve('$BUILDER_HOST/$BUILDER_SOURCE/$BUILDER_VERSION/builder.pyz', 'builder.pyz')"
22-
- python3 builder.pyz build -p aws-c-http --cmake-extra=-DENABLE_PROXY_INTEGRATION_TESTS=ON
22+
- python3 builder.pyz build -p aws-c-http --cmake-extra=-DENABLE_PROXY_INTEGRATION_TESTS=ON --cmake-extra=-DENABLE_LOCALHOST_INTEGRATION_TESTS=ON --coverage
2323
post_build:
2424
commands:
2525
- echo Build completed on `date`

tests/h2_test_helper.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ static void s_frame_init(
2727
}
2828

2929
static void s_frame_clean_up(struct h2_decoded_frame *frame) {
30+
if (!frame) {
31+
return;
32+
}
3033
aws_http_headers_release(frame->headers);
3134
aws_array_list_clean_up(&frame->settings);
3235
aws_byte_buf_clean_up(&frame->data);

tests/py_localhost/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ Python 3.5+ required.
1717
#### Echo
1818

1919
- Minor changed based on the example to response the headers of requests back within the headers from `/echo`.
20-
- To test the server runs correctly, you can do `curl -k -v -H "foo:bar" https://localhost:8443/echo` and check the result.
20+
- To test the server runs correctly, you can do `curl -k -v -H "foo:bar" https://localhost:3443/echo` and check the result.
2121

2222
#### Download test
2323

2424
- To test download, when `:path` is `/downloadTest`, server will response a repeated string with length `self.download_test_length`, which is 2,500,000,000 now. It will be repeats of sting "This is CRT HTTP test."
25-
- To test the server runs correctly, you can do `curl -k -v -H "foo:bar" https://localhost:8443/downloadTest` and check the result.
25+
- To test the server runs correctly, you can do `curl -k -v -H "foo:bar" https://localhost:3443/downloadTest` and check the result.
2626

2727
#### Slow Connection Test
2828

@@ -31,10 +31,10 @@ Python 3.5+ required.
3131
#### Upload test
3232

3333
- To test upload, when `:method` is `POST` or `PUT`, server will response the length received from response body
34-
- To test the server runs correctly, you can do `curl -k -X POST -F'data=@upload_test.txt' https://localhost:8443/upload_test` where `upload_test.txt` is file to upload.
34+
- To test the server runs correctly, you can do `curl -k -X POST -F'data=@upload_test.txt' https://localhost:3443/upload_test` where `upload_test.txt` is file to upload.
3535

3636
### Non-TLS server
3737

3838
- The code is based the non-tls [example](http://python-hyper.org/projects/h2/en/stable/basic-usage.html) from hyper h2 server.
3939
- Run python. `python3 ./non_tls_server.py`.
40-
- To test the server runs correctly, you can do `curl -v --http2-prior-knowledge http://localhost:8080` and check the result.
40+
- To test the server runs correctly, you can do `curl -v --http2-prior-knowledge http://localhost:3280` and check the result.

tests/py_localhost/non_tls_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def handle(sock):
4949

5050
sock = socket.socket()
5151
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
52-
sock.bind(('0.0.0.0', 8080))
52+
sock.bind(('0.0.0.0', 3280))
5353
sock.listen(5)
5454

5555
while True:

tests/py_localhost/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def window_updated(self, stream_id, delta):
313313

314314
loop = asyncio.new_event_loop()
315315
# Each client connection will create a new protocol instance
316-
coro = loop.create_server(H2Protocol, '127.0.0.1', 8443, ssl=ssl_context)
316+
coro = loop.create_server(H2Protocol, '127.0.0.1', 3443, ssl=ssl_context)
317317
server = loop.run_until_complete(coro)
318318

319319
# Serve requests until Ctrl+C is pressed

tests/test_connection_manager.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ static void s_cm_tester_on_cm_shutdown_complete(void *user_data) {
119119

120120
aws_mutex_lock(&tester->lock);
121121
tester->is_shutdown_complete = true;
122-
aws_mutex_unlock(&tester->lock);
123122
aws_condition_variable_notify_one(&tester->signal);
123+
aws_mutex_unlock(&tester->lock);
124124
}
125125

126126
static struct aws_event_loop *s_new_event_loop(
@@ -872,7 +872,7 @@ static int s_test_connection_manager_proxy_setup_shutdown(struct aws_allocator *
872872

873873
struct aws_http_proxy_options proxy_options = {
874874
.host = aws_byte_cursor_from_c_str("127.0.0.1"),
875-
.port = 8080,
875+
.port = 3280,
876876
};
877877

878878
struct cm_tester_options options = {
@@ -1367,8 +1367,8 @@ static void s_aws_http_on_stream_complete_proxy_test(struct aws_http_stream *str
13671367

13681368
aws_mutex_lock(&tester->lock);
13691369
tester->proxy_request_complete = true;
1370-
aws_mutex_unlock(&tester->lock);
13711370
aws_condition_variable_notify_one(&tester->signal);
1371+
aws_mutex_unlock(&tester->lock);
13721372
}
13731373

13741374
static struct aws_byte_cursor s_get_proxy_host_for_test(

0 commit comments

Comments
 (0)