Skip to content
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

Refactor: Events: Clean up tests #10160

Merged
merged 15 commits into from Mar 26, 2024
Merged

Conversation

maxhoheiser
Copy link
Member

@maxhoheiser maxhoheiser commented Feb 1, 2024

Motivation

The current events tests are all defined in a single file .../events/test_events.py, including (except one) the fixtures not imported from ...fixtures.py. This makes it hard to read and add new tests especially grouping them to similar tests.

Change

  • extracted events tests specific fixtures into conftest.py file
  • separate tests targeting EventBus into a separate class
  • extracted events tests targeting rule testing into separate file tests_events_rules.py
  • extracted events tests specifically testing integration with additional services into separate file tests_events_integrations.py
  • extracted events testing input transformation e.g. InputPaths (and future InputTransformers) in to separate file tests_events_inputs.py, also separating InputPaths into a separate class to deal with future InputTransformers

Copy link

github-actions bot commented Feb 1, 2024

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 29m 23s ⏱️ - 2m 33s
2 721 tests ±0  2 466 ✅ ±0  255 💤 ±0  0 ❌ ±0 
2 723 runs  ±0  2 466 ✅ ±0  257 💤 ±0  0 ❌ ±0 

Results for commit 9ce2706. ± Comparison against base commit be903b2.

This pull request removes 49 and adds 49 tests. Note that renamed tests count towards both.
tests.aws.services.events.test_events.TestEvents ‑ test_create_rule_with_one_unit_in_singular_should_succeed[rate(1 day)]
tests.aws.services.events.test_events.TestEvents ‑ test_create_rule_with_one_unit_in_singular_should_succeed[rate(1 hour)]
tests.aws.services.events.test_events.TestEvents ‑ test_create_rule_with_one_unit_in_singular_should_succeed[rate(1 minute)]
tests.aws.services.events.test_events.TestEvents ‑ test_put_event_with_content_base_rule_in_pattern
tests.aws.services.events.test_events.TestEvents ‑ test_put_events_into_event_bus[domain]
tests.aws.services.events.test_events.TestEvents ‑ test_put_events_into_event_bus[path]
tests.aws.services.events.test_events.TestEvents ‑ test_put_events_into_event_bus[standard]
tests.aws.services.events.test_events.TestEvents ‑ test_put_events_nonexistent_event_bus
tests.aws.services.events.test_events.TestEvents ‑ test_put_events_to_default_eventbus_for_custom_eventbus
tests.aws.services.events.test_events.TestEvents ‑ test_put_events_with_input_path
…
tests.aws.services.events.test_events.TestEvents ‑ test_event_pattern
tests.aws.services.events.test_events.TestEventsEventBus ‑ test_put_events_into_event_bus[domain]
tests.aws.services.events.test_events.TestEventsEventBus ‑ test_put_events_into_event_bus[path]
tests.aws.services.events.test_events.TestEventsEventBus ‑ test_put_events_into_event_bus[standard]
tests.aws.services.events.test_events.TestEventsEventBus ‑ test_put_events_nonexistent_event_bus
tests.aws.services.events.test_events.TestEventsEventBus ‑ test_put_events_to_default_eventbus_for_custom_eventbus
tests.aws.services.events.test_events_inputs.TestEventsInputPath ‑ test_put_events_with_input_path
tests.aws.services.events.test_events_inputs.TestEventsInputPath ‑ test_put_events_with_input_path_multiple
tests.aws.services.events.test_events_inputs.TestEventsInputTransformers ‑ test_put_events_with_input_transformation_to_sqs
tests.aws.services.events.test_events_integrations ‑ test_put_events_with_target_firehose
…

♻️ This comment has been updated with latest results.

@maxhoheiser maxhoheiser force-pushed the refactor/events/clean-up-tests branch 4 times, most recently from 93ff37c to bfaf207 Compare February 7, 2024 09:13
@maxhoheiser maxhoheiser force-pushed the refactor/events/clean-up-tests branch 3 times, most recently from e4d061d to d5bdfb2 Compare February 8, 2024 17:09
@maxhoheiser maxhoheiser self-assigned this Feb 8, 2024
@maxhoheiser maxhoheiser added the aws:events Amazon EventBridge label Feb 8, 2024
@maxhoheiser maxhoheiser force-pushed the refactor/events/clean-up-tests branch 2 times, most recently from e823011 to d802fb7 Compare February 8, 2024 17:18
@maxhoheiser maxhoheiser added type: feature New feature, or improvement to an existing feature semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases labels Feb 8, 2024
@coveralls
Copy link

coveralls commented Feb 8, 2024

Coverage Status

coverage: 83.861% (-0.02%) from 83.877%
when pulling 80d1a0c on refactor/events/clean-up-tests
into e2faf69 on master.

@maxhoheiser maxhoheiser added this to the 3.2 milestone Feb 19, 2024
@maxhoheiser maxhoheiser modified the milestones: 3.2, 3.3 Feb 27, 2024
@maxhoheiser maxhoheiser marked this pull request as ready for review March 19, 2024 18:11
Copy link
Member

@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea 💡

Refactoring tests can by definition not change any behavior, therefore this PR should have the semver label patch. The label feature also does not apply here.

Given that re-grouping is the main contribution of this PR, it would make sense to write a short docstring description at the top of the new test files to clarify the separation. Examples from Lambda:

So many unvalidated tests 😅 We have a mission 📈



def sqs_collect_messages(
aws_client,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you remove the typings "SQSClient" deliberately?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I moved it to use the aws_client directly to keep it in line with how we generally call boto clients.

@markers.aws.unknown
def test_put_events_with_values_in_array(self, aws_client, put_events_with_filter_to_sqs):
def test_put_events_with_values_in_array(sef, put_events_with_filter_to_sqs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: self

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in: bf0255f

tests/aws/services/events/test_events.py Show resolved Hide resolved
@@ -1,6 +1,87 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This snapshot file still contains some tests moved into other files. For example: tests/aws/services/events/test_events.py::TestEvents::test_put_rule. These should be removed. We don't have good tooling for maintaining snapshots during refactorings.

For such refactorings: I typically just delete the snapshot and validations files and re-create all snapshots from scratch.

assert put_response["FailedEntryCount"] == 0
assert put_response["FailedEntries"] == []

def check_stream_status():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea for later: Such waiters seem quite common in our test suite. We could consider adding a re-usable helper or even waiter (Dominik demoed how the boto waiters can be extended).


message_body = json.loads(messages[0]["Body"])
assert message_body["time"] == "2022-01-01T00:00:00Z"


class TestEventsInputTransformers:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good example to think where it belongs to:

  • Would input transformers fit into test_events_inputs?
  • Different integrations have different transformer behavior?
  • Or here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in: 8fa25b3

@maxhoheiser maxhoheiser added semver: patch Non-breaking changes which can be included in patch releases and removed type: feature New feature, or improvement to an existing feature labels Mar 25, 2024
@maxhoheiser maxhoheiser removed the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label Mar 26, 2024
@maxhoheiser maxhoheiser force-pushed the refactor/events/clean-up-tests branch from af485bf to b13ca25 Compare March 26, 2024 16:10
@maxhoheiser maxhoheiser merged commit 26d849f into master Mar 26, 2024
29 checks passed
@maxhoheiser maxhoheiser deleted the refactor/events/clean-up-tests branch March 26, 2024 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:events Amazon EventBridge semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants