File: TestDefStatus.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 (179 lines) | stat: -rw-r--r-- 6,411 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
 * 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/node/Defs.hpp"
#include "ecflow/node/Family.hpp"
#include "ecflow/node/Suite.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_DefsStatus)

BOOST_AUTO_TEST_CASE(test_defstatus) {
    ECF_NAME_THIS_TEST();

    // Create a defs file corresponding to:
    // suite suite1
    //	family f1
    //   	task t1
    //   	task t2
    //	family f2
    //   	task t1
    //   	task t2
    Defs theDefs;
    suite_ptr suite = theDefs.add_suite("suite1");
    family_ptr f1   = suite->add_family("f1");
    task_ptr t1     = f1->add_task("t1");
    task_ptr t2     = f1->add_task("t2");

    family_ptr f2  = suite->add_family("f2");
    task_ptr f2_t1 = f2->add_task("t1");
    task_ptr f2_t2 = f2->add_task("t2");

    // Get all nodes and tasks for ease of test
    vector<Node*> nodes;
    vector<Task*> tasks;
    theDefs.getAllNodes(nodes);
    theDefs.getAllTasks(tasks);

    BOOST_CHECK_MESSAGE(!suite->begun(), "Expected suite not to be begun ");

    /// It should be noted that once a suite has begun, it stays begun, however for test purposes we had
    /// added ability to reset the begin state.

    /// Test 1: with no defstatus. All nodes should be set to NState::QUEUED
    theDefs.beginAll();
    BOOST_CHECK_MESSAGE(suite->begun(), "Expected suite to be begun ");
    for (Node* n : nodes) {
        BOOST_CHECK_MESSAGE(n->state() == NState::QUEUED, "Expected queued but found " << NState::toString(n->state()));
    }

    theDefs.requeue();
    for (Node* n : nodes) {
        BOOST_CHECK_MESSAGE(n->state() == NState::QUEUED, "Expected queued but found " << NState::toString(n->state()));
    }

    /// Test 2: with defstatus on suite. With complete the status should have been propagated down
    suite->addDefStatus(DState::COMPLETE);
    theDefs.reset_begin(); // for test purposes only
    BOOST_CHECK_MESSAGE(!suite->begun(), "Expected suite not to be begun ");

    theDefs.beginAll();
    for (Node* n : nodes) {
        BOOST_CHECK_MESSAGE(n->state() == NState::COMPLETE,
                            "Expected complete but found " << NState::toString(n->state()));
    }

    theDefs.requeue();
    for (Node* n : nodes) {
        BOOST_CHECK_MESSAGE(n->state() == NState::COMPLETE,
                            "Expected complete but found " << NState::toString(n->state()));
    }

    /// Test 3: defstatus of family f1 and f2. The parent node(suite) should reflect status of children
    /// Also setting defstatus complete on a family should have propagated it downwards to tasks
    suite->addDefStatus(DState::default_state()); // reset defstatus
    f1->addDefStatus(DState::COMPLETE);
    f2->addDefStatus(DState::COMPLETE);
    theDefs.reset_begin(); // for test purposes only
    theDefs.beginAll();
    for (Node* n : nodes) {
        BOOST_CHECK_MESSAGE(n->state() == NState::COMPLETE,
                            "Expected complete but found " << NState::toString(n->state()));
    }

    theDefs.requeue();
    for (Node* n : nodes) {
        BOOST_CHECK_MESSAGE(n->state() == NState::COMPLETE,
                            "Expected complete but found " << NState::toString(n->state()));
    }

    // Suspend is really a user interaction the real state suould be queued
    f1->addDefStatus(DState::default_state()); // reset defstatus
    f2->addDefStatus(DState::default_state()); // reset defstatus
    suite->addDefStatus(DState::SUSPENDED);    // reset defstatus
    theDefs.reset_begin();                     // for test purposes only
    theDefs.beginAll();
    for (Node* n : nodes) {
        BOOST_CHECK_MESSAGE(n->state() == NState::QUEUED, "Expected queued but found " << NState::toString(n->state()));
    }

    theDefs.requeue();
    for (Node* n : nodes) {
        BOOST_CHECK_MESSAGE(n->state() == NState::QUEUED, "Expected queued but found " << NState::toString(n->state()));
    }
}

BOOST_AUTO_TEST_CASE(test_ECFLOW_139) {
    ECF_NAME_THIS_TEST();

    // Create a defs file corresponding to:
    // suite suite1
    // family f1
    //    task t1; defstatus suspended
    //    task t2; defstatus suspended
    // family f2
    //    task t1; defstatus suspended
    //    task t2; defstatus suspended
    Defs theDefs;
    suite_ptr suite = theDefs.add_suite("suite1");
    family_ptr f1   = suite->add_family("f1");
    task_ptr t1     = f1->add_task("t1");
    task_ptr t2     = f1->add_task("t2");
    t1->addDefStatus(DState::SUSPENDED);
    t2->addDefStatus(DState::SUSPENDED);

    family_ptr f2  = suite->add_family("f2");
    task_ptr f2_t1 = f2->add_task("t1");
    task_ptr f2_t2 = f2->add_task("t2");
    f2_t1->addDefStatus(DState::SUSPENDED);
    f2_t2->addDefStatus(DState::SUSPENDED);

    // Get all nodes and tasks for ease of test
    vector<Task*> tasks;
    theDefs.getAllTasks(tasks);

    /// It should be noted that once a suite has begun, it stays begun, however for test purposes we had
    /// added ability to reset the begin state.

    /// Test 1: Check NODE state All nodes should be set to NState::QUEUED
    theDefs.beginAll();
    for (Task* n : tasks) {
        BOOST_CHECK_MESSAGE(n->state() == NState::QUEUED, "Expected queued but found " << NState::toString(n->state()));
    }

    /// Check: DSTATE
    for (Task* n : tasks) {
        BOOST_CHECK_MESSAGE(n->dstate() == DState::SUSPENDED,
                            "Expected suspended but found " << DState::toString(n->dstate()));
    }

    theDefs.requeue();
    for (Task* n : tasks) {
        BOOST_CHECK_MESSAGE(n->state() == NState::QUEUED, "Expected queued but found " << NState::toString(n->state()));
    }
    for (Task* n : tasks) {
        BOOST_CHECK_MESSAGE(n->dstate() == DState::SUSPENDED,
                            "Expected suspended but found " << DState::toString(n->dstate()));
    }
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()