File: TestOrderCmd.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 (253 lines) | stat: -rw-r--r-- 10,691 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
/*
 * 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/base/cts/ClientToServerCmd.hpp"
#include "ecflow/core/Chrono.hpp"
#include "ecflow/core/Timer.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;

///
/// \note This is used to INVOKE a SINGLE test.
/// Making it easier for Easier for debugging and development
///

BOOST_AUTO_TEST_SUITE(S_Test)

BOOST_AUTO_TEST_SUITE(T_OrderCmd)

std::vector<std::string> to_string_vec(const std::vector<suite_ptr>& sv) {
    std::vector<std::string> r;
    r.reserve(sv.size());
    for (size_t i = 0; i < sv.size(); i++) {
        r.push_back(sv[i]->name());
    }
    return r;
}

std::vector<std::string> to_string_vec(const std::vector<node_ptr>& sv) {
    std::vector<std::string> r;
    r.reserve(sv.size());
    for (size_t i = 0; i < sv.size(); i++) {
        r.push_back(sv[i]->name());
    }
    return r;
}

void test_ordering() {

    TestFixture::client().set_throw_on_error(true);
    std::vector<std::string> str_a_b_c;
    str_a_b_c.push_back("a");
    str_a_b_c.push_back("b");
    str_a_b_c.push_back("c");
    std::vector<std::string> str_c_b_a;
    str_c_b_a.push_back("c");
    str_c_b_a.push_back("b");
    str_c_b_a.push_back("a");
    std::vector<std::string> str_b_c_a;
    str_b_c_a.push_back("b");
    str_b_c_a.push_back("c");
    str_b_c_a.push_back("a");
    std::vector<std::string> str_b_a_c;
    str_b_a_c.push_back("b");
    str_b_a_c.push_back("a");
    str_b_a_c.push_back("c");
    std::vector<std::string> str_a_c_b;
    str_a_c_b.push_back("a");
    str_a_c_b.push_back("c");
    str_a_c_b.push_back("b");
    TestFixture::client().sync_local(); // First sync_local will do a full sync
    {
        // TEST SUITE ORDERING
        TestFixture::client().order("/a", NOrder::toString(NOrder::ORDER));
        TestFixture::client().sync_local();
        BOOST_CHECK_MESSAGE(!TestFixture::client().server_reply().full_sync(), "Expected incremental sync");
        BOOST_CHECK_MESSAGE(to_string_vec(TestFixture::client().defs()->suiteVec()) == str_c_b_a,
                            "Order not as expected");

        TestFixture::client().order("/a", NOrder::toString(NOrder::ALPHA));
        TestFixture::client().sync_local();
        BOOST_CHECK_MESSAGE(!TestFixture::client().server_reply().full_sync(), "Expected incremental sync");
        BOOST_CHECK_MESSAGE(to_string_vec(TestFixture::client().defs()->suiteVec()) == str_a_b_c,
                            "Order not as expected");

        TestFixture::client().order("/a", NOrder::toString(NOrder::BOTTOM));
        TestFixture::client().sync_local();
        BOOST_CHECK_MESSAGE(!TestFixture::client().server_reply().full_sync(), "Expected incremental sync");
        BOOST_CHECK_MESSAGE(to_string_vec(TestFixture::client().defs()->suiteVec()) == str_b_c_a,
                            "Order not as expected");

        TestFixture::client().order("/a", NOrder::toString(NOrder::ALPHA));
        TestFixture::client().order("/a", NOrder::toString(NOrder::DOWN));
        TestFixture::client().sync_local();
        BOOST_CHECK_MESSAGE(!TestFixture::client().server_reply().full_sync(), "Expected incremental sync");
        BOOST_CHECK_MESSAGE(to_string_vec(TestFixture::client().defs()->suiteVec()) == str_b_a_c,
                            "Order not as expected");

        TestFixture::client().order("/a", NOrder::toString(NOrder::ALPHA));
        TestFixture::client().order("/c", NOrder::toString(NOrder::UP));
        TestFixture::client().sync_local();
        BOOST_CHECK_MESSAGE(!TestFixture::client().server_reply().full_sync(), "Expected incremental sync");
        BOOST_CHECK_MESSAGE(to_string_vec(TestFixture::client().defs()->suiteVec()) == str_a_c_b,
                            "Order not as expected");
    }
    {
        // TEST FAMILY ordering
        TestFixture::client().order("/a/a", NOrder::toString(NOrder::ORDER));
        TestFixture::client().sync_local();
        BOOST_CHECK_MESSAGE(!TestFixture::client().server_reply().full_sync(), "Expected incremental sync");
        BOOST_CHECK_MESSAGE(to_string_vec(TestFixture::client().defs()->suiteVec()[0]->nodeVec()) == str_c_b_a,
                            "Order not as expected");

        TestFixture::client().order("/a/a", NOrder::toString(NOrder::ALPHA));
        TestFixture::client().sync_local();
        BOOST_CHECK_MESSAGE(!TestFixture::client().server_reply().full_sync(), "Expected incremental sync");
        BOOST_CHECK_MESSAGE(to_string_vec(TestFixture::client().defs()->suiteVec()[0]->nodeVec()) == str_a_b_c,
                            "Order not as expected");

        TestFixture::client().order("/a/a", NOrder::toString(NOrder::BOTTOM));
        TestFixture::client().sync_local();
        BOOST_CHECK_MESSAGE(!TestFixture::client().server_reply().full_sync(), "Expected incremental sync");
        BOOST_CHECK_MESSAGE(to_string_vec(TestFixture::client().defs()->suiteVec()[0]->nodeVec()) == str_b_c_a,
                            "Order not as expected");

        TestFixture::client().order("/a/a", NOrder::toString(NOrder::ALPHA));
        TestFixture::client().order("/a/a", NOrder::toString(NOrder::DOWN));
        TestFixture::client().sync_local();
        BOOST_CHECK_MESSAGE(!TestFixture::client().server_reply().full_sync(), "Expected incremental sync");
        BOOST_CHECK_MESSAGE(to_string_vec(TestFixture::client().defs()->suiteVec()[0]->nodeVec()) == str_b_a_c,
                            "Order not as expected");

        TestFixture::client().order("/a/a", NOrder::toString(NOrder::ALPHA));
        TestFixture::client().order("/a/c", NOrder::toString(NOrder::UP));
        TestFixture::client().sync_local();
        BOOST_CHECK_MESSAGE(!TestFixture::client().server_reply().full_sync(), "Expected incremental sync");
        BOOST_CHECK_MESSAGE(to_string_vec(TestFixture::client().defs()->suiteVec()[0]->nodeVec()) == str_a_c_b,
                            "Order not as expected");
    }
}

BOOST_AUTO_TEST_CASE(test_change_order) {
    ECF_NAME_THIS_TEST();

    DurationTimer timer;
    TestClean clean_at_start_and_end;

    /// NOT: We *DONT* need to run the jobs for this TEST
    std::vector<std::string> str_a_b_c;
    str_a_b_c.push_back("a");
    str_a_b_c.push_back("b");
    str_a_b_c.push_back("c");
    Defs theDefs;
    {
        for (size_t s = 0; s < str_a_b_c.size(); s++) {
            suite_ptr suite = theDefs.add_suite(str_a_b_c[s]);
            suite->addDefStatus(DState::SUSPENDED); // NO NEED to run jobs for this test:
            for (size_t f = 0; f < str_a_b_c.size(); f++) {
                family_ptr fam = suite->add_family(str_a_b_c[f]);
                for (size_t t = 0; t < str_a_b_c.size(); t++) {
                    fam->add_task(str_a_b_c[t]);
                }
            }
        }
    }

    // The test harness will create corresponding directory structure & default ecf file
    ServerTestHarness serverTestHarness;
    serverTestHarness.run(theDefs,
                          ServerTestHarness::testDataDefsLocation("test_change_order.def"),
                          1 /*timeout*/,
                          false /* don't wait for test to finish */);

    test_ordering();

    std::cout << timer.duration() << " update-calendar-count(" << serverTestHarness.serverUpdateCalendarCount()
              << ")\n";
}

BOOST_AUTO_TEST_CASE(test_handle_change_order) {
    ECF_NAME_THIS_TEST();

    DurationTimer timer;
    TestClean clean_at_start_and_end;

    std::vector<std::string> str_a_b_c;
    str_a_b_c.push_back("a");
    str_a_b_c.push_back("b");
    str_a_b_c.push_back("c");
    std::vector<std::string> suite_a_b_c_d_e;
    suite_a_b_c_d_e.push_back("a");
    suite_a_b_c_d_e.push_back("b");
    suite_a_b_c_d_e.push_back("c");
    suite_a_b_c_d_e.push_back("d");
    suite_a_b_c_d_e.push_back("e");
    Defs theDefs;
    {
        for (size_t s = 0; s < suite_a_b_c_d_e.size(); s++) {
            suite_ptr suite = theDefs.add_suite(suite_a_b_c_d_e[s]);
            suite->addDefStatus(DState::SUSPENDED); // NO NEED to run jobs for this test:
            for (size_t f = 0; f < str_a_b_c.size(); f++) {
                family_ptr fam = suite->add_family(str_a_b_c[f]);
                for (size_t t = 0; t < str_a_b_c.size(); t++) {
                    fam->add_task(str_a_b_c[t]);
                }
            }
        }
    }

    // The test harness will create corresponding directory structure & default ecf file
    ServerTestHarness serverTestHarness;
    serverTestHarness.run(theDefs,
                          ServerTestHarness::testDataDefsLocation("test_change_order.def"),
                          1 /*timeout*/,
                          false /* don't wait for test to finish */);

    TestFixture::client().set_throw_on_error(true);
    TestFixture::client().sync_local(); // First sync_local will do a full sync
    {
        // register suites a,b,c
        std::vector<std::string> suites_a_b_c;
        suites_a_b_c.push_back("a");
        suites_a_b_c.push_back("b");
        suites_a_b_c.push_back("c");
        TestFixture::client().ch_register(false /*add new suites to handle*/, suites_a_b_c);

        // Check the sync_local() does a full sync for our handle
        TestFixture::client().sync_local();
        BOOST_CHECK_MESSAGE(TestFixture::client().server_reply().in_sync(), "Expected to be in sync after syn_local()");
        BOOST_CHECK_MESSAGE(TestFixture::client().server_reply().full_sync(),
                            "Expected a full_sync() after registering");
        BOOST_CHECK_MESSAGE(TestFixture::client().defs()->suiteVec().size() == 3, "Expected sync to return 3 suites.");
    }

    // Do same test, this time sync_local will only return suite a,b,c (i.e suite d,e not registered and hence left out)
    // Ording should still be applied to the whole suite.
    test_ordering();

    std::cout << timer.duration() << " update-calendar-count(" << serverTestHarness.serverUpdateCalendarCount()
              << ")\n";
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE_END()