def test_em(self): # Create an ensemble and a workflow e = ensembles.Ensemble(self.username, "foo") e.set_max_planning(1) e.set_max_running(1) db.session.add(e) db.session.flush() w = ensembles.EnsembleWorkflow(e.id, "bar") db.session.add(w) db.session.flush() w2 = ensembles.EnsembleWorkflow(e.id, "baz") db.session.add(w2) db.session.flush() mgr = em.EnsembleManager() e.set_state(ensembles.EnsembleStates.PAUSED) db.session.flush() mgr.loop_once() self.assertEquals(w.state, ensembles.EnsembleWorkflowStates.READY, "State should still be READY") self.assertEquals(w2.state, ensembles.EnsembleWorkflowStates.READY, "State should still be READY") e.set_state(ensembles.EnsembleStates.ACTIVE) db.session.flush() mgr.loop_once() self.assertEquals(w.state, ensembles.EnsembleWorkflowStates.PLANNING, "State should be PLANNING") self.assertEquals(w2.state, ensembles.EnsembleWorkflowStates.READY, "State should be READY") mgr.loop_once() self.assertEquals(w.state, ensembles.EnsembleWorkflowStates.RUNNING, "State should be RUNNING") self.assertEquals(w.submitdir, "submitdir", "Submitdir should be set") self.assertEquals(w.wf_uuid, "d8f8e15c-a55f-4ca0-8474-62bdb3310083", "UUID should be set") self.assertEquals(w2.state, ensembles.EnsembleWorkflowStates.PLANNING, "State should be PLANNING") mgr.loop_once() self.assertEquals(w.state, ensembles.EnsembleWorkflowStates.SUCCESSFUL, "State should be SUCCESSFUL") self.assertEquals(w2.state, ensembles.EnsembleWorkflowStates.RUNNING, "State should be RUNNING") mgr.loop_once() self.assertEquals(w2.state, ensembles.EnsembleWorkflowStates.SUCCESSFUL, "State should be SUCCESSFUL")
def test_workflow_processor(self): "Simple tests to make sure the WorkflowProcessor works" wf_uuid = "d8f8e15c-a55f-4ca0-8474-62bdb3310083" e = ensembles.Ensemble(self.username, "foo") db.session.add(e) db.session.flush() ew = ensembles.EnsembleWorkflow(e.id, "bar") ew.wf_uuid = wf_uuid db.session.add(ew) db.session.flush() p = em.WorkflowProcessor(ew) self.assertRaises(em.EMException, p.run) ew.submitdir = "/some/path/not/existing" db.session.flush() self.assertRaises(em.EMException, p.run) p = em.WorkflowProcessor(ew) self.assertTrue(p.pending()) self.assertRaises(em.EMException, p.running) self.assertRaises(em.EMException, p.running_successful) dw = dash.DashboardWorkflow() dw.wf_uuid = wf_uuid db.session.add(dw) db.session.flush() ws = dash.DashboardWorkflowstate() ws.wf_id = dw.wf_id ws.state = 'WORKFLOW_STARTED' ws.restart_count = 0 ws.status = 0 db.session.add(ws) db.session.flush() p = em.WorkflowProcessor(ew) self.assertTrue(p.running()) self.assertRaises(em.EMException, p.running_successful) ws.state = 'WORKFLOW_TERMINATED' ws.status = 0 db.session.flush() self.assertFalse(p.running()) self.assertTrue(p.running_successful()) ws.status = 1 db.session.flush() self.assertFalse(p.running_successful())
def test_ensemble_db(self): self.assertEqual(len(ensembles.list_ensembles(self.username)), 0, "Should be no ensembles") e = ensembles.create_ensemble(self.username, "foo", 1, 1) self.assertEqual(len(ensembles.list_ensembles(self.username)), 1, "Should be 1 ensemble") self.assertEqual(len(ensembles.list_actionable_ensembles()), 0, "Should be 0 actionable ensembles") w = ensembles.EnsembleWorkflow(e.id, "bar") db.session.add(w) db.session.flush() self.assertEqual(len(ensembles.list_actionable_ensembles()), 1, "Should be 1 actionable ensembles")