File: TestRepeatWithTimeDependencies.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 (258 lines) | stat: -rw-r--r-- 11,526 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
 * 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/CalendarUpdateParams.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/Task.hpp"
#include "ecflow/test/scaffold/Naming.hpp"

using namespace ecf;

BOOST_AUTO_TEST_SUITE(U_Node)

BOOST_AUTO_TEST_SUITE(T_RepeatWithTimeDependencies)

BOOST_AUTO_TEST_CASE(test_repeat_day_time_combination_in_hierarchy) {
    ECF_NAME_THIS_TEST();

    // Create the suite, starting on a sunday
    // suite s1
    //  family f
    //    repeat integer rep 0 1
    //    family f1
    //       day monday
    //       task t1
    //         time 10:00  # should run, monday at 10:00 twice, due to repeat
    //         time 11:00  # should run, monday at 11:00 twice, due to repeat
    Defs defs;
    suite_ptr suite = defs.add_suite("s1");
    auto the_time   = boost::posix_time::ptime(boost::gregorian::date(2019, 8, 4),
                                             boost::posix_time::time_duration(0, 0, 0)); // sunday
    suite->addClock(ClockAttr(the_time));
    family_ptr f  = suite->add_family("f");
    family_ptr f1 = f->add_family("f1");
    f1->addRepeat(RepeatInteger("rep", 0, 1, 1));
    f1->addDay(DayAttr(DayAttr::MONDAY));
    task_ptr t1 = f1->add_task("t1");
    t1->addTime(ecf::TimeAttr(ecf::TimeSlot(10, 0)));
    t1->addTime(ecf::TimeAttr(ecf::TimeSlot(11, 0)));
    defs.beginAll();

    CalendarUpdateParams calUpdateParams(boost::posix_time::hours(1));
    auto expected_time1 = boost::posix_time::ptime(boost::gregorian::date(2019, 8, 5),
                                                   boost::posix_time::time_duration(10, 0, 0)); // Monday & 10
    auto expected_time2 = boost::posix_time::ptime(boost::gregorian::date(2019, 8, 5),
                                                   boost::posix_time::time_duration(11, 0, 0)); // Monday & 11
    auto expected_time3 = boost::posix_time::ptime(boost::gregorian::date(2019, 8, 12),
                                                   boost::posix_time::time_duration(10, 0, 0)); // Monday & 10
    auto expected_time4 = boost::posix_time::ptime(boost::gregorian::date(2019, 8, 12),
                                                   boost::posix_time::time_duration(11, 0, 0)); // Monday & 11
    // cout << defs << "\n";

    int submitted = 0;
    for (int m = 1; m < 212; m++) { // run for 9 days

        // const std::vector<DayAttr>& days = f1->days();
        // const std::vector<ecf::TimeAttr>& times = t1->timeVec();
        // cout << "Suite time " << suite->calendar().suiteTime() << " dayChanged:" << suite->calendar().dayChanged() <<
        // " " << days[0].dump() << " " << times[0].dump() << " rep: " << f1->repeat().value() << "\n";

        Jobs jobs(&defs);
        JobsParam jobsParam;
        jobs.generate(jobsParam);

        if (jobsParam.submitted().size()) {
            submitted++;
            // cout << "   submitted at " << suite->calendar().suiteTime() << " " << days[0].dump() << " " <<
            // times[0].dump() << "\n";

            // 1st Run: Monday at 10:00 am
            if (submitted == 1) {
                BOOST_CHECK_MESSAGE(suite->calendar().suiteTime() == expected_time1,
                                    "\nExpected to submit at " << expected_time1 << " only, but also found "
                                                               << suite->calendar().suiteTime());
            }

            // 2nd Run: Monday at 11:00 am
            if (submitted == 2) {
                BOOST_CHECK_MESSAGE(suite->calendar().suiteTime() == expected_time2,
                                    "\nExpected to submit at " << expected_time2 << " only, but also found "
                                                               << suite->calendar().suiteTime());
            }

            // 3rd Run: Monday at 10:00 am
            if (submitted == 3) {
                BOOST_CHECK_MESSAGE(suite->calendar().suiteTime() == expected_time3,
                                    "\nExpected to submit at " << expected_time3 << " only, but also found "
                                                               << suite->calendar().suiteTime());
            }

            // 4th Run: Monday at 11:00 am
            if (submitted == 4) {
                BOOST_CHECK_MESSAGE(suite->calendar().suiteTime() == expected_time4,
                                    "\nExpected to submit at " << expected_time4 << " only, but also found "
                                                               << suite->calendar().suiteTime());
            }

            t1->set_state(NState::COMPLETE); // cause repeat to loop
            // cout << "   set_complete t1 at " << suite->calendar().suiteTime() << " " << days[0].dump() << " " <<
            // times[0].dump() << "\n";
        }

        defs.updateCalendar(calUpdateParams);
    }
    BOOST_CHECK_MESSAGE(submitted == 4, "Expected four submission but found " << submitted);
}

BOOST_AUTO_TEST_CASE(test_repeat_time_day_combination_in_hierarchy) {
    ECF_NAME_THIS_TEST();

    // Create the suite, starting on a sunday
    // suite s1
    //  family f
    //    repeat integer rep 0 1
    //    family f1
    //       time 10:00  # should run, 2 on monday at midnight, the time has NO effect
    //       task t1
    //          day monday
    Defs defs;
    suite_ptr suite = defs.add_suite("s1");
    auto the_time   = boost::posix_time::ptime(boost::gregorian::date(2019, 8, 4),
                                             boost::posix_time::time_duration(0, 0, 0)); // sunday
    suite->addClock(ClockAttr(the_time));
    family_ptr f  = suite->add_family("f");
    family_ptr f1 = f->add_family("f1");
    f1->addRepeat(RepeatInteger("rep", 0, 3, 1)); // four iteration
    f1->addTime(ecf::TimeAttr(ecf::TimeSlot(10, 0)));
    task_ptr t1 = f1->add_task("t1");
    t1->addDay(DayAttr(DayAttr::MONDAY));
    defs.beginAll();

    CalendarUpdateParams calUpdateParams(boost::posix_time::hours(1));
    auto expected_time1 = boost::posix_time::ptime(boost::gregorian::date(2019, 8, 5),
                                                   boost::posix_time::time_duration(0, 0, 0)); // Monday & 00:00
    auto expected_time3 = boost::posix_time::ptime(boost::gregorian::date(2019, 8, 12),
                                                   boost::posix_time::time_duration(0, 0, 0)); // Monday & 00:00
    // cout << defs << "\n";

    int submitted = 0;
    for (int m = 1; m < 212; m++) { // run for 9 days

        // const std::vector<DayAttr>& days = t1->days();
        // const std::vector<ecf::TimeAttr>& times = f1->timeVec();
        // cout << "Suite time " << suite->calendar().suiteTime() << " dayChanged:" << suite->calendar().dayChanged() <<
        // " " << days[0].dump() << " " << times[0].dump() << " rep: " << f1->repeat().value() << "\n";

        Jobs jobs(&defs);
        JobsParam jobsParam;
        jobs.generate(jobsParam);

        if (jobsParam.submitted().size()) {
            submitted++;
            // cout << "   submitted at " << suite->calendar().suiteTime() << " " << days[0].dump() << " " <<
            // times[0].dump() << "\n";

            // 1st Run: Monday at 00:00 am
            if (submitted == 1) {
                BOOST_CHECK_MESSAGE(suite->calendar().suiteTime() == expected_time1,
                                    "\nExpected to submit at " << expected_time1 << " only, but also found "
                                                               << suite->calendar().suiteTime());
            }

            // 1st Run: Monday at 00:00 am
            if (submitted == 2) {
                BOOST_CHECK_MESSAGE(suite->calendar().suiteTime() == expected_time3,
                                    "\nExpected to submit at " << expected_time3 << " only, but also found "
                                                               << suite->calendar().suiteTime());
            }

            t1->set_state(NState::COMPLETE); // cause repeat to loop
            // cout << "   set_complete t1 at " << suite->calendar().suiteTime() << " " << days[0].dump() << " " <<
            // times[0].dump() << "\n"; PrintStyle style(PrintStyle::MIGRATE); cout << defs << "\n";
        }

        defs.updateCalendar(calUpdateParams);
    }
    BOOST_CHECK_MESSAGE(submitted == 2, "Expected two submission but found " << submitted);
}

BOOST_AUTO_TEST_CASE(test_repeat_with_impossible_day_combination_in_hierarchy) {
    ECF_NAME_THIS_TEST();

    // Create the suite, starting on a sunday
    //   suite s1
    //     clock real 04.08.2019            # Sunday
    //     family f
    //       repeat integer rep 0 1
    //       family f1
    //          day monday
    //          task t1
    //               day tuesday            # cant be free on Monday and Tuesday,
    //               time 10:00
    //               verify complete:1
    Defs defs;
    suite_ptr suite = defs.add_suite("s1");
    suite->addClock(ClockAttr(boost::posix_time::ptime(boost::gregorian::date(2019, 8, 4),
                                                       boost::posix_time::time_duration(0, 0, 0)))); // sunday
    family_ptr f  = suite->add_family("f");
    family_ptr f1 = f->add_family("f1");
    f1->addRepeat(RepeatInteger("rep", 0, 1, 1)); // 2 iteration
    f1->addDay(DayAttr(DayAttr::MONDAY));
    task_ptr t1 = f1->add_task("t1");
    t1->addDay(DayAttr(DayAttr::TUESDAY));
    t1->addTime(ecf::TimeAttr(ecf::TimeSlot(10, 0)));
    defs.beginAll();

    CalendarUpdateParams calUpdateParams(boost::posix_time::hours(1));
    // cout << defs << "\n";

    int submitted = 0;
    for (int m = 1; m < 212; m++) { // run for 9 days

        // const std::vector<DayAttr>& fdays = f1->days();
        // const std::vector<DayAttr>& days = t1->days();
        // const std::vector<ecf::TimeAttr>& times = t1->timeVec();
        // cout << "Suite time " << suite->calendar().suiteTime() << " dayChanged:" << suite->calendar().dayChanged() <<
        // "\n   "
        //          << fdays[0].dump() << " " << days[0].dump() << " " << times[0].dump() << " rep: " <<
        //          f1->repeat().value() << "\n";

        Jobs jobs(&defs);
        JobsParam jobsParam;
        jobs.generate(jobsParam);

        if (jobsParam.submitted().size()) {
            submitted++;
            // cout << " submitted at " << suite->calendar().suiteTime() << " dayChanged:" <<
            // suite->calendar().dayChanged() << "\n   "
            //          << fdays[0].dump() << " " << days[0].dump() << " " << times[0].dump() << " rep: " <<
            //          f1->repeat().value() << "\n";

            t1->set_state(NState::COMPLETE); // cause repeat to loop
                                             // PrintStyle style(PrintStyle::MIGRATE);
            // cout << defs << "\n";
        }

        defs.updateCalendar(calUpdateParams);
    }
    BOOST_CHECK_MESSAGE(submitted == 0, "Expected 0 submission but found " << submitted);
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()