Skip to content

Commit

Permalink
all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
aappleby committed Mar 26, 2024
1 parent dc2ecc4 commit 5dbec3f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
12 changes: 9 additions & 3 deletions tests/job_count.hancho
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ import random
# Queues up 100 tasks that use random numbers of cores, then a "Job Hog" that uses all cores, then
# another batch of 100 tasks that use random numbers of cores.

rule = Rule(
build_config.defaults(
command_path = Path.cwd(),
source_path = Path.cwd(),
build_path = Path.cwd() / "build",
)

rule = build_config.rule(
desc = "I am task {index}, I use {job_count} cores",
command = "(exit 0)",
)

slow_rule = Rule(
slow_rule = build_config.rule(
desc = "********** I am the slow task, I eat all the cores **********",
command = "touch {files_out} && sleep 0.3",
command = "touch {rel_build_files} && sleep 0.3",
)

for i in range(100):
Expand Down
31 changes: 17 additions & 14 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,20 +252,23 @@ def test_cancellation(self):
self.assertFalse(Path("build/fail_result.txt").exists())
self.assertFalse(Path("build/should_not_be_created.txt").exists())

# def test_task_creates_task(self):
# """Tasks using callbacks can create new tasks when they run."""
# self.assertEqual(0, run_hancho("task_creates_task"))
# self.assertTrue(Path("build/dummy.txt").exists())
#
# def test_tons_of_tasks(self):
# """We should be able to queue up 1000+ tasks at once."""
# self.assertEqual(0, run_hancho("tons_of_tasks"))
# self.assertEqual(1000, len(glob.glob("build/*")))
#
# def test_job_count(self):
# """We should be able to dispatch tasks that require various numbers of jobs/cores."""
# self.assertEqual(0, run_hancho("job_count"))
# self.assertTrue(Path("build/slow_result.txt").exists())
def test_task_creates_task(self):
"""Tasks using callbacks can create new tasks when they run."""
result = run_hancho("task_creates_task")
self.assertEqual(0, result.returncode)
self.assertTrue(Path("build/dummy.txt").exists())

def test_tons_of_tasks(self):
"""We should be able to queue up 1000+ tasks at once."""
result = run_hancho("tons_of_tasks")
self.assertEqual(0, result.returncode)
self.assertEqual(1000, len(glob.glob("build/*")))

def test_job_count(self):
"""We should be able to dispatch tasks that require various numbers of jobs/cores."""
result = run_hancho("job_count")
self.assertEqual(0, result.returncode)
self.assertTrue(Path("build/slow_result.txt").exists())


################################################################################
Expand Down
12 changes: 9 additions & 3 deletions tests/task_creates_task.hancho
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
from hancho import *

rule1 = Rule(
command = "touch {files_out}"
build_config.defaults(
command_path = Path.cwd(),
source_path = Path.cwd(),
build_path = Path.cwd() / "build",
)

rule1 = build_config.rule(
command = "touch {rel_build_files}"
)

def callback(task):
rule1([], "dummy.txt")
return []

rule2 = Rule(
rule2 = build_config.rule(
command = callback
)

Expand Down
10 changes: 8 additions & 2 deletions tests/tons_of_tasks.hancho
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
from hancho import *

rule = Rule(
build_config.defaults(
command_path = Path.cwd(),
source_path = Path.cwd(),
build_path = Path.cwd() / "build",
)

rule = build_config.rule(
desc = "I am task {index}",
command = "echo {index} > {files_out}",
command = "echo {index} > {rel_build_files}",
)

for i in range(1000):
Expand Down

0 comments on commit 5dbec3f

Please sign in to comment.