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

AWS utils: Add unit tests for restart_workers #2604

Closed

Conversation

nikochiko
Copy link
Contributor

@nikochiko nikochiko commented Jan 10, 2020

Changes proposed in this PR:

  • Add tests for aws_utils.restart_workers
  • Mock the intermediate function service_manager

Reference PR: #2413

@codecov-io
Copy link

codecov-io commented Jan 10, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@c2c1a30). Click here to learn what that means.
The diff coverage is n/a.

@@            Coverage Diff            @@
##             master    #2604   +/-   ##
=========================================
  Coverage          ?   73.82%           
=========================================
  Files             ?       82           
  Lines             ?     5338           
  Branches          ?        0           
=========================================
  Hits              ?     3941           
  Misses            ?     1397           
  Partials          ?        0
Impacted Files Coverage Δ
apps/challenges/aws_utils.py 39.89% <ø> (ø)
Impacted Files Coverage Δ
apps/challenges/aws_utils.py 39.89% <ø> (ø)

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 c2c1a30...992b59e. Read the comment docs.

@nikochiko nikochiko changed the title aws_utils: Add unit tests for restart_workers AWS utils: Add unit tests for restart_workers Jan 10, 2020
tests/unit/challenges/test_aws_utils.py Show resolved Hide resolved
end_date=timezone.now() + timedelta(days=1),
)
self.ecs_client.create_cluster(clusterName="cluster")
self.client_token = "abc123"
Copy link
Member

Choose a reason for hiding this comment

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

@nikochiko can we use a randomly generated string here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍

queryset = super(TestRestartWorkers, self).queryset(pklist)

expected_count = 3
expected_num_of_workers = [1, 1, 1]
Copy link
Member

Choose a reason for hiding this comment

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

Can this 1 be declared as a class variable so that we can use the variable name where needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ram81 I think it is better if we keep it this way. As it states the number of workers and could be any number (0, 1, 2, 3, etc.) the number of variables would be too much to handle.
What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

@nikochiko but the number is based on the number of challenges right? so can't we use that to compute the number of workers?

Copy link
Member

Choose a reason for hiding this comment

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

Also as I can see in the code above you are setting the number of workers for every challenge. So I think we can just create 1 variable with a value that can be used in both setting the number of worker and using that in expected_num_of_workers. Let me know if this makes sense

Copy link
Contributor Author

@nikochiko nikochiko Jan 12, 2020

Choose a reason for hiding this comment

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

@Ram81 Okay, I think that makes sense now. So let me know if I have the right idea:

# in setup
self.no_active_workers = 0
self.one_active_worker = 1

# in tests
self.set_challenge_worker(self.challenge, self.one_active_worker)
expected_num_of_workers = [self.one_active_worker, self.one_active_worker, self.no_active_worker] # For [1, 1, 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.

but the number is based on the number of challenges right? so can't we use that to compute the number of workers?

I'm sorry I didn't get what you meant by computing the number of workers. Can you please elaborate?

Copy link
Contributor Author

@nikochiko nikochiko Jan 12, 2020

Choose a reason for hiding this comment

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

If you are referring to computing the expected_count, I want to clarify that it is only the number of workers successfully restarted and not the number of active workers. It can be different for example in this case: https://github.com/Cloud-CV/EvalAI/pull/2604/files#diff-cc74cf6292b78dc74ea17124c792900eR194-R195

queryset = super(TestRestartWorkers, self).queryset(pklist)

expected_count = 2
expected_num_of_workers = [0, 1, 1]
Copy link
Member

Choose a reason for hiding this comment

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

Same here

pklist = [self.challenge.pk, self.challenge2.pk, self.challenge3.pk]
queryset = super(TestRestartWorkers, self).queryset(pklist)

expected_count = 2
Copy link
Member

Choose a reason for hiding this comment

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

Same here

tests/unit/challenges/test_aws_utils.py Outdated Show resolved Hide resolved
queryset = super(TestRestartWorkers, self).queryset(pklist)

expected_count = 3
expected_num_of_workers = [1, 1, 1]
Copy link
Member

Choose a reason for hiding this comment

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

@nikochiko but the number is based on the number of challenges right? so can't we use that to compute the number of workers?

queryset = super(TestRestartWorkers, self).queryset(pklist)

expected_count = 3
expected_num_of_workers = [1, 1, 1]
Copy link
Member

Choose a reason for hiding this comment

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

Also as I can see in the code above you are setting the number of workers for every challenge. So I think we can just create 1 variable with a value that can be used in both setting the number of worker and using that in expected_num_of_workers. Let me know if this makes sense

from rest_framework.test import APITestCase, APIClient

import challenges.aws_utils as aws_utils
from challenges.models import Challenge
Copy link
Member

Choose a reason for hiding this comment

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

@nikochiko please reorder all imports lexicographically. Another thing all from imports should come at last and all the direct import statements should be at start. Your lines 5-7 are correct but all from imports should be considered together to order lexicographically

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! 👍 Please see if it is okay now.

@yashdusing
Copy link
Contributor

LGTM 👍

@KhalidRmb
Copy link
Member

@yashdusing Could you comment here what the error was with the deploymentController? I can't find your comment. Thanks!

@yashdusing
Copy link
Contributor

yashdusing commented Jan 14, 2020

@KhalidRmb I thought it had to do with braces and unpacking. But, after inspecting the logs, I inferred that botocore was being reinstalled to a lower version after awscli was installed (only in Travis). The previous versions of botocore did not have provisions for deploymentController which was causing the issues.

@KhalidRmb
Copy link
Member

Oh...Thanks for the catch! @yashdusing

@nikochiko
Copy link
Contributor Author

@yashdusing Thanks for the fix, nice catch! 👌🎉

@stale
Copy link

stale bot commented Mar 14, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the inactivity label Mar 14, 2020
@stale
Copy link

stale bot commented Mar 21, 2020

This pull request has been automatically closed as there is no further activity. Thank you for your contributions.

@stale stale bot closed this Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants