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

Use threads instead of processes in test_pocs.py #468

Merged
merged 2 commits into from
Feb 11, 2018

Conversation

jamessynge
Copy link
Contributor

Run pocs in a thread instead of in a separate process to make it easier
to share resources between the test thread and pocs. This was motivated
by PanMemoryDB, but I think it will help in general.

Add a Timeout class to pocs.utils and use in test_pocs to force the
ending of long running tests.

Shutdown pocs even if message not received; use a try-finally block
to ensure we send the shutdown message.

Run pocs in a thread instead of in a separate process to make it easier
to share resources between the test thread and pocs. This was motivated
by PanMemoryDB, but I think it will help in general.

Add a Timeout class to pocs.utils and use in test_pocs to force the
ending of long running tests.

Shutdown pocs even if message not received; use a try-finally block
to ensure we send the shutdown message.
@jamessynge jamessynge requested a review from wtgee February 10, 2018 20:39
@codecov
Copy link

codecov bot commented Feb 10, 2018

Codecov Report

Merging #468 into develop will decrease coverage by 0.11%.
The diff coverage is 73.68%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #468      +/-   ##
===========================================
- Coverage    67.64%   67.53%   -0.12%     
===========================================
  Files           63       63              
  Lines         5306     5328      +22     
  Branches       737      740       +3     
===========================================
+ Hits          3589     3598       +9     
- Misses        1520     1528       +8     
- Partials       197      202       +5
Impacted Files Coverage Δ
pocs/utils/__init__.py 83.95% <73.68%> (-3.15%) ⬇️
pocs/state/states/default/pointing.py 65.3% <0%> (-10.21%) ⬇️
pocs/utils/logger.py 85.71% <0%> (-3.84%) ⬇️
pocs/observatory.py 71.7% <0%> (-0.28%) ⬇️
pocs/state/machine.py 88.96% <0%> (+0.68%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d9dff6c...b9605df. Read the comment docs.

Copy link
Member

@wtgee wtgee left a comment

Choose a reason for hiding this comment

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

Seems like you are going to have some clashes with #463 and I can't tell if this is to pull out features of that or augment it. Maybe the Timeout should just have it's own PR first?

return False


def wait_for_pointing(sub, max_duration=90):
Copy link
Member

Choose a reason for hiding this comment

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

The MemoryDB PR has a note about perhaps changing which state we check for so we don't run through scheduling.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, I've incorporated that in this branch, pushing in a few minutes.

if self.is_non_blocking:
return 0
else:
delta = self.target_time - time.monotonic()
Copy link
Member

Choose a reason for hiding this comment

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

Am I missing something about where these come from? Should this class inherit from serialutil.Timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to just copy their code and eliminate things we don't need. time.monotonic() is like time.time(), but guarantees that it won't go backwards.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I didn't realize target_time first gets set in the restart method so didn't see where it was coming from. Makes sense now.

Copy link
Member

Choose a reason for hiding this comment

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

Although maybe just start is a better name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

restart because init calls it, so that it is started at creation. If too confusing, I could remove restart, so you have to create a new instance each time, which is definitely the common way to use it.

class Timeout(object):
"""Simple timer object for tracking whether a time duration has elapsed.

Attribute `is_non_blocking` is true IFF the duration is zero.
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand where non-blocking case. Where would you be using a timeout=0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, timeout==0 means that it will always be considered to have expired.

@jamessynge
Copy link
Contributor Author

This change is really about simplifying #463 which had gotten too large, reflecting the various bugs I found along the while debugging use of the memory db.

Use hardware module to get the list of simulator names, minus 'weather'.

Wait for pocs thread to stop even if an assertion has failed, to avoid
having two running at once (i.e. if the next test starts while the
previous test's thread is still running).
Copy link
Member

@wtgee wtgee left a comment

Choose a reason for hiding this comment

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

LGTM

if self.is_non_blocking:
return 0
else:
delta = self.target_time - time.monotonic()
Copy link
Member

Choose a reason for hiding this comment

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

Ok, I didn't realize target_time first gets set in the restart method so didn't see where it was coming from. Makes sense now.

if self.is_non_blocking:
return 0
else:
delta = self.target_time - time.monotonic()
Copy link
Member

Choose a reason for hiding this comment

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

Although maybe just start is a better name?

@jamessynge jamessynge merged commit 42d62a5 into panoptes:develop Feb 11, 2018
@jamessynge jamessynge deleted the test_pocs_threaded branch February 11, 2018 01:59
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.

2 participants