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

Test for pull request #304 (Added try-catch to notification close in symbol destructor) #369

Merged
merged 5 commits into from
Jul 30, 2024

Conversation

chhinze
Copy link
Contributor

@chhinze chhinze commented Feb 8, 2024

This is an extension to #304 (fixing #303) adding a test for the specific behavior. I have this problem repeatedly, when using auto_update=true for AdsSymbols and the server disconnects and, afterwards the AdsSymbols instances get garbage-collected.

I would love to see pull request #304 merged, so I added the requested test. The additional commit is directly added on top of the commit in the branch in #304. Without the try-catch in #304 the test fails. I hope the test is useful.

Is this what you had in mind @stlehmann?

@chhinze chhinze changed the title Bugfix/adssymbol del Test for pull request #304 (Added try-catch to notification close in symbol destructor) Feb 9, 2024
@RobertoRoos
Copy link
Contributor

RobertoRoos commented Jul 24, 2024

Stumbling across this again. Issue #303 is still relevant, thanks @chhinze for adding a test!

@stlehmann could we merge this?
I'm not sure if there are other maintainers too, @chrisbeardy maybe?

Comment on lines 72 to 90
raised_error: str = ""

try:
# 4. stop the test server
test_server.stop()
time.sleep(0.1) # Give server a moment

# some code, where test_int is cleared by the Garbage collector after the server was stopped
# (e.g. the machine with ADS Server disconnected)
# this raised an ADSError up to commit [a7af674](https://github.com/stlehmann/pyads/tree/a7af674b49b1c91966f2bac1f00f86273cbd9af8)
# `clear_device_notifications()` failed, if not wrapped in try-catch as the server is no longer present.
test_int.__del__()
except pyads.ADSError as e:
raised_error = str(e)

# check no error was raised:
self.assertTrue(
not raised_error, f"Closing server connection raised: {raised_error}"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you could be bothered, I find something like:

test_server.stop()
time.sleep(0.1)  # Give server a moment

try:
    test_int.__del__()
except ExceptionType as err:
    self.fail(f"Closing server connection raised: {raised_error}")

more neat (see SO).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I would be happy to consider your suggestions. Just to be clear: do you mean by the comment that you find the comments too cluttering, or do you refer to the self.assertTrue(...) check, or both?

Copy link
Contributor

@RobertoRoos RobertoRoos Jul 25, 2024

Choose a reason for hiding this comment

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

No, your in-code comments are fine. I mean the way of asserting an exception does not get raised. I think the except self.fail(...) is cleaner than an self.assert... after the clause.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for pointing it out and for the clarification. I changed it now with the recent commit cbff3e8.

@chrisbeardy
Copy link
Collaborator

I have some plans this week or next to take a look at some of the Open PRs, as I have a few that I have "marked" in my own head as ready to merge so was going to spend some time doing it.

# `clear_device_notifications()` failed, if not wrapped in try-catch as the server is no longer present.
test_int.__del__()
except pyads.ADSError as e:
self.fail(not raised_error, f"Closing server connection raised: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for updating. The syntax isn't correct though, self.fail() doesn't take in a verification parameter, only the string message:

self.fail(f"Closing server connection raised: {e}")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry and thanks for spotting the mistake. I updated it now and specifically tested again that it raises corectly for pre #303 code (without try except-wrapped in AdsSymbol.__del__()).

Use self.fail() now instead of self.assert().
Thanks to @RobtertoRoos for pointing it out.
@chhinze chhinze force-pushed the bugfix/adssymbol_del branch from cbff3e8 to 22d0318 Compare July 25, 2024 14:51
@chrisbeardy chrisbeardy merged commit 3e08041 into stlehmann:master Jul 30, 2024
4 checks passed
@coveralls
Copy link

Pull Request Test Coverage Report for Build 10158424620

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.8%) to 95.133%

Totals Coverage Status
Change from base Build 10158401621: 0.8%
Covered Lines: 1720
Relevant Lines: 1808

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants