Skip to content

Commit ade69eb

Browse files
authored
Minor contract test and pr_build improvements (#57)
In this commit we are making a few small changes to contract tests and pr_build: * In image Dockerfile upgrade pip and use PIP_ROOT_USER_ACTION=ignore to avoid unneeded warnings in image build process * In contract test base, make use of `addCleanup`, which (based on TestCase documentation) will always run, even if `setUp` fails, (unlike tearDown). This ensures tests reliably clean up and avoids issues with failures in setup. * In PR build, break out lint/spellcheck into their own jobs to keep workflow clean and lean. Add the ability to optionally run unit tests to setup steps, for saving some runtime of lint/spellcheck. * In PR build, disable fail-fast. If one matrix invocation fails, we still want to see the others to catch multiple issues if they are present. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 77ac67b commit ade69eb

File tree

6 files changed

+85
-35
lines changed

6 files changed

+85
-35
lines changed

.github/actions/artifacts_build/action.yml

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
name: Build and Push aws-opentelemetry-distro Wheel and Image files according inputs
1+
name: Build and Push aws-opentelemetry-distro
22
description: |
3-
This action assumes that Repo was checked out and Python was set correctly
3+
This action assumes that the repo was checked out. Builds and pushes/loads wheel and image files.
44
55
inputs:
66
aws-region:
@@ -35,27 +35,13 @@ inputs:
3535
runs:
3636
using: "composite"
3737
steps:
38-
- name: Set up Python
39-
uses: actions/setup-python@v4
38+
- name: Set up
39+
uses: ./.github/actions/set_up
4040
with:
41-
python-version: ${{ inputs.python_version }}
42-
43-
- name: Install tox
44-
shell: bash
45-
run: pip install tox==3.27.1 tox-factor
46-
47-
- name: Cache tox environment
48-
# Preserves .tox directory between runs for faster installs
49-
uses: actions/cache@v1
50-
with:
51-
path: |
52-
.tox
53-
~/.cache/pip
54-
key: v7-build-tox-cache-${{ inputs.python_version }}-${{ inputs.package_name }}-${{ inputs.os }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}
55-
56-
- name: run tox
57-
shell: bash
58-
run: tox -f ${{ inputs.python_version }}-${{ inputs.package_name }} -- -ra --benchmark-json=${{ inputs.python_version }}-${{ inputs.package_name }}-${{ inputs.os }}-benchmark.json
41+
python_version: ${{ inputs.python_version }}
42+
package_name: ${{ inputs.package_name }}
43+
os: ${{ inputs.os }}
44+
run_unit_tests: true
5945

6046
- name: Configure AWS Credentials
6147
uses: aws-actions/configure-aws-credentials@v4

.github/actions/set_up/action.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Set up
2+
description: |
3+
This action assumes that the repo was checked out. Installs python and tox, then runs tox to trigger unit tests.
4+
5+
inputs:
6+
python_version:
7+
required: true
8+
description: "The python version used in actions"
9+
package_name:
10+
required: true
11+
description: "The package name"
12+
os:
13+
required: true
14+
description: "The os"
15+
run_unit_tests:
16+
required: true
17+
description: "true/false flag indicating if we should run unit tests/benchmarks with tox"
18+
19+
20+
runs:
21+
using: "composite"
22+
steps:
23+
- name: Set up Python
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: ${{ inputs.python_version }}
27+
28+
- name: Install tox
29+
shell: bash
30+
run: pip install tox==3.27.1 tox-factor
31+
32+
- name: Cache tox environment
33+
# Preserves .tox directory between runs for faster installs
34+
uses: actions/cache@v1
35+
with:
36+
path: |
37+
.tox
38+
~/.cache/pip
39+
key: v7-build-tox-cache-${{ inputs.python_version }}-${{ inputs.package_name }}-${{ inputs.os }}-${{ hashFiles('tox.ini', 'dev-requirements.txt') }}
40+
41+
- name: Run unit tests/benchmarks with tox
42+
if: ${{ inputs.python_version == 'true' }}
43+
shell: bash
44+
run: tox -f ${{ inputs.python_version }}-${{ inputs.package_name }} -- -ra --benchmark-json=${{ inputs.python_version }}-${{ inputs.package_name }}-${{ inputs.os }}-benchmark.json

.github/workflows/pr_build.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ jobs:
1717
build:
1818
runs-on: ubuntu-latest
1919
strategy:
20+
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
2021
matrix:
2122
python-version: ["3.8", "3.9", "3.10", "3.11"]
22-
tox-environment: ["spellcheck", "lint"]
2323
steps:
2424
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
2525
uses: actions/checkout@v4
2626

27-
- name: Install libsnappy-dev
28-
if: ${{ matrix.tox-environment == 'lint' }}
29-
run: sudo apt-get update && sudo apt-get install -y libsnappy-dev
30-
3127
- name: Build Wheel and Image Files
3228
uses: ./.github/actions/artifacts_build
3329
with:
@@ -41,11 +37,33 @@ jobs:
4137
package_name: aws-opentelemetry-distro
4238
os: ubuntu-latest
4339

44-
- name: run spell check tox
45-
run: tox -e ${{ matrix.tox-environment }}
46-
4740
- name: Set up and run contract tests with pytest
4841
run: |
4942
bash contract-tests/set-up-contract-tests.sh
5043
pip install pytest
51-
pytest contract-tests/tests
44+
pytest contract-tests/tests
45+
46+
lint:
47+
runs-on: ubuntu-latest
48+
strategy:
49+
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
50+
matrix:
51+
tox-environment: ["spellcheck", "lint"]
52+
steps:
53+
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
54+
uses: actions/checkout@v4
55+
56+
- name: Install libsnappy-dev
57+
if: ${{ matrix.tox-environment == 'lint' }}
58+
run: sudo apt-get update && sudo apt-get install -y libsnappy-dev
59+
60+
- name: Set up
61+
uses: ./.github/actions/set_up
62+
with:
63+
python_version: 3.11
64+
package_name: aws-opentelemetry-distro
65+
os: ubuntu-latest
66+
run_unit_tests: false
67+
68+
- name: Run ${{ matrix.tox-environment }} with tox
69+
run: tox -e ${{ matrix.tox-environment }}

contract-tests/images/applications/requests/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ WORKDIR /requests
66
COPY ./dist/$DISTRO /requests
77
COPY ./contract-tests/images/applications/requests /requests
88

9+
ENV PIP_ROOT_USER_ACTION=ignore
910
ARG DISTRO
10-
RUN pip install -r requirements.txt && pip install ${DISTRO} --force-reinstall
11+
RUN pip install --upgrade pip && pip install -r requirements.txt && pip install ${DISTRO} --force-reinstall
1112
RUN opentelemetry-bootstrap -a install
1213

1314
# Without `-u`, logs will be buffered and `wait_for_logs` will never return.

contract-tests/images/mock-collector/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ FROM public.ecr.aws/docker/library/python:3.11-slim
22
WORKDIR /mock-collector
33
COPY . /mock-collector
44

5-
RUN pip install -r requirements.txt
5+
ENV PIP_ROOT_USER_ACTION=ignore
6+
RUN pip install --upgrade pip && pip install -r requirements.txt
67

78
# Without `-u`, logs will be buffered and `wait_for_logs` will never return.
89
CMD ["python", "-u", "./mock_collector_server.py"]

contract-tests/tests/test/amazon/base/contract_test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def class_tear_down(cls) -> None:
7575

7676
@override
7777
def setUp(self) -> None:
78+
self.addCleanup(self.tear_down)
7879
application_networking_config: Dict[str, EndpointConfig] = {
7980
NETWORK_NAME: EndpointConfig(version="1.22", aliases=self.get_application_network_aliases())
8081
}
@@ -102,8 +103,7 @@ def setUp(self) -> None:
102103
self.mock_collector.get_container_host_ip(), self.mock_collector.get_exposed_port(_MOCK_COLLECTOR_PORT)
103104
)
104105

105-
@override
106-
def tearDown(self) -> None:
106+
def tear_down(self) -> None:
107107
try:
108108
_logger.info("Application stdout")
109109
_logger.info(self.application.get_logs()[0].decode())

0 commit comments

Comments
 (0)