Skip to content

Commit

Permalink
adding tests and CLI check for 0 or less input for duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Tushman committed Dec 2, 2014
1 parent ab26d5e commit 41a11d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions rq/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,13 @@ def worker(url, config, burst, name, worker_class, job_class, queue_class, path,
@click.option('--duration', help='Seconds you want the workers to be suspended. Default is forever.', type=int)
def suspend(url, config, duration):
"""Suspends all workers, to resume run `rq resume`"""
if duration is not None and duration < 1:
click.echo("Duration must be an integer greater than 1")
sys.exit(1)

connection = connect(url, config)
connection_suspend(connection, duration)

if duration:
msg = """Suspending workers for {} seconds. No new jobs will be started during that time, but then will
automatically resume""".format(duration)
Expand Down
13 changes: 12 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,20 @@ def test_suspend_with_ttl(self):
"""rq suspend -u <url> --duration=2
"""
runner = CliRunner()
result = runner.invoke(main, ['suspend', '-u', self.redis_url, '--duration', 2])
result = runner.invoke(main, ['suspend', '-u', self.redis_url, '--duration', 1])
self.assert_normal_execution(result)

def test_suspend_with_invalid_ttl(self):
"""rq suspend -u <url> --duration=0
"""
runner = CliRunner()
result = runner.invoke(main, ['suspend', '-u', self.redis_url, '--duration', 0])

self.assertEqual(result.exit_code, 1)
self.assertIn("Duration must be an integer greater than 1", result.output)






0 comments on commit 41a11d0

Please sign in to comment.