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

Quick calculations don't increment node counter #310

Merged
merged 1 commit into from
Aug 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions webapp/apps/taxbrain/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ def submit_dropq_calculation(self, mods, first_budget_year):
def submit_dropq_small_calculation(self, mods, first_budget_year):
url_template = "http://{hn}" + DROPQ_SMALL_URL
return self.submit_calculation(mods, first_budget_year, url_template,
num_years=NUM_BUDGET_YEARS_QUICK)
num_years=NUM_BUDGET_YEARS_QUICK,
increment_counter=False)

def submit_elastic_calculation(self, mods, first_budget_year):
url_template = "http://{hn}/elastic_gdp_start_job"
return self.submit_calculation(mods, first_budget_year, url_template,
start_budget_year=1)

def submit_calculation(self, mods, first_budget_year, url_template,
start_budget_year=0, num_years=NUM_BUDGET_YEARS):
start_budget_year=0, num_years=NUM_BUDGET_YEARS,
increment_counter=True):
print "mods is ", mods
user_mods = package_up_vars(mods, first_budget_year)
if not bool(user_mods):
Expand All @@ -78,8 +80,9 @@ def submit_calculation(self, mods, first_budget_year, url_template,
dropq_worker_offset = wnc.current_offset
if dropq_worker_offset > len(DROPQ_WORKERS):
dropq_worker_offset = 0
wnc.current_offset = (dropq_worker_offset + num_years) % len(DROPQ_WORKERS)
wnc.save()
if increment_counter:
wnc.current_offset = (dropq_worker_offset + num_years) % len(DROPQ_WORKERS)
wnc.save()
hostnames = DROPQ_WORKERS[dropq_worker_offset: dropq_worker_offset + num_years]
print "hostnames: ", hostnames
num_hosts = len(hostnames)
Expand Down
11 changes: 10 additions & 1 deletion webapp/apps/taxbrain/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.test import Client
import mock

from ..models import TaxSaveInputs, OutputUrl
from ..models import TaxSaveInputs, OutputUrl, WorkerNodesCounter
from ..models import convert_to_floats
from ..helpers import (expand_1D, expand_2D, expand_list, package_up_vars,
format_csv, arrange_totals_by_row, default_taxcalc_data)
Expand Down Expand Up @@ -70,6 +70,9 @@ def test_taxbrain_quick_calc_post(self):
u'start_year': unicode(START_YEAR), 'csrfmiddlewaretoken':'abc123',
u'quick_calc': 'Quick Calculation!'}

wnc, created = WorkerNodesCounter.objects.get_or_create(singleton_enforce=1)
current_dropq_worker_offset = wnc.current_offset

response = self.client.post('/taxbrain/', data)
# Check that redirect happens
self.assertEqual(response.status_code, 302)
Expand All @@ -82,6 +85,12 @@ def test_taxbrain_quick_calc_post(self):
# Check that we only retrieve one year of results
self.assertEqual(webapp_views.dropq_compute.count, 1)

wnc, created = WorkerNodesCounter.objects.get_or_create(singleton_enforce=1)
next_dropq_worker_offset = wnc.current_offset
# Check that quick calc does not advance the counter
self.assertEqual(current_dropq_worker_offset, next_dropq_worker_offset)



def test_taxbrain_post_no_behavior_entries(self):
#Monkey patch to mock out running of compute jobs
Expand Down