mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
switch out recursive dfs for stack based approach, to avoid possibly hitting the recursion limit
This commit is contained in:
@@ -134,6 +134,21 @@ class GraphTests(TestCase):
|
||||
graph.forwards_plan, ("app_a", "0003"),
|
||||
)
|
||||
|
||||
def test_dfs(self):
|
||||
graph = MigrationGraph()
|
||||
root = ("app_a", "1")
|
||||
graph.add_node(root, None)
|
||||
expected = [root]
|
||||
for i in xrange(2, 1000):
|
||||
parent = ("app_a", str(i - 1))
|
||||
child = ("app_a", str(i))
|
||||
graph.add_node(child, None)
|
||||
graph.add_dependency(str(i), child, parent)
|
||||
expected.append(child)
|
||||
|
||||
actual = graph.dfs(root, lambda x: graph.dependents.get(x, set()))
|
||||
self.assertEqual(expected[::-1], actual)
|
||||
|
||||
def test_plan_invalid_node(self):
|
||||
"""
|
||||
Tests for forwards/backwards_plan of nonexistent node.
|
||||
|
||||
Reference in New Issue
Block a user