~michihenning/unity-scopes-api/reconnect-fix

« back to all changes in this revision

Viewing changes to test/gtest/scopes/Runtime/Runtime_test.cpp

  • Committer: Tarmac
  • Author(s): Michi Henning
  • Date: 2014-09-05 10:46:54 UTC
  • mfrom: (449.2.2 more-race-fixes)
  • Revision ID: tarmac-20140905104654-x94r317i02h3snbx
Wait for queued oneway requests to be picked up by an invocation thread during shut-down, to avoid destroying the outgoing oneway queue while invocations are potentially still sitting there, waiting to be written to Zmq.

Fixed stale comment in CMakeLists.txt.

Minor doc fixes.

Removed incorrect MallocMessageBuilder when marhsaling unknown exception.

Added exception checking if outgoing invocation pools can't be created.

Added instrumentation to some tests that fail on Jenkins to report load (of dubious benefit, at least on amd and i386, probably useful for arm).

Fixed race conditions in Runtime_test due to non-interlocked accessed of various count variables.

Fixed a few minor issues in RegistryI test with incorrect initial process count and missing initialization in Receiver.

Approved by Pete Woods, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
        EXPECT_EQ("art", result.art());
89
89
        EXPECT_EQ("dnd_uri", result.dnd_uri());
90
90
        count_++;
 
91
        lock_guard<mutex> lock(mutex_);
91
92
        last_result_ = std::make_shared<Result>(result);
92
93
    }
93
94
 
111
112
        EXPECT_EQ(1, annotation_count_);
112
113
        EXPECT_EQ(2, info_count_);
113
114
 
114
 
        ASSERT_EQ(2, details.info_list().size());
115
 
        EXPECT_EQ(OperationInfo::NoInternet, details.info_list()[0].code());
116
 
        EXPECT_EQ("Partial results returned due to no internet connection.", details.info_list()[0].message());
117
 
        EXPECT_EQ(OperationInfo::PoorInternet, details.info_list()[1].code());
118
 
        EXPECT_EQ("Partial results returned due to poor internet connection.", details.info_list()[1].message());
 
115
        EXPECT_EQ(2, details.info_list().size()); // If this assertion fails, the test hangs until Jenkins times out
 
116
        if (details.info_list().size() == 2)
 
117
        {
 
118
            EXPECT_EQ(OperationInfo::NoInternet, details.info_list()[0].code());
 
119
            EXPECT_EQ("Partial results returned due to no internet connection.", details.info_list()[0].message());
 
120
            EXPECT_EQ(OperationInfo::PoorInternet, details.info_list()[1].code());
 
121
            EXPECT_EQ("Partial results returned due to poor internet connection.", details.info_list()[1].message());
 
122
        }
119
123
 
120
124
        // Signal that the query has completed.
121
125
        unique_lock<mutex> lock(mutex_);
146
150
 
147
151
    std::shared_ptr<Result> last_result()
148
152
    {
 
153
        lock_guard<mutex> lock(mutex_);
149
154
        return last_result_;
150
155
    }
151
156
 
153
158
    bool query_complete_;
154
159
    mutex mutex_;
155
160
    condition_variable cond_;
156
 
    int count_;
157
 
    int dep_count_;
158
 
    int annotation_count_;
159
 
    int info_count_;
 
161
    atomic_int count_;
 
162
    atomic_int dep_count_;
 
163
    atomic_int annotation_count_;
 
164
    atomic_int info_count_;
160
165
    std::shared_ptr<Result> last_result_;
161
166
};
162
167
 
195
200
        EXPECT_EQ(2, data_pushes_);
196
201
        EXPECT_EQ(2, info_count_);
197
202
 
198
 
        ASSERT_EQ(2, details.info_list().size());
199
 
        EXPECT_EQ(OperationInfo::NoLocationData, details.info_list()[0].code());
200
 
        EXPECT_EQ("", details.info_list()[0].message());
201
 
        EXPECT_EQ(OperationInfo::InaccurateLocationData, details.info_list()[1].code());
202
 
        EXPECT_EQ("Partial results returned due to inaccurate location data.", details.info_list()[1].message());
 
203
        EXPECT_EQ(2, details.info_list().size());
 
204
        if (details.info_list().size() == 2)
 
205
        {
 
206
            EXPECT_EQ(OperationInfo::NoLocationData, details.info_list()[0].code());
 
207
            EXPECT_EQ("", details.info_list()[0].message());
 
208
            EXPECT_EQ(OperationInfo::InaccurateLocationData, details.info_list()[1].code());
 
209
            EXPECT_EQ("Partial results returned due to inaccurate location data.", details.info_list()[1].message());
 
210
        }
203
211
 
204
212
        // Signal that the query has completed.
205
213
        unique_lock<mutex> lock(mutex_);
232
240
    bool query_complete_;
233
241
    mutex mutex_;
234
242
    condition_variable cond_;
235
 
    int widgets_pushes_;
236
 
    int data_pushes_;
237
 
    int info_count_;
 
243
    atomic_int widgets_pushes_;
 
244
    atomic_int data_pushes_;
 
245
    atomic_int info_count_;
238
246
};
239
247
 
240
248
class PushReceiver : public SearchListenerBase
366
374
    receiver->wait_until_finished();
367
375
 
368
376
    auto result = receiver->last_result();
369
 
    ASSERT_TRUE(result.get() != nullptr);
370
 
 
371
 
    auto target = result->target_scope_proxy();
372
 
    EXPECT_TRUE(target != nullptr);
373
 
 
374
 
    auto previewer = make_shared<PreviewReceiver>();
375
 
    auto preview_ctrl = target->preview(*(result.get()), ActionMetadata("en", "phone"), previewer);
376
 
    previewer->wait_until_finished();
 
377
    EXPECT_TRUE(result.get() != nullptr);
 
378
 
 
379
    if (result.get() != nullptr)
 
380
    {
 
381
        auto target = result->target_scope_proxy();
 
382
        EXPECT_TRUE(target != nullptr);
 
383
        auto previewer = make_shared<PreviewReceiver>();
 
384
        auto preview_ctrl = target->preview(*(result.get()), ActionMetadata("en", "phone"), previewer);
 
385
        previewer->wait_until_finished();
 
386
    }
377
387
}
378
388
 
379
389
TEST(Runtime, cardinality)
454
464
    auto ctrl = scope->search("test", SearchMetadata("unused", "unused"), receiver);
455
465
    // Allow some time for the search message to get there.
456
466
    this_thread::sleep_for(chrono::milliseconds(100));
 
467
 
457
468
    // search() in the scope doesn't return for some time, so the cancel() that follows
458
469
    // is sent to the "fake" QueryCtrlProxy.
459
470
    ctrl->cancel();
460
471
    receiver->wait_until_finished();
 
472
 
461
473
    // The receiver receives its cancel from the client-side run time instead of the
462
474
    // scope because the run time short-cuts sending the cancel locally instead
463
475
    // of waiting for the cancel message from the scope. Allow some time for the
464
476
    // cancel to reach the scope before shutting down the run time, so the scope
465
477
    // can test that it received the cancel.
466
 
    this_thread::sleep_for(chrono::milliseconds(300));
 
478
    this_thread::sleep_for(chrono::milliseconds(500));
467
479
}
468
480
 
469
481
void scope_thread(Runtime::SPtr const& rt, string const& runtime_ini_file)
488
500
{
489
501
    ::testing::InitGoogleTest(&argc, argv);
490
502
 
 
503
    int rc = 0;
 
504
 
491
505
    Runtime::SPtr srt = move(Runtime::create_scope_runtime("TestScope", "Runtime.ini"));
492
506
    std::thread scope_t(scope_thread, srt, "Runtime.ini");
493
507
 
501
515
    // from a synchronous remote call.
502
516
    this_thread::sleep_for(chrono::milliseconds(500));
503
517
 
504
 
    auto rc = RUN_ALL_TESTS();
 
518
    rc = ::system("echo -n \"load average: \"; cat /proc/loadavg; vmstat --wide");
 
519
    if (rc == 0)
 
520
    {
 
521
        rc = RUN_ALL_TESTS();
 
522
    }
505
523
 
506
524
    srt->destroy();
507
525
    scope_t.join();