X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=test%2Fexecution%2Fresource.py;h=bb1de3eadf944073498d68b5ba5c68b153fe38a7;hb=6a8c7da45f7d745ea47c5020b13dfb8ada0931db;hp=74e560e0454ad4867cd5d5274243c1aba5ed4d9a;hpb=97f98e73d96e1e3106ba62f7a29f2ff7353e4c95;p=nepi.git diff --git a/test/execution/resource.py b/test/execution/resource.py index 74e560e0..bb1de3ea 100755 --- a/test/execution/resource.py +++ b/test/execution/resource.py @@ -23,6 +23,7 @@ from nepi.execution.attribute import Attribute from nepi.execution.ec import ExperimentController from nepi.execution.resource import ResourceManager, ResourceState, clsinit +import random import time import unittest @@ -126,9 +127,15 @@ class Application(ResourceManager): if node.state < ResourceState.READY: self.ec.schedule("0.5s", self.deploy) else: + time.sleep(random.random() * 5) super(Application, self).deploy() self.logger.debug(" -------- DEPLOYED ------- ") + def start(self): + super(Application, self).start() + time.sleep(random.random() * 5) + self._state = ResourceState.FINISHED + class ResourceManagerTestCase(unittest.TestCase): def test_deploy_in_order(self): """ @@ -169,10 +176,8 @@ class ResourceManagerTestCase(unittest.TestCase): ec.deploy() - while not all([ ec.state(guid) == ResourceState.STARTED \ - for guid in [app1, app2, node1, node2, iface1, iface2, chan]]) \ - and not ec.finished: - time.sleep(0.5) + guids = [app1, app2] + ec.wait_finished(guids) ec.shutdown() @@ -201,6 +206,36 @@ class ResourceManagerTestCase(unittest.TestCase): self.assertTrue(rmchan.ready_time < rmiface1.ready_time) self.assertTrue(rmchan.ready_time < rmiface2.ready_time) + def test_concurrency(self): + from nepi.execution.resource import ResourceFactory + + ResourceFactory.register_type(Application) + ResourceFactory.register_type(Node) + ResourceFactory.register_type(Interface) + ResourceFactory.register_type(Channel) + + ec = ExperimentController() + + node = ec.register_resource("Node") + + apps = list() + for i in xrange(5000): + app = ec.register_resource("Application") + ec.register_connection(app, node) + apps.append(app) + + ec.deploy() + + ec.wait_finished(apps) + + self.assertTrue(ec.state(node) == ResourceState.STARTED) + self.assertTrue( + all([ec.state(guid) == ResourceState.FINISHED \ + for guid in apps]) + ) + + ec.shutdown() + def test_start_with_condition(self): # TODO!!! pass