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 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
|
/*
* 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_TimeDependencies)
// See ECFLOW-337
// See ECFLOW-833. Also See Note: libs/core/doc/TimeDependencies.ddoc
BOOST_AUTO_TEST_CASE(test_day_time_combination) {
ECF_NAME_THIS_TEST();
// Create the suite, starting on a sunday
// suite s1
// clock real 7.6.2015 # sunday
// task t1 # run task monday at 10, Day acts like a guard, time if ignored until day is free
// day monday
// time 10:00
Defs defs;
suite_ptr suite = defs.add_suite("s1");
auto the_time = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 7),
boost::posix_time::time_duration(0, 0, 0)); // sunday
suite->addClock(ClockAttr(the_time));
task_ptr t1 = suite->add_task("t1");
t1->addDay(DayAttr(DayAttr::MONDAY));
t1->addTime(ecf::TimeAttr(ecf::TimeSlot(10, 0)));
defs.beginAll();
CalendarUpdateParams calUpdateParams(boost::posix_time::hours(1));
auto expected_time = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 8),
boost::posix_time::time_duration(10, 0, 0)); // Monday & 10
// cout << "expected_time = " << expected_time << "\n";
int submitted = 0;
for (int m = 1; m < 120; m++) { // run for 5 days
Jobs jobs(&defs);
JobsParam jobsParam;
jobs.generate(jobsParam);
if (jobsParam.submitted().size()) {
submitted++;
// cout << "submitted at " << suite->calendar().suiteTime() << "\n";
BOOST_CHECK_MESSAGE(suite->calendar().suiteTime() == expected_time,
"\nExpected to submit at " << expected_time << " only, but also found "
<< suite->calendar().suiteTime());
}
defs.updateCalendar(calUpdateParams);
if (suite->calendar().dayChanged()) {
Node::Requeue_args args(Node::Requeue_args::TIME);
t1->requeue(args);
}
// cout << "Suite time " << suite->calendar().suiteTime() << " dayChanged: " << suite->calendar().dayChanged()
// << "\n";
}
BOOST_CHECK_MESSAGE(submitted == 1, "Expected one submission but found " << submitted);
}
BOOST_AUTO_TEST_CASE(test_date_time_combination) {
ECF_NAME_THIS_TEST();
// Create the suite, starting on a sunday
// suite s1
// clock real 7.6.2015 # sunday
// task t1 # run task monday at 10, Date acts like a guard, time if ignored until date is free
// date 8.6.2015
// time 10:00
Defs defs;
suite_ptr suite = defs.add_suite("s1");
auto the_time = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 7),
boost::posix_time::time_duration(0, 0, 0)); // sunday
suite->addClock(ClockAttr(the_time));
task_ptr t1 = suite->add_task("t1");
t1->addDate(DateAttr(8, 6, 2015)); // Monday
t1->addTime(ecf::TimeAttr(ecf::TimeSlot(10, 0)));
defs.beginAll();
CalendarUpdateParams calUpdateParams(boost::posix_time::hours(1));
auto expected_time = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 8),
boost::posix_time::time_duration(10, 0, 0)); // Monday & 10
// cout << defs << "\n";
int submitted = 0;
for (int m = 1; m < 100; m++) {
Jobs jobs(&defs);
JobsParam jobsParam;
jobs.generate(jobsParam);
if (jobsParam.submitted().size()) {
submitted++;
// cout << "submitted at " << suite->calendar().suiteTime() << "\n";
BOOST_CHECK_MESSAGE(suite->calendar().suiteTime() == expected_time,
"\nExpected to submit at " << expected_time << " only, but also found "
<< suite->calendar().suiteTime());
}
defs.updateCalendar(calUpdateParams);
if (suite->calendar().dayChanged()) {
Node::Requeue_args args;
t1->requeue(args);
}
// cout << "Suite time " << suite->calendar().suiteTime() << " dayChanged: " << suite->calendar().dayChanged()
// << "\n";
}
BOOST_CHECK_MESSAGE(submitted == 1, "Expected one submission but found " << submitted);
}
BOOST_AUTO_TEST_CASE(test_day_time_combination_in_hierarchy) {
ECF_NAME_THIS_TEST();
// Create the suite, starting on a sunday
// suite s1
// clock real 7.6.2015 # sunday
// family f1
// day monday # day attribute prevents time from being free
// task t1
// time 10:00 # should run ONCE, monday at 10:00
Defs defs;
suite_ptr suite = defs.add_suite("s1");
auto the_time = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 7),
boost::posix_time::time_duration(0, 0, 0)); // sunday
suite->addClock(ClockAttr(the_time));
family_ptr f1 = suite->add_family("f1");
f1->addDay(DayAttr(DayAttr::MONDAY));
task_ptr t1 = f1->add_task("t1");
t1->addTime(ecf::TimeAttr(ecf::TimeSlot(10, 0)));
defs.beginAll();
CalendarUpdateParams calUpdateParams(boost::posix_time::hours(1));
auto expected_time = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 8),
boost::posix_time::time_duration(10, 0, 0)); // Monday & 10
// cout << defs << "\n";
int submitted = 0;
for (int m = 1; m < 120; m++) { // run for 5 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() << "\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_time,
"\nExpected to submit at " << expected_time << " only, but also found "
<< suite->calendar().suiteTime());
}
Node::Requeue_args args;
f1->requeue(args);
// cout << " requeue f1 at " << suite->calendar().suiteTime() << " " << days[0].dump() << " " <<
// times[0].dump() << "\n";
}
defs.updateCalendar(calUpdateParams);
}
BOOST_CHECK_MESSAGE(submitted == 1, "Expected one submission but found " << submitted);
}
BOOST_AUTO_TEST_CASE(test_time_day_combination_in_hierarchy) {
ECF_NAME_THIS_TEST();
// Create the suite, starting on a sunday
// suite s1
// clock real 7.6.2015 # sunday
// family f1
// time 10:00
// task t1 # task should run *TWICE*, Monday morning @00:00 and, at 10:00
// day monday
Defs defs;
suite_ptr suite = defs.add_suite("s1");
auto the_time = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 7),
boost::posix_time::time_duration(0, 0, 0)); // sunday
suite->addClock(ClockAttr(the_time));
family_ptr f1 = suite->add_family("f1");
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(2015, 6, 8),
boost::posix_time::time_duration(0, 0, 0)); // Monday & 00:00
// cout << defs << "\n";
int submitted = 0;
for (int m = 1; m < 120; m++) { // run for 5 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() << "\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());
}
Node::Requeue_args args;
f1->requeue(args);
// cout << " requeue f1 at " << suite->calendar().suiteTime() << " " << days[0].dump() << " " <<
// times[0].dump() << "\n";
}
defs.updateCalendar(calUpdateParams);
}
BOOST_CHECK_MESSAGE(submitted == 2, "Expected two submission but found " << submitted);
}
BOOST_AUTO_TEST_CASE(test_date_time_combination_in_hierarchy) {
ECF_NAME_THIS_TEST();
// Create the suite, starting on a sunday
// suite s1
// clock real 7.6.2015 # sunday
// family f1
// date 8.6.15 # monday date now guards the time
// task t1
// time 10:00
Defs defs;
suite_ptr suite = defs.add_suite("s1");
auto the_time = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 7),
boost::posix_time::time_duration(0, 0, 0)); // sunday
suite->addClock(ClockAttr(the_time));
family_ptr f1 = suite->add_family("f1");
f1->addDate(DateAttr(8, 6, 2015)); // Monday
task_ptr t1 = f1->add_task("t1");
t1->addTime(ecf::TimeAttr(ecf::TimeSlot(10, 0)));
defs.beginAll();
CalendarUpdateParams calUpdateParams(boost::posix_time::hours(1));
auto expected_time = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 8),
boost::posix_time::time_duration(10, 0, 0)); // Monday & 10
// cout << defs << "\n";
int submitted = 0;
for (int m = 1; m < 100; m++) {
// const std::vector<DateAttr>& dates = f1->dates();
// const std::vector<ecf::TimeAttr>& times = t1->timeVec();
// cout << "Suite time " << suite->calendar().suiteTime() << " dayChanged:" << suite->calendar().dayChanged() <<
// " " << dates[0].dump() << " " << times[0].dump() << "\n";
Jobs jobs(&defs);
JobsParam jobsParam;
jobs.generate(jobsParam);
if (jobsParam.submitted().size()) {
submitted++;
// cout << " submitted at " << suite->calendar().suiteTime() << " " << dates[0].dump() << " " <<
// times[0].dump() << "\n";
// New to ecflow 5.0, parent date will guard the time. i.e will not let time be free until date is
// satisfied.
if (submitted == 1) {
BOOST_CHECK_MESSAGE(suite->calendar().suiteTime() == expected_time,
"\nExpected to submit at " << expected_time << " only, but also found "
<< suite->calendar().suiteTime());
}
Node::Requeue_args args;
f1->requeue(args);
// cout << " requeue at " << suite->calendar().suiteTime() << " " << dates[0].dump() << " " <<
// times[0].dump() << "\n";
}
defs.updateCalendar(calUpdateParams);
}
BOOST_CHECK_MESSAGE(submitted == 1, "Expected one submission but found " << submitted);
}
BOOST_AUTO_TEST_CASE(test_time_date_combination_in_hierarchy) {
ECF_NAME_THIS_TEST();
// Create the suite, starting on a sunday
// suite s1
// clock real 7.6.2015 # sunday
// family f1
// time 10:00
// task t1
// date 8.6.15 # monday, run once at Monday morning, and gain Monday at 10:00
//
Defs defs;
suite_ptr suite = defs.add_suite("s1");
auto the_time = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 7),
boost::posix_time::time_duration(0, 0, 0)); // sunday
suite->addClock(ClockAttr(the_time));
family_ptr f1 = suite->add_family("f1");
f1->addTime(ecf::TimeAttr(ecf::TimeSlot(10, 0)));
task_ptr t1 = f1->add_task("t1");
t1->addDate(DateAttr(8, 6, 2015)); // Monday
defs.beginAll();
CalendarUpdateParams calUpdateParams(boost::posix_time::hours(1));
auto expected_time1 = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 8),
boost::posix_time::time_duration(0, 0, 0)); // Monday & 00:00
auto expected_time2 = boost::posix_time::ptime(boost::gregorian::date(2015, 6, 8),
boost::posix_time::time_duration(10, 0, 0)); // Monday & 10
// cout << defs << "\n";
int submitted = 0;
for (int m = 1; m < 100; m++) {
// const std::vector<DateAttr>& dates = t1->dates();
// const std::vector<ecf::TimeAttr>& times = f1->timeVec();
// cout << "Suite time " << suite->calendar().suiteTime() << " dayChanged:" << suite->calendar().dayChanged() <<
// " " << dates[0].dump() << " " << times[0].dump() << "\n";
Jobs jobs(&defs);
JobsParam jobsParam;
jobs.generate(jobsParam);
if (jobsParam.submitted().size()) {
submitted++;
// cout << " submitted at " << suite->calendar().suiteTime() << " " << dates[0].dump() << " " <<
// times[0].dump() << "\n";
// 1st Run: MONDAY Morning 00:00 time was free from sunday
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 10:00
if (submitted == 2) {
BOOST_CHECK_MESSAGE(suite->calendar().suiteTime() == expected_time2,
"\nExpected to submit at " << expected_time2 << " only, but also found "
<< suite->calendar().suiteTime());
}
Node::Requeue_args args;
f1->requeue(args);
// cout << " requeue at " << suite->calendar().suiteTime() << " " << dates[0].dump() << " " <<
// times[0].dump() << "\n";
}
defs.updateCalendar(calUpdateParams);
}
BOOST_CHECK_MESSAGE(submitted == 2, "Expected two submission but found " << submitted);
}
BOOST_AUTO_TEST_CASE(test_impossible_day_combination) {
ECF_NAME_THIS_TEST();
// Create the suite, starting on a sunday
// suite s1
// clock real 4.8.2019 # sunday
// family f1
// day monday
// task t1 # task should never run, can't be Sunday/Monday at same time.
// day tuesday
// time 10:00
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 f1 = suite->add_family("f1");
f1->addDay(DayAttr(DayAttr::MONDAY));
task_ptr t1 = f1->add_task("t1");
t1->addTime(ecf::TimeAttr(ecf::TimeSlot(10, 0)));
t1->addDay(DayAttr(DayAttr::TUESDAY));
defs.beginAll();
CalendarUpdateParams calUpdateParams(boost::posix_time::hours(1));
// cout << defs << "\n";
int submitted = 0;
for (int m = 1; m < 100; m++) {
// const std::vector<DateAttr>& fdates = f1->dates();
// const std::vector<DateAttr>& dates = t1->dates();
// const std::vector<ecf::TimeAttr>& times = t1->timeVec();
// cout << "Suite time " << suite->calendar().suiteTime() << " dayChanged:" << suite->calendar().dayChanged() <<
// "\n "
// << fdates[0].dump() << " " << dates[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 " << suite->calendar().suiteTime() << " dayChanged:" <<
// suite->calendar().dayChanged() << "\n "
// << fdates[0].dump() << " " << dates[0].dump() << " " << times[0].dump() << " rep: " <<
// f1->repeat().value() << "\n";
Node::Requeue_args args;
t1->requeue(args);
}
defs.updateCalendar(calUpdateParams);
}
BOOST_CHECK_MESSAGE(submitted == 0, "Expected zero submission but found " << submitted);
}
BOOST_AUTO_TEST_CASE(test_impossible_date_combination) {
ECF_NAME_THIS_TEST();
// Create the suite, starting on a sunday
// suite s1
// family f1
// date 5.8.2019 # monday
// task t1 # task should never run, can't be Sunday/Monday at same time.
// date 6.8.2019 # tuesday
// time 10:00
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 f1 = suite->add_family("f1");
f1->addDate(DateAttr(5, 8, 2019)); // Monday
task_ptr t1 = f1->add_task("t1");
t1->addTime(ecf::TimeAttr(ecf::TimeSlot(10, 0)));
t1->addDate(DateAttr(6, 8, 2019)); // Tuesday
defs.beginAll();
CalendarUpdateParams calUpdateParams(boost::posix_time::hours(1));
// cout << defs << "\n";
int submitted = 0;
for (int m = 1; m < 100; m++) {
// 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";
Node::Requeue_args args;
t1->requeue(args);
}
defs.updateCalendar(calUpdateParams);
}
BOOST_CHECK_MESSAGE(submitted == 0, "Expected zero submission but found " << submitted);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
|