daemon: modified node service boot to properly order services and account for services with the same dependency without cycles, for now removed trying to simultaneously booting services
This commit is contained in:
parent
3e41d31c6c
commit
936d782e41
2 changed files with 129 additions and 166 deletions
|
@ -1,3 +1,4 @@
|
|||
import itertools
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
@ -15,40 +16,6 @@ SERVICE_ONE = "MyService"
|
|||
SERVICE_TWO = "MyService2"
|
||||
|
||||
|
||||
class ServiceA(CoreService):
|
||||
name = "A"
|
||||
dependencies = ("B",)
|
||||
|
||||
|
||||
class ServiceB(CoreService):
|
||||
name = "B"
|
||||
dependencies = ()
|
||||
|
||||
|
||||
class ServiceC(CoreService):
|
||||
name = "C"
|
||||
dependencies = ("B", "D")
|
||||
|
||||
|
||||
class ServiceD(CoreService):
|
||||
name = "D"
|
||||
dependencies = ()
|
||||
|
||||
|
||||
class ServiceBadDependency(CoreService):
|
||||
name = "E"
|
||||
dependencies = ("Z",)
|
||||
|
||||
|
||||
class ServiceF(CoreService):
|
||||
name = "F"
|
||||
dependencies = ()
|
||||
|
||||
|
||||
class ServiceCycleDependency(CoreService):
|
||||
name = "G"
|
||||
|
||||
|
||||
class TestServices:
|
||||
def test_service_all_files(self, session: Session):
|
||||
# given
|
||||
|
@ -255,35 +222,95 @@ class TestServices:
|
|||
|
||||
def test_services_dependencies(self):
|
||||
# given
|
||||
services = [ServiceA, ServiceB, ServiceC, ServiceD, ServiceF]
|
||||
service_a = CoreService()
|
||||
service_a.name = "a"
|
||||
service_b = CoreService()
|
||||
service_b.name = "b"
|
||||
service_c = CoreService()
|
||||
service_c.name = "c"
|
||||
service_d = CoreService()
|
||||
service_d.name = "d"
|
||||
service_e = CoreService()
|
||||
service_e.name = "e"
|
||||
service_a.dependencies = (service_b.name,)
|
||||
service_b.dependencies = ()
|
||||
service_c.dependencies = (service_b.name, service_d.name)
|
||||
service_d.dependencies = ()
|
||||
service_e.dependencies = ()
|
||||
services = [service_a, service_b, service_c, service_d, service_e]
|
||||
|
||||
# when
|
||||
boot_paths = ServiceDependencies(services).boot_paths()
|
||||
results = []
|
||||
permutations = itertools.permutations(services)
|
||||
for permutation in permutations:
|
||||
permutation = list(permutation)
|
||||
result = ServiceDependencies(permutation).boot_order()
|
||||
results.append(result)
|
||||
|
||||
# then
|
||||
assert len(boot_paths) == 2
|
||||
for result in results:
|
||||
assert len(result) == len(services)
|
||||
|
||||
def test_services_dependencies_not_present(self):
|
||||
def test_services_missing_dependency(self):
|
||||
# given
|
||||
services = [
|
||||
ServiceA,
|
||||
ServiceB,
|
||||
ServiceC,
|
||||
ServiceD,
|
||||
ServiceF,
|
||||
ServiceBadDependency,
|
||||
]
|
||||
service_a = CoreService()
|
||||
service_a.name = "a"
|
||||
service_b = CoreService()
|
||||
service_b.name = "b"
|
||||
service_c = CoreService()
|
||||
service_c.name = "c"
|
||||
service_a.dependencies = (service_b.name,)
|
||||
service_b.dependencies = (service_c.name,)
|
||||
service_c.dependencies = ("d",)
|
||||
services = [service_a, service_b, service_c]
|
||||
|
||||
# when, then
|
||||
with pytest.raises(ValueError):
|
||||
ServiceDependencies(services).boot_paths()
|
||||
permutations = itertools.permutations(services)
|
||||
for permutation in permutations:
|
||||
permutation = list(permutation)
|
||||
with pytest.raises(ValueError):
|
||||
ServiceDependencies(permutation).boot_order()
|
||||
|
||||
def test_services_dependencies_cycle(self):
|
||||
# given
|
||||
service_d = ServiceD()
|
||||
service_d.dependencies = ("C",)
|
||||
services = [ServiceA, ServiceB, ServiceC, service_d, ServiceF]
|
||||
service_a = CoreService()
|
||||
service_a.name = "a"
|
||||
service_b = CoreService()
|
||||
service_b.name = "b"
|
||||
service_c = CoreService()
|
||||
service_c.name = "c"
|
||||
service_a.dependencies = (service_b.name,)
|
||||
service_b.dependencies = (service_c.name,)
|
||||
service_c.dependencies = (service_a.name,)
|
||||
services = [service_a, service_b, service_c]
|
||||
|
||||
# when, then
|
||||
with pytest.raises(ValueError):
|
||||
ServiceDependencies(services).boot_paths()
|
||||
permutations = itertools.permutations(services)
|
||||
for permutation in permutations:
|
||||
permutation = list(permutation)
|
||||
with pytest.raises(ValueError):
|
||||
ServiceDependencies(permutation).boot_order()
|
||||
|
||||
def test_services_common_dependency(self):
|
||||
# given
|
||||
service_a = CoreService()
|
||||
service_a.name = "a"
|
||||
service_b = CoreService()
|
||||
service_b.name = "b"
|
||||
service_c = CoreService()
|
||||
service_c.name = "c"
|
||||
service_b.dependencies = (service_a.name,)
|
||||
service_c.dependencies = (service_a.name, service_b.name)
|
||||
services = [service_a, service_b, service_c]
|
||||
|
||||
# when
|
||||
results = []
|
||||
permutations = itertools.permutations(services)
|
||||
for permutation in permutations:
|
||||
permutation = list(permutation)
|
||||
result = ServiceDependencies(permutation).boot_order()
|
||||
results.append(result)
|
||||
|
||||
# then
|
||||
for result in results:
|
||||
assert result == [service_a, service_b, service_c]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue