Skip to content

Commit c0faa84

Browse files
authored
Enable integration test debugging (#69)
- moved integration_testing to tests/integration/host - moved gradle files to root so that commands can be run in the project root - moved unit_testing to test/unit - can debug via pycharm or vscode - generate a pytest report after each run - logs show up in the console and the test report - add ability to use pytest filters to select tests - add ability to filter out test configurations with cluster sizes that do not match an existing cluster
1 parent 31e7f1a commit c0faa84

File tree

104 files changed

+1237
-714
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+1237
-714
lines changed

Diff for: .github/workflows/integration_tests.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ jobs:
4545
echo "TEMP_AWS_SESSION_TOKEN=${creds[2]}" >> $GITHUB_ENV
4646
4747
- name: 'Run Integration Tests'
48-
working-directory: ${{ github.workspace }}/integration_testing
4948
run: |
5049
./gradlew --no-parallel --no-daemon test-all-environments --info
5150
env:
@@ -54,3 +53,11 @@ jobs:
5453
AWS_ACCESS_KEY_ID: ${{ env.TEMP_AWS_ACCESS_KEY_ID }}
5554
AWS_SECRET_ACCESS_KEY: ${{ env.TEMP_AWS_SECRET_ACCESS_KEY }}
5655
AWS_SESSION_TOKEN: ${{ env.TEMP_AWS_SESSION_TOKEN }}
56+
57+
- name: 'Archive results'
58+
if: always()
59+
uses: actions/upload-artifact@v3
60+
with:
61+
name: pytest-integration-report
62+
path: ./tests/integration/container/reports
63+
retention-days: 5

Diff for: .github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ jobs:
4545
- name: Run isort - dependency import sorting check
4646
run: poetry run isort --check-only .
4747
- name: Run unit tests
48-
run: poetry run python -m pytest ./unit_testing -Werror
48+
run: poetry run pytest ./tests/unit -Werror

Diff for: .gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ MANIFEST
3636
pip-log.txt
3737
pip-delete-this-directory.txt
3838

39-
# Unit test / coverage reports
39+
# Testing / coverage reports
4040
htmlcov/
4141
.tox/
4242
.nox/
@@ -50,6 +50,8 @@ coverage.xml
5050
.hypothesis/
5151
.pytest_cache/
5252
cover/
53+
tests/integration/container/reports
54+
tests/integration/host/bin
5355

5456
# Translations
5557
*.mo
@@ -155,6 +157,5 @@ cython_debug/
155157
.idea/
156158
.vs/
157159
.gradle/
158-
159160
**/.gradle
160-
integration_testing/bin
161+

Diff for: .vscode/launch.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Python: Debug test file",
6+
"type": "python",
7+
"request": "launch",
8+
"module": "pytest",
9+
"args": [
10+
"${file}"
11+
],
12+
"justMyCode": false
13+
},
14+
{
15+
"name": "Attach",
16+
"type": "python",
17+
"request": "attach",
18+
"pathMappings": [
19+
{
20+
"localRoot": "${workspaceFolder}",
21+
"remoteRoot": "/app"
22+
}
23+
],
24+
"connect": {
25+
"host": "localhost",
26+
"port": 5005
27+
}
28+
}
29+
]
30+
}

Diff for: .vscode/settings.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"python.linting.enabled": true,
44
"python.linting.flake8Enabled": true,
55
"python.testing.autoTestDiscoverOnSaveEnabled": true,
6-
"python.testing.cwd": "${workspaceFolder}/unit_testing",
7-
"python.testing.unittestEnabled": true,
8-
"python.testing.pytestEnabled": false,
6+
"python.testing.unittestEnabled": false,
7+
"python.testing.pytestEnabled": true,
8+
"python.testing.cwd": "${workspaceFolder}/tests/unit"
99
}

Diff for: aws_wrapper/__init__.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from logging import DEBUG, Formatter, Handler, StreamHandler, getLogger
15+
from logging import DEBUG, Handler, getLogger
1616

17+
from .utils.utils import LogUtils
1718
from .wrapper import AwsWrapperConnection
1819

1920
# PEP249 compliance
@@ -24,17 +25,7 @@
2425

2526

2627
def set_logger(name='aws_wrapper', level=DEBUG, format_string=None):
27-
if format_string is None:
28-
format_string = \
29-
"%(asctime)s.%(msecs)03d %(name)-12s:%(funcName)s [%(levelname)-8s] - %(threadName)s - %(message)s"
30-
31-
handler = StreamHandler()
32-
handler.setFormatter(Formatter(format_string))
33-
handler.setLevel(level)
34-
35-
logger = getLogger(name)
36-
logger.setLevel(level)
37-
logger.addHandler(handler)
28+
LogUtils.setup_logger(getLogger(name), level, format_string)
3829

3930

4031
class NullHandler(Handler):

Diff for: aws_wrapper/host_list_provider.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
from aws_wrapper.utils.rds_url_type import RdsUrlType
3939
from aws_wrapper.utils.rdsutils import RdsUtils
4040
from aws_wrapper.utils.timeout import timeout
41-
from aws_wrapper.utils.utils import Utils
41+
from aws_wrapper.utils.utils import LogUtils
4242

4343
logger = getLogger(__name__)
4444

@@ -344,15 +344,15 @@ def refresh(self, connection: Optional[Connection] = None) -> Tuple[HostInfo, ..
344344
self._initialize()
345345
connection = connection if connection else self._host_list_provider_service.current_connection
346346
topology = self._get_topology(connection, False)
347-
logger.debug(Utils.log_topology(topology.hosts))
347+
logger.debug(LogUtils.log_topology(topology.hosts))
348348
self._hosts = topology.hosts
349349
return tuple(self._hosts)
350350

351351
def force_refresh(self, connection: Optional[Connection] = None) -> Tuple[HostInfo, ...]:
352352
self._initialize()
353353
connection = connection if connection else self._host_list_provider_service.current_connection
354354
topology = self._get_topology(connection, True)
355-
logger.debug(Utils.log_topology(topology.hosts))
355+
logger.debug(LogUtils.log_topology(topology.hosts))
356356
self._hosts = topology.hosts
357357
return tuple(self._hosts)
358358

Diff for: aws_wrapper/utils/utils.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,29 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import sys
16+
from logging import DEBUG, Formatter, Logger, StreamHandler
1517
from queue import Empty, Queue
1618
from typing import Optional
1719

1820

19-
class Utils:
21+
class LogUtils:
22+
@staticmethod
23+
def setup_logger(logger: Logger, level: int = DEBUG, format_string: Optional[str] = None):
24+
for handler in logger.handlers:
25+
if isinstance(handler, StreamHandler):
26+
return
27+
28+
if format_string is None:
29+
format_string = \
30+
"%(asctime)s.%(msecs)03d %(name)-12s:%(funcName)s [%(levelname)-8s] - %(threadName)s - %(message)s"
31+
32+
handler = StreamHandler(stream=sys.stdout)
33+
handler.setFormatter(Formatter(format_string))
34+
handler.setLevel(level)
35+
36+
logger.setLevel(level)
37+
logger.addHandler(handler)
2038

2139
@staticmethod
2240
def log_topology(hosts: list, message_prefix: Optional[str] = None):
@@ -38,17 +56,6 @@ def log_topology(hosts: list, message_prefix: Optional[str] = None):
3856
return prefix + f"Topology: {{\n\t{msg}}}"
3957

4058

41-
class SubscribedMethodUtils:
42-
# TODO: check for missing network methods
43-
NETWORK_BOUND_METHODS = {
44-
"Connection.commit",
45-
"Connection.rollback",
46-
"Cursor.callproc",
47-
"Cursor.execute",
48-
"Cursor.executemany"
49-
}
50-
51-
5259
class QueueUtils:
5360
@staticmethod
5461
def get(q: Queue):

Diff for: aws_wrapper/writer_failover_handler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from typing import TYPE_CHECKING
1818

19+
from aws_wrapper import LogUtils
1920
from aws_wrapper.errors import AwsWrapperError
2021

2122
if TYPE_CHECKING:
@@ -35,7 +36,6 @@
3536
WriterFailoverResult)
3637
from aws_wrapper.hostinfo import HostAvailability, HostInfo, HostRole
3738
from aws_wrapper.utils.messages import Messages
38-
from aws_wrapper.utils.utils import Utils
3939

4040
logger = getLogger(__name__)
4141

@@ -238,7 +238,7 @@ def refresh_topology_and_connect_to_new_writer(self, initial_writer_host: HostIn
238238

239239
if not self.is_same(writer_candidate, initial_writer_host):
240240
# new writer available
241-
logger.debug(Utils.log_topology(self._current_topology, "[TaskB] "))
241+
logger.debug(LogUtils.log_topology(self._current_topology, "[TaskB] "))
242242

243243
if self.connect_to_writer(writer_candidate):
244244
return True

Diff for: integration_testing/gradlew renamed to gradlew

File renamed without changes.
File renamed without changes.

Diff for: integration_testing/settings.gradle.kts

-2
This file was deleted.

0 commit comments

Comments
 (0)