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
|
/*
* 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 <limits>
#include <boost/test/unit_test.hpp>
#include "ServerTestHarness.hpp"
#include "TestFixture.hpp"
#include "ecflow/attribute/VerifyAttr.hpp"
#include "ecflow/base/cts/user/CFileCmd.hpp"
#include "ecflow/core/AssertTimer.hpp"
#include "ecflow/core/NOrder.hpp"
#include "ecflow/core/Str.hpp"
#include "ecflow/core/Timer.hpp"
#include "ecflow/node/Alias.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 ecf;
///
/// This test will TEST:
/// o Alias creation and running
/// o Alias ordering
/// o Alias deletion
/// Will indirectly test the Alias memento's
///
BOOST_AUTO_TEST_SUITE(S_Test)
BOOST_AUTO_TEST_SUITE(T_Alias)
void wait_for_alias_to_complete(const std::string& alias_path) {
AssertTimer assertTimer(10, false); // Bomb out after 10 seconds, fall back if test fail
while (1) {
BOOST_REQUIRE_MESSAGE(TestFixture::client().sync_local() == 0,
"Could not get the defs from server\n"
<< TestFixture::client().errorMsg());
defs_ptr defs = TestFixture::client().defs();
node_ptr alias = defs->findAbsNode(alias_path);
BOOST_REQUIRE_MESSAGE(alias.get(),
"Could not locate created alias at path " << alias_path << "\n"
<< TestFixture::client().errorMsg());
if (alias->state() == NState::COMPLETE) {
break;
}
sleep(2);
}
}
BOOST_AUTO_TEST_CASE(test_alias) {
ECF_NAME_THIS_TEST();
DurationTimer timer;
TestClean clean_at_start_and_end;
// Create the defs file corresponding to the text below
// ECF_HOME variable is automatically added by the test harness.
// ECF_INCLUDE variable is automatically added by the test harness.
// SLEEPTIME variable is automatically added by the test harness.
// ECF_CLIENT_EXE_PATH variable is automatically added by the test harness.
// This is substituted in ecf includes
// Allows test to run without requiring installation
Defs theDefs;
task_ptr task_a;
{
suite_ptr suite = theDefs.add_suite("test_alias");
suite->add_variable("SLEEPTIME", "0");
task_a = suite->add_task("task_a");
task_a->addMeter(Meter("meter", 0, 20, 20));
task_a->addEvent(Event(1, "event"));
task_a->addLabel(Label("task_a_label", "Label1"));
}
// The test harness will create corresponding directory structure & default ecf file
ServerTestHarness serverTestHarness;
serverTestHarness.run(theDefs, ServerTestHarness::testDataDefsLocation("test_alias.def"));
// After the task has completed create a Alias
TestFixture::client().set_throw_on_error(false);
// Get the ecf script from the current task and use it to create alias
BOOST_REQUIRE_MESSAGE(TestFixture::client().file(
task_a->absNodePath(), CFileCmd::toString(CFileCmd::ECF), "10000") == 0,
"Expected to retreive script\n"
<< TestFixture::client().errorMsg());
std::string script = TestFixture::client().get_string();
BOOST_CHECK_MESSAGE(!script.empty(), "script for task " << task_a->absNodePath() << " is empty");
// TEST Alias CREATION and running =============================================================================
// Split the file into line
std::vector<std::string> script_lines;
Str::split(script, script_lines, "\n");
NameValueVec used_variables;
int result = TestFixture::client().edit_script_submit(
task_a->absNodePath(), used_variables, script_lines, true /*create alias*/, true /*run alias*/);
BOOST_REQUIRE_MESSAGE(result == 0,
"Expected alias creation and run to succeed\n"
<< TestFixture::client().errorMsg());
std::string alias0_path = task_a->absNodePath() + "/alias0";
// Wait for alias to complete.
wait_for_alias_to_complete(alias0_path);
// #ifdef DEBUG
// BOOST_REQUIRE_MESSAGE(TestFixture::client().sync_local() == 0, "Could not get the defs from server\n" <<
// TestFixture::client().errorMsg()); defs_ptr defs = TestFixture::client().defs(); PrintStyle
// style(PrintStyle::STATE); std::cout << *defs;
// #endif
// TEST ORDERING:: Create another alias, but don't run it.
// =============================================================================
result = TestFixture::client().edit_script_submit(
task_a->absNodePath(), used_variables, script_lines, true /*create alias*/, false /*run alias*/);
BOOST_REQUIRE_MESSAGE(result == 0, "Expected alias creation succeed\n" << TestFixture::client().errorMsg());
{
BOOST_REQUIRE_MESSAGE(TestFixture::client().sync_local() == 0,
"Could not get the defs from server\n"
<< TestFixture::client().errorMsg());
defs_ptr defs = TestFixture::client().defs();
std::vector<alias_ptr> aliases;
defs->get_all_aliases(aliases);
BOOST_REQUIRE_MESSAGE(aliases.size() == 2, "Expected 2 aliases\n" << TestFixture::client().errorMsg());
}
BOOST_REQUIRE_MESSAGE(TestFixture::client().order(alias0_path, NOrder::toString(NOrder::DOWN)) == 0,
"Expected order NOrder::DOWN to succeed\n"
<< TestFixture::client().errorMsg());
{
BOOST_REQUIRE_MESSAGE(TestFixture::client().sync_local() == 0,
"Could not get the defs from server\n"
<< TestFixture::client().errorMsg());
defs_ptr defs = TestFixture::client().defs();
Task* task = defs->findAbsNode(task_a->absNodePath())->isTask();
BOOST_REQUIRE_MESSAGE(task, "expected to find Task");
std::vector<std::string> expected;
expected.push_back("alias1");
expected.push_back("alias0");
BOOST_REQUIRE_MESSAGE(ecf::algorithm::transform_to_name_vector(task->aliases()) == expected,
"NOrder::DOWN expected "
<< ecf::algorithm::join(expected) << " but found "
<< ecf::algorithm::join(ecf::algorithm::transform_to_name_vector(task->aliases())));
}
BOOST_REQUIRE_MESSAGE(TestFixture::client().order(alias0_path, NOrder::toString(NOrder::UP)) == 0,
"Expected order NOrder::UP to succeed\n"
<< TestFixture::client().errorMsg());
{
BOOST_REQUIRE_MESSAGE(TestFixture::client().sync_local() == 0,
"Could not get the defs from server\n"
<< TestFixture::client().errorMsg());
defs_ptr defs = TestFixture::client().defs();
Task* task = defs->findAbsNode(task_a->absNodePath())->isTask();
BOOST_REQUIRE_MESSAGE(task, "expected to find Task");
std::vector<std::string> expected;
expected.push_back("alias0");
expected.push_back("alias1");
BOOST_REQUIRE_MESSAGE(ecf::algorithm::transform_to_name_vector(task->aliases()) == expected,
"NOrder::UP expected "
<< ecf::algorithm::join(expected) << " but found "
<< ecf::algorithm::join(ecf::algorithm::transform_to_name_vector(task->aliases())));
}
BOOST_REQUIRE_MESSAGE(TestFixture::client().order(alias0_path, NOrder::toString(NOrder::ORDER)) == 0,
"Expected order NOrder::ORDER to succeed\n"
<< TestFixture::client().errorMsg());
{
BOOST_REQUIRE_MESSAGE(TestFixture::client().sync_local() == 0,
"Could not get the defs from server\n"
<< TestFixture::client().errorMsg());
defs_ptr defs = TestFixture::client().defs();
Task* task = defs->findAbsNode(task_a->absNodePath())->isTask();
BOOST_REQUIRE_MESSAGE(task, "expected to find Task");
std::vector<std::string> expected;
expected.push_back("alias1");
expected.push_back("alias0");
BOOST_REQUIRE_MESSAGE(ecf::algorithm::transform_to_name_vector(task->aliases()) == expected,
"NOrder::ORDER expected "
<< ecf::algorithm::join(expected) << " but found "
<< ecf::algorithm::join(ecf::algorithm::transform_to_name_vector(task->aliases())));
}
BOOST_REQUIRE_MESSAGE(TestFixture::client().order(alias0_path, NOrder::toString(NOrder::ALPHA)) == 0,
"Expected order NOrder::ALPHA to succeed\n"
<< TestFixture::client().errorMsg());
{
BOOST_REQUIRE_MESSAGE(TestFixture::client().sync_local() == 0,
"Could not get the defs from server\n"
<< TestFixture::client().errorMsg());
defs_ptr defs = TestFixture::client().defs();
Task* task = defs->findAbsNode(task_a->absNodePath())->isTask();
BOOST_REQUIRE_MESSAGE(task, "expected to find Task");
std::vector<std::string> expected;
expected.push_back("alias0");
expected.push_back("alias1");
BOOST_REQUIRE_MESSAGE(ecf::algorithm::transform_to_name_vector(task->aliases()) == expected,
"NOrder::ALPHA expected "
<< ecf::algorithm::join(expected) << " but found "
<< ecf::algorithm::join(ecf::algorithm::transform_to_name_vector(task->aliases())));
}
// TEST Alias DELETION =============================================================================
std::string alias1_path = task_a->absNodePath() + "/alias1";
BOOST_REQUIRE_MESSAGE(TestFixture::client().delete_node(alias0_path) == 0,
"delete alias0 failed\n"
<< TestFixture::client().errorMsg());
BOOST_REQUIRE_MESSAGE(TestFixture::client().delete_node(alias1_path) == 0,
"delete alias1 failed\n"
<< TestFixture::client().errorMsg());
// Get the defs from the server
BOOST_REQUIRE_MESSAGE(TestFixture::client().sync_local() == 0,
"Could not get the defs from server\n"
<< TestFixture::client().errorMsg());
defs_ptr defs = TestFixture::client().defs();
std::vector<alias_ptr> aliases;
defs->get_all_aliases(aliases);
BOOST_REQUIRE_MESSAGE(aliases.empty(), "Alias deletion falied\n" << TestFixture::client().errorMsg());
std::cout << timer.duration() << " update-calendar-count(" << serverTestHarness.serverUpdateCalendarCount()
<< ")\n";
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
|