Skip to content

Commit

Permalink
Merge pull request web2py#1498 from niphlod/fix/1491
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro authored Oct 14, 2016
2 parents d15d0e6 + 87489f3 commit bc72324
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gluon/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def run(
die(errmsg)

if f:
exec('print %s()' % f, _env)
exec('print( %s())' % f, _env)
return

_env.update(exec_pythonrc())
Expand Down
42 changes: 34 additions & 8 deletions gluon/tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,14 +601,21 @@ def inner_teardown(self):
fdest = os.path.join(current.request.folder, 'models', 'scheduler.py')
os.unlink(fdest)
additional_files = [
os.path.join(current.request.folder, 'private', 'demo8.pholder')
os.path.join(current.request.folder, 'private', 'demo8.pholder'),
os.path.join(current.request.folder, 'views', 'issue_1485_2.html'),
]
for f in additional_files:
try:
os.unlink(f)
except:
pass

def writeview(self, content, dest=None):
from gluon import current
fdest = os.path.join(current.request.folder, 'views', dest)
with open(fdest, 'w') as q:
q.write(content)

def writefunction(self, content, initlines=None):
from gluon import current
fdest = os.path.join(current.request.folder, 'models', 'scheduler.py')
Expand All @@ -620,6 +627,9 @@ def writefunction(self, content, initlines=None):
db_dal = os.path.abspath(os.path.join(request.folder, '..', '..', 'dummy2.db'))
sched_dal = DAL('sqlite://%s' % db_dal, folder=os.path.dirname(db_dal))
sched = Scheduler(sched_dal, max_empty_runs=15, migrate=False, heartbeat=1)
def termination():
sched.terminate()
sched_dal.commit()
"""
with open(fdest, 'w') as q:
q.write(initlines)
Expand Down Expand Up @@ -699,10 +709,11 @@ def testNoReturn_and_Timeout_and_Progress(self):
timeout1 = s.queue_task('demo4', timeout=5)
timeout2 = s.queue_task('demo4')
progress = s.queue_task('demo6', sync_output=2)
termination = s.queue_task('termination')
self.db.commit()
self.writefunction(r"""
def demo3():
time.sleep(15)
time.sleep(3)
print(1/0)
return None
Expand All @@ -712,7 +723,7 @@ def demo4():
return dict(a=1, b=2)
def demo5():
time.sleep(15)
time.sleep(3)
print("I'm printing something")
rtn = dict(a=1, b=2)
Expand Down Expand Up @@ -758,6 +769,7 @@ def testDrift_and_env_and_immediate(self):
immediate = s.queue_task('demo1', ['a', 'b'], dict(c=1, d=2), immediate=True)
env = s.queue_task('demo7')
drift = s.queue_task('demo1', ['a', 'b'], dict(c=1, d=2), period=93, prevent_drift=True)
termination = s.queue_task('termination')
self.db.commit()
self.writefunction(r"""
def demo1(*args,**vars):
Expand Down Expand Up @@ -844,27 +856,41 @@ def demo8():
]
self.exec_asserts(res, 'FAILED_CONSECUTIVE')

def testHugeResult(self):
def testRegressions(self):
s = Scheduler(self.db)
huge_result = s.queue_task('demo10', retry_failed=1, period=1)
issue_1485 = s.queue_task('issue_1485')
termination = s.queue_task('termination')
self.db.commit()
self.writefunction(r"""
def demo10():
res = 'a' * 99999
return dict(res=res)
def issue_1485():
return response.render('issue_1485.html', dict(variable='abc'))
""")
self.writeview(r"""<span>{{=variable}}</span>""", 'issue_1485.html')
ret = self.exec_sched()
# process finished just fine
self.assertEqual(ret, 0)
# huge_result - checks
task = s.task_status(huge_result.id, output=True)
task_huge = s.task_status(huge_result.id, output=True)
res = [
("task status completed", task.scheduler_task.status == 'COMPLETED'),
("task times_run is 1", task.scheduler_task.times_run == 1),
("result is the correct one", task.result == dict(res='a' * 99999))
("task status completed", task_huge.scheduler_task.status == 'COMPLETED'),
("task times_run is 1", task_huge.scheduler_task.times_run == 1),
("result is the correct one", task_huge.result == dict(res='a' * 99999))
]
self.exec_asserts(res, 'HUGE_RESULT')

task_issue_1485 = s.task_status(issue_1485.id, output=True)
res = [
("task status completed", task_issue_1485.scheduler_task.status == 'COMPLETED'),
("task times_run is 1", task_issue_1485.scheduler_task.times_run == 1),
("result is the correct one", task_issue_1485.result == '<span>abc</span>')
]
self.exec_asserts(res, 'issue_1485')


if __name__ == '__main__':
unittest.main()

0 comments on commit bc72324

Please sign in to comment.