File: TestJobCreator.cpp

package info (click to toggle)
ecflow 5.15.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,868 kB
  • sloc: cpp: 269,341; python: 22,756; sh: 3,609; perl: 770; xml: 333; f90: 204; ansic: 141; makefile: 70
file content (118 lines) | stat: -rw-r--r-- 4,256 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * Copyright 2009- ECMWF.
 *
 * This software is licensed under the terms of the Apache Licence version 2.0
 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
 * In applying this licence, ECMWF does not waive the privileges and immunities
 * granted to it by virtue of its status as an intergovernmental organisation
 * nor does it submit to any jurisdiction.
 */

#include <iostream>

#include <boost/test/unit_test.hpp>

#include "ecflow/core/Environment.hpp"
#include "ecflow/core/File.hpp"
#include "ecflow/core/Str.hpp"
#include "ecflow/node/Defs.hpp"
#include "ecflow/node/Family.hpp"
#include "ecflow/node/Jobs.hpp"
#include "ecflow/node/JobsParam.hpp"
#include "ecflow/node/Suite.hpp"
#include "ecflow/node/System.hpp"
#include "ecflow/node/Task.hpp"
#include "ecflow/test/scaffold/Naming.hpp"

using namespace std;
using namespace ecf;

BOOST_AUTO_TEST_SUITE(U_Node)

BOOST_AUTO_TEST_SUITE(T_JobCreator)

BOOST_AUTO_TEST_CASE(test_job_creator) {
    ECF_NAME_THIS_TEST();

    // SET SMSHOME
    std::string ecf_home = File::test_data("libs/node/test/data/SMSHOME", "libs/node");

    // Create the defs file corresponding to the text below
    // # Test the sms file can be found via ECF_SCRIPT
    // # Note: we have to use relative paths, since these tests are relocatable
    // #
    // suite suite
    //	edit SLEEPTIME 10
    //	edit ECF_INCLUDE $ECF_HOME/includes
    //	family family
    //   	task t1
    //   	task t2
    //    	task t3
    //  	endfamily
    // endsuite
    // #
    // # This test suite should force a backwards search since the sms files
    // # are located in SMSHOME
    // suite suite1
    //    family family
    //   		task suite1_task1
    //   		task suite1_task2
    //    	    task suite1_task3
    //    endfamily
    // endsuite
    // Create a defs file, where the task name mirrors the sms files in the given directory
    Defs theDefs;
    {
        suite_ptr suite = Suite::create("suite");
        family_ptr fam  = Family::create("family");
        suite->addVariable(Variable(ecf::environment::ECF_INCLUDE, "$ECF_HOME/../includes"));
        suite->addVariable(Variable("SLEEPTIME", "1"));
        suite->addVariable(Variable("ECF_CLIENT_EXE_PATH", "a/made/up/path"));
        fam->addTask(Task::create("t1"));
        fam->addTask(Task::create("t2"));
        fam->addTask(Task::create("t3"));
        suite->addFamily(fam);
        theDefs.addSuite(suite);
    }
    {
        suite_ptr suite1(new Suite("suite1"));
        family_ptr fam(new Family("family"));
        fam->addTask(Task::create("suite1_task1"));
        fam->addTask(Task::create("suite1_task2"));
        fam->addTask(Task::create("suite1_task3"));
        suite1->addFamily(fam);
        theDefs.addSuite(suite1);
    }
    // 	cerr << theDefs << "\n";

    // get all the task, assume non hierarchical families
    std::vector<Task*> theTasks;
    theDefs.getAllTasks(theTasks);
    BOOST_REQUIRE_MESSAGE(theTasks.size() == 6, "Expected 6 tasks but found, " << theTasks.size());

    // Override ECF_HOME.   ECF_HOME is need to locate to the .ecf files
    theDefs.server_state().add_or_update_user_variables(ecf::environment::ECF_HOME, ecf_home);

    /// begin , will cause creation of generated variables. The generated variables
    /// are use in client scripts and used to locate the ecf files
    theDefs.beginAll();

    // Test Job creator. The job creation should succeed 3 times only, since
    // the sms file suite1_task1, suite1_task2,suite1_task3 are empty.
    JobsParam jobsParam(true /*create jobs*/); // spawn_jobs = false
    Jobs jobs(&theDefs);
    jobs.generate(jobsParam);
    BOOST_REQUIRE_MESSAGE(jobsParam.submitted().size() == 3,
                          "expected 3 jobs but found " << jobsParam.submitted().size() << "\n"
                                                       << jobsParam.errorMsg());

    // Expect error message complaining about sms file suite1_task1, suite1_task2,suite1_task3 being empty
    BOOST_REQUIRE_MESSAGE(!jobsParam.errorMsg().empty(), "expected error message about empty ecf files");

    /// Destroy System singleton to avoid valgrind from complaining
    System::destroy();
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()