Esempio n. 1
0
    def test_evict_non_existent_app(self):
        # tests that apps previously run with this session that are finished and eventually
        # removed by the scheduler also get removed from the session after a status() API has been
        # called on the app

        scheduler = LocalScheduler(self.image_fetcher, cache_size=1)
        session = StandaloneSession(name="test_session",
                                    scheduler=scheduler,
                                    wait_interval=1)
        test_file = os.path.join(self.test_dir, "test_file")
        role = (session.role(name="touch").runs("touch.sh", test_file).on(
            self.test_container))
        app = session.app("touch_test_file").of(role)

        # local scheduler was setup with a cache size of 1
        # run the same app twice (the first will be removed from the scheduler's cache)
        # then validate that the first one will drop from the session's app cache as well
        app_id1 = session.run(app)
        session.wait(app_id1)

        app_id2 = session.run(app)
        session.wait(app_id2)

        apps = session.list()

        self.assertEqual(1, len(apps))
        self.assertFalse(app_id1 in apps)
        self.assertTrue(app_id2 in apps)
    def test_list(self):
        session = StandaloneSession(name="test_session",
                                    scheduler=self.scheduler,
                                    wait_interval=1)
        role = Role(name="touch").runs("sleep.sh", "1").on(self.test_container)
        app = Application("sleeper").of(role)

        num_apps = 4

        for _ in range(num_apps):
            # since this test validates the list() API,
            # we do not wait for the apps to finish so run the apps
            # in managed mode so that the local scheduler reaps the apps on exit
            session.run(app, mode=RunMode.MANAGED)

        apps = session.list()
        self.assertEqual(num_apps, len(apps))