~stolowski/unity-scopes-api/fix-1393382-rtm

« back to all changes in this revision

Viewing changes to test/gtest/scopes/Activation/Activation_test.cpp

  • Committer: Pawel Stolowski
  • Date: 2014-11-04 14:33:07 UTC
  • mfrom: (241.1.20 unity-scopes-api)
  • Revision ID: pawel.stolowski@canonical.com-20141104143307-cs70gjyowjtwpk69
Merged trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    {
43
43
        push_func_ = push_func;
44
44
    };
 
45
 
45
46
    void push(CategorisedResult result) override
46
47
    {
47
48
        push_func_(result);
48
49
    }
 
50
 
49
51
    void finished(CompletionDetails const&) override {}
50
52
 
51
53
    std::function<void(CategorisedResult)> push_func_;
57
59
    void wait_until_finished()
58
60
    {
59
61
        std::unique_lock<std::mutex> lock(mutex_);
60
 
        cond_.wait(lock, [this] { return this->query_complete_; });
 
62
        auto ok = cond_.wait_for(lock, std::chrono::seconds(2), [this] { return this->query_complete_; });
 
63
        ASSERT_TRUE(ok) << "query did not complete after 2 seconds";
61
64
    }
62
65
 
63
66
protected:
70
73
    }
71
74
 
72
75
private:
73
 
    bool query_complete_;
 
76
    bool query_complete_ = false;
74
77
    std::mutex mutex_;
75
78
    std::condition_variable cond_;
76
 
 
77
79
};
78
80
 
79
81
class SearchReceiver : public SearchListenerBase, public WaitUntilFinished
84
86
        this->result = std::make_shared<Result>(result);
85
87
    }
86
88
 
87
 
    virtual void finished(CompletionDetails const&) override
 
89
    virtual void finished(CompletionDetails const& details) override
88
90
    {
 
91
        EXPECT_EQ(CompletionDetails::OK, details.status()) << details.message();
89
92
        notify();
90
93
    }
91
94
 
145
148
    {
146
149
        std::shared_ptr<CategorisedResult> received_result;
147
150
        auto df = []() -> void {};
148
 
        auto runtime = internal::RuntimeImpl::create("", "Runtime.ini");
 
151
        auto runtime = internal::RuntimeImpl::create("", TEST_DIR "/Runtime.ini");
149
152
        auto receiver = std::make_shared<DummyReceiver>([&received_result](CategorisedResult result)
150
153
                {
151
154
                    received_result.reset(new CategorisedResult(result));
178
181
    {
179
182
        std::shared_ptr<CategorisedResult> received_result;
180
183
        auto df = []() -> void {};
181
 
        auto runtime = internal::RuntimeImpl::create("", "Runtime.ini");
 
184
        auto runtime = internal::RuntimeImpl::create("", TEST_DIR "/Runtime.ini");
182
185
        auto receiver = std::make_shared<DummyReceiver>([&received_result](CategorisedResult result)
183
186
                {
184
187
                    received_result.reset(new CategorisedResult(result));
230
233
    {
231
234
        std::shared_ptr<CategorisedResult> received_result;
232
235
        auto df = []() -> void {};
233
 
        auto runtime = internal::RuntimeImpl::create("", "Runtime.ini");
 
236
        auto runtime = internal::RuntimeImpl::create("", TEST_DIR "/Runtime.ini");
234
237
        auto receiver = std::make_shared<DummyReceiver>([&received_result](CategorisedResult result)
235
238
                {
236
239
                    received_result.reset(new CategorisedResult(result));
288
291
    {
289
292
        std::shared_ptr<CategorisedResult> received_result;
290
293
        auto df = []() -> void {};
291
 
        auto runtime = internal::RuntimeImpl::create("", "Runtime.ini");
 
294
        auto runtime = internal::RuntimeImpl::create("", TEST_DIR "/Runtime.ini");
292
295
        auto receiver = std::make_shared<DummyReceiver>([&received_result](CategorisedResult result)
293
296
                {
294
297
                    received_result.reset(new CategorisedResult(result));
342
345
    {
343
346
        std::shared_ptr<CategorisedResult> received_result;
344
347
        auto df = []() -> void {};
345
 
        auto runtime = internal::RuntimeImpl::create("", "Runtime.ini");
 
348
        auto runtime = internal::RuntimeImpl::create("", TEST_DIR "/Runtime.ini");
346
349
        auto receiver = std::make_shared<DummyReceiver>([&received_result](CategorisedResult result)
347
350
                {
348
351
                    received_result.reset(new CategorisedResult(result));
397
400
    {
398
401
        std::shared_ptr<CategorisedResult> received_result;
399
402
        auto df = []() -> void {};
400
 
        auto runtime = internal::RuntimeImpl::create("", "Runtime.ini");
 
403
        auto runtime = internal::RuntimeImpl::create("", TEST_DIR "/Runtime.ini");
401
404
        auto receiver = std::make_shared<DummyReceiver>([&received_result](CategorisedResult result)
402
405
                {
403
406
                    received_result.reset(new CategorisedResult(result));
456
459
    {
457
460
        std::shared_ptr<CategorisedResult> received_result;
458
461
        auto df = []() -> void {};
459
 
        auto runtime = internal::RuntimeImpl::create("", "Runtime.ini");
 
462
        auto runtime = internal::RuntimeImpl::create("", TEST_DIR "/Runtime.ini");
460
463
        auto receiver = std::make_shared<DummyReceiver>([&received_result](CategorisedResult result)
461
464
                {
462
465
                    received_result.reset(new CategorisedResult(result));
510
513
struct RaiiScopeThread
511
514
{
512
515
    ScopeType scope;
513
 
    Runtime::SPtr runtime;
 
516
    Runtime::UPtr runtime;
514
517
    std::thread scope_thread;
515
518
 
516
 
    RaiiScopeThread(std::string const& scope_id, std::string const& configfile)
517
 
        : runtime(Runtime::create_scope_runtime(scope_id, configfile)),
 
519
    RaiiScopeThread(Runtime::UPtr rt, std::string const& configfile)
 
520
        : runtime(move(rt)),
518
521
          scope_thread([this, configfile]{ runtime->run_scope(&scope, configfile, ""); })
519
522
    {
520
 
        std::this_thread::sleep_for(std::chrono::milliseconds(500));
521
523
    }
522
524
 
523
525
    ~RaiiScopeThread()
532
534
 
533
535
RuntimeImpl::SPtr run_test_registry()
534
536
{
535
 
    RuntimeImpl::SPtr runtime = RuntimeImpl::create("TestRegistry", "Runtime.ini");
536
 
    MiddlewareBase::SPtr middleware = runtime->factory()->create("TestRegistry", "Zmq", "Zmq.ini");
 
537
    RuntimeImpl::SPtr runtime = RuntimeImpl::create("TestRegistry", TEST_DIR "/Runtime.ini");
 
538
    MiddlewareBase::SPtr middleware = runtime->factory()->create("TestRegistry", "Zmq", TEST_DIR "/Zmq.ini");
537
539
    RegistryObject::SPtr reg_obj(std::make_shared<RegistryObject>(*death_observer, std::make_shared<Executor>(), middleware));
538
540
    middleware->add_registry_object("TestRegistry", reg_obj);
539
541
    return runtime;
543
545
TEST(Activation, scope)
544
546
{
545
547
    auto reg_rt = run_test_registry();
546
 
    RaiiScopeThread<TestScope> scope_thread("TestScope", "Runtime.ini");
 
548
 
 
549
    auto scope_rt = Runtime::create_scope_runtime("TestScope", TEST_DIR "/Runtime.ini");
 
550
    RaiiScopeThread<TestScope> scope_thread(move(scope_rt), TEST_DIR "/Runtime.ini");
547
551
 
548
552
    // parent: connect to scope and run a query
549
 
    auto rt = internal::RuntimeImpl::create("", "Runtime.ini");
550
 
    auto mw = rt->factory()->create("TestScope", "Zmq", "Zmq.ini");
 
553
    auto rt = internal::RuntimeImpl::create("", TEST_DIR "/Runtime.ini");
 
554
    auto mw = rt->factory()->create("TestScope", "Zmq", TEST_DIR "/Zmq.ini");
551
555
    mw->start();
552
556
    auto proxy = mw->create_scope_proxy("TestScope");
553
557
    auto scope = internal::ScopeImpl::create(proxy, rt.get(), "TestScope");