2016-02-26 17:49:07 +00:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
#include "util/index_helpers.hpp"
|
2016-02-26 17:49:07 +00:00
|
|
|
#include "util/test_file.hpp"
|
|
|
|
|
|
|
|
#include "impl/realm_coordinator.hpp"
|
|
|
|
#include "object_schema.hpp"
|
|
|
|
#include "property.hpp"
|
|
|
|
#include "results.hpp"
|
|
|
|
#include "schema.hpp"
|
|
|
|
|
|
|
|
#include <realm/commit_log.hpp>
|
|
|
|
#include <realm/group_shared.hpp>
|
|
|
|
#include <realm/link_view.hpp>
|
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2016-02-26 17:49:07 +00:00
|
|
|
using namespace realm;
|
|
|
|
|
|
|
|
TEST_CASE("Results") {
|
|
|
|
InMemoryTestFile config;
|
|
|
|
config.cache = false;
|
|
|
|
config.automatic_change_notifications = false;
|
|
|
|
config.schema = std::make_unique<Schema>(Schema{
|
|
|
|
{"object", "", {
|
|
|
|
{"value", PropertyTypeInt},
|
|
|
|
{"link", PropertyTypeObject, "linked to object", false, false, true}
|
|
|
|
}},
|
|
|
|
{"other object", "", {
|
|
|
|
{"value", PropertyTypeInt}
|
|
|
|
}},
|
|
|
|
{"linking object", "", {
|
|
|
|
{"link", PropertyTypeObject, "object", false, false, true}
|
|
|
|
}},
|
|
|
|
{"linked to object", "", {
|
|
|
|
{"value", PropertyTypeInt}
|
|
|
|
}}
|
|
|
|
});
|
|
|
|
|
|
|
|
auto r = Realm::get_shared_realm(config);
|
|
|
|
auto coordinator = _impl::RealmCoordinator::get_existing_coordinator(config.path);
|
|
|
|
auto table = r->read_group()->get_table("class_object");
|
|
|
|
|
|
|
|
r->begin_transaction();
|
|
|
|
table->add_empty_row(10);
|
|
|
|
for (int i = 0; i < 10; ++i)
|
2016-01-08 18:13:05 +00:00
|
|
|
table->set_int(0, i, i * 2);
|
2016-02-26 17:49:07 +00:00
|
|
|
r->commit_transaction();
|
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
Results results(r, *config.schema->find("object"), table->where().greater(0, 0).less(0, 10));
|
2016-02-26 17:49:07 +00:00
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
SECTION("unsorted notifications") {
|
2016-02-26 17:49:07 +00:00
|
|
|
int notification_calls = 0;
|
2016-04-19 21:05:15 +00:00
|
|
|
CollectionChangeSet change;
|
|
|
|
auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) {
|
2016-02-26 17:49:07 +00:00
|
|
|
REQUIRE_FALSE(err);
|
2016-01-08 18:13:05 +00:00
|
|
|
change = c;
|
2016-02-26 17:49:07 +00:00
|
|
|
++notification_calls;
|
|
|
|
});
|
|
|
|
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-02-26 17:49:07 +00:00
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
auto write = [&](auto&& f) {
|
|
|
|
r->begin_transaction();
|
|
|
|
f();
|
|
|
|
r->commit_transaction();
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
};
|
|
|
|
|
2016-02-26 17:49:07 +00:00
|
|
|
SECTION("initial results are delivered") {
|
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
}
|
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
SECTION("notifications are sent asynchronously") {
|
2016-02-26 17:49:07 +00:00
|
|
|
r->begin_transaction();
|
2016-01-08 18:13:05 +00:00
|
|
|
table->set_int(0, 0, 4);
|
2016-02-26 17:49:07 +00:00
|
|
|
r->commit_transaction();
|
|
|
|
|
|
|
|
REQUIRE(notification_calls == 1);
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-02-26 17:49:07 +00:00
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
}
|
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
SECTION("notifications are not delivered when the token is destroyed before they are calculated") {
|
2016-02-26 17:49:07 +00:00
|
|
|
r->begin_transaction();
|
2016-01-08 18:13:05 +00:00
|
|
|
table->set_int(0, 0, 4);
|
2016-02-26 17:49:07 +00:00
|
|
|
r->commit_transaction();
|
|
|
|
|
|
|
|
REQUIRE(notification_calls == 1);
|
2016-01-08 18:13:05 +00:00
|
|
|
token = {};
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(notification_calls == 1);
|
2016-02-26 17:49:07 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
SECTION("notifications are not delivered when the token is destroyed before they are delivered") {
|
2016-02-26 17:49:07 +00:00
|
|
|
r->begin_transaction();
|
2016-01-08 18:13:05 +00:00
|
|
|
table->set_int(0, 0, 4);
|
2016-02-26 17:49:07 +00:00
|
|
|
r->commit_transaction();
|
|
|
|
|
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
coordinator->on_change();
|
2016-01-08 18:13:05 +00:00
|
|
|
token = {};
|
2016-02-26 17:49:07 +00:00
|
|
|
r->notify();
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(notification_calls == 1);
|
2016-02-26 17:49:07 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
SECTION("notifications are delivered when a new callback is added from within a callback") {
|
|
|
|
NotificationToken token2, token3;
|
|
|
|
bool called = false;
|
2016-04-19 21:05:15 +00:00
|
|
|
token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
|
|
|
token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
2016-01-08 18:13:05 +00:00
|
|
|
called = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(called);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("notifications are not delivered when a callback is removed from within a callback") {
|
|
|
|
NotificationToken token2, token3;
|
2016-04-19 21:05:15 +00:00
|
|
|
token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
2016-01-08 18:13:05 +00:00
|
|
|
token3 = {};
|
|
|
|
});
|
2016-04-19 21:05:15 +00:00
|
|
|
token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(false);
|
|
|
|
});
|
|
|
|
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("removing the current callback does not stop later ones from being called") {
|
|
|
|
NotificationToken token2, token3;
|
|
|
|
bool called = false;
|
2016-04-19 21:05:15 +00:00
|
|
|
token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
2016-01-08 18:13:05 +00:00
|
|
|
token2 = {};
|
|
|
|
});
|
2016-04-19 21:05:15 +00:00
|
|
|
token3 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr) {
|
2016-01-08 18:13:05 +00:00
|
|
|
called = true;
|
|
|
|
});
|
2016-02-26 17:49:07 +00:00
|
|
|
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
|
|
|
|
REQUIRE(called);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("modifications to unrelated tables do not send notifications") {
|
|
|
|
write([&] {
|
|
|
|
r->read_group()->get_table("class_other object")->add_empty_row();
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("irrelevant modifications to linked tables do not send notifications") {
|
|
|
|
write([&] {
|
|
|
|
r->read_group()->get_table("class_linked to object")->add_empty_row();
|
|
|
|
});
|
2016-02-26 17:49:07 +00:00
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
}
|
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
SECTION("irrelevant modifications to linking tables do not send notifications") {
|
|
|
|
write([&] {
|
|
|
|
r->read_group()->get_table("class_linking object")->add_empty_row();
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("modifications that leave a non-matching row non-matching do not send notifications") {
|
|
|
|
write([&] {
|
|
|
|
table->set_int(0, 6, 13);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("deleting non-matching rows does not send a notification") {
|
|
|
|
write([&] {
|
|
|
|
table->move_last_over(0);
|
|
|
|
table->move_last_over(6);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("modifying a matching row and leaving it matching marks that row as modified") {
|
|
|
|
write([&] {
|
|
|
|
table->set_int(0, 1, 3);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
REQUIRE_INDICES(change.modifications, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("modifying a matching row to no longer match marks that row as deleted") {
|
|
|
|
write([&] {
|
|
|
|
table->set_int(0, 2, 0);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
REQUIRE_INDICES(change.deletions, 1);
|
|
|
|
}
|
|
|
|
|
2016-03-04 19:19:33 +00:00
|
|
|
SECTION("modifying a non-matching row to match marks that row as inserted, but not modified") {
|
2016-01-08 18:13:05 +00:00
|
|
|
write([&] {
|
|
|
|
table->set_int(0, 7, 3);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
REQUIRE_INDICES(change.insertions, 4);
|
2016-03-04 19:19:33 +00:00
|
|
|
REQUIRE(change.modifications.empty());
|
2016-01-08 18:13:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("deleting a matching row marks that row as deleted") {
|
|
|
|
write([&] {
|
|
|
|
table->move_last_over(3);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
REQUIRE_INDICES(change.deletions, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("moving a matching row via deletion marks that row as moved") {
|
|
|
|
write([&] {
|
|
|
|
table->where().greater_equal(0, 10).find_all().clear(RemoveMode::unordered);
|
|
|
|
table->move_last_over(0);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
REQUIRE_MOVES(change, {3, 0});
|
|
|
|
}
|
|
|
|
|
2016-02-26 17:49:07 +00:00
|
|
|
SECTION("modifications from multiple transactions are collapsed") {
|
|
|
|
r->begin_transaction();
|
2016-01-08 18:13:05 +00:00
|
|
|
table->set_int(0, 0, 6);
|
2016-02-26 17:49:07 +00:00
|
|
|
r->commit_transaction();
|
|
|
|
|
2016-03-08 19:19:13 +00:00
|
|
|
coordinator->on_change();
|
|
|
|
|
2016-02-26 17:49:07 +00:00
|
|
|
r->begin_transaction();
|
|
|
|
table->set_int(0, 1, 0);
|
|
|
|
r->commit_transaction();
|
|
|
|
|
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
coordinator->on_change();
|
|
|
|
r->notify();
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
}
|
2016-03-08 19:19:13 +00:00
|
|
|
|
2016-03-11 00:58:43 +00:00
|
|
|
SECTION("inserting a row then modifying it in a second transaction does not report it as modified") {
|
|
|
|
r->begin_transaction();
|
|
|
|
size_t ndx = table->add_empty_row();
|
|
|
|
table->set_int(0, ndx, 6);
|
|
|
|
r->commit_transaction();
|
|
|
|
|
|
|
|
coordinator->on_change();
|
|
|
|
|
|
|
|
r->begin_transaction();
|
|
|
|
table->set_int(0, ndx, 7);
|
|
|
|
r->commit_transaction();
|
|
|
|
|
|
|
|
advance_and_notify(*r);
|
|
|
|
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
REQUIRE_INDICES(change.insertions, 4);
|
|
|
|
REQUIRE(change.modifications.empty());
|
|
|
|
}
|
|
|
|
|
2016-03-08 19:19:13 +00:00
|
|
|
SECTION("notifications are not delivered when collapsing transactions results in no net change") {
|
|
|
|
r->begin_transaction();
|
|
|
|
size_t ndx = table->add_empty_row();
|
|
|
|
table->set_int(0, ndx, 5);
|
|
|
|
r->commit_transaction();
|
|
|
|
|
|
|
|
coordinator->on_change();
|
|
|
|
|
|
|
|
r->begin_transaction();
|
|
|
|
table->move_last_over(ndx);
|
|
|
|
r->commit_transaction();
|
|
|
|
|
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
coordinator->on_change();
|
|
|
|
r->notify();
|
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
}
|
2016-03-11 22:43:08 +00:00
|
|
|
|
2016-03-22 14:57:50 +00:00
|
|
|
SECTION("the first call of a notification can include changes if it previously ran for a different callback") {
|
2016-04-19 21:05:15 +00:00
|
|
|
auto token2 = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr) {
|
2016-03-22 14:57:50 +00:00
|
|
|
REQUIRE(!c.empty());
|
2016-03-11 22:43:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
write([&] {
|
|
|
|
table->set_int(0, table->add_empty_row(), 5);
|
|
|
|
});
|
|
|
|
}
|
2016-01-08 18:13:05 +00:00
|
|
|
}
|
2016-02-26 17:49:07 +00:00
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
// Sort in descending order
|
|
|
|
results = results.sort({{0}, {false}});
|
|
|
|
|
|
|
|
SECTION("sorted notifications") {
|
|
|
|
int notification_calls = 0;
|
2016-04-19 21:05:15 +00:00
|
|
|
CollectionChangeSet change;
|
|
|
|
auto token = results.add_notification_callback([&](CollectionChangeSet c, std::exception_ptr err) {
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE_FALSE(err);
|
|
|
|
change = c;
|
|
|
|
++notification_calls;
|
|
|
|
});
|
|
|
|
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
|
|
|
|
auto write = [&](auto&& f) {
|
2016-02-26 17:49:07 +00:00
|
|
|
r->begin_transaction();
|
2016-01-08 18:13:05 +00:00
|
|
|
f();
|
2016-02-26 17:49:07 +00:00
|
|
|
r->commit_transaction();
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SECTION("modifications that leave a non-matching row non-matching do not send notifications") {
|
|
|
|
write([&] {
|
|
|
|
table->set_int(0, 6, 13);
|
|
|
|
});
|
2016-02-26 17:49:07 +00:00
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
}
|
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
SECTION("deleting non-matching rows does not send a notification") {
|
|
|
|
write([&] {
|
|
|
|
table->move_last_over(0);
|
|
|
|
table->move_last_over(6);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("modifying a matching row and leaving it matching marks that row as modified") {
|
|
|
|
write([&] {
|
|
|
|
table->set_int(0, 1, 3);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
REQUIRE_INDICES(change.modifications, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("modifying a matching row to no longer match marks that row as deleted") {
|
|
|
|
write([&] {
|
|
|
|
table->set_int(0, 2, 0);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
REQUIRE_INDICES(change.deletions, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("modifying a non-matching row to match marks that row as inserted") {
|
|
|
|
write([&] {
|
|
|
|
table->set_int(0, 7, 3);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
REQUIRE_INDICES(change.insertions, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("deleting a matching row marks that row as deleted") {
|
|
|
|
write([&] {
|
|
|
|
table->move_last_over(3);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
REQUIRE_INDICES(change.deletions, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("moving a matching row via deletion does not send a notification") {
|
|
|
|
write([&] {
|
|
|
|
table->where().greater_equal(0, 10).find_all().clear(RemoveMode::unordered);
|
|
|
|
table->move_last_over(0);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("modifying a matching row to change its position sends insert+delete") {
|
|
|
|
write([&] {
|
|
|
|
table->set_int(0, 2, 9);
|
|
|
|
});
|
|
|
|
REQUIRE(notification_calls == 2);
|
|
|
|
REQUIRE_INDICES(change.deletions, 2);
|
|
|
|
REQUIRE_INDICES(change.insertions, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("modifications from multiple transactions are collapsed") {
|
|
|
|
r->begin_transaction();
|
|
|
|
table->set_int(0, 0, 5);
|
|
|
|
r->commit_transaction();
|
|
|
|
|
2016-02-26 17:49:07 +00:00
|
|
|
r->begin_transaction();
|
2016-01-08 18:13:05 +00:00
|
|
|
table->set_int(0, 1, 0);
|
2016-02-26 17:49:07 +00:00
|
|
|
r->commit_transaction();
|
|
|
|
|
|
|
|
REQUIRE(notification_calls == 1);
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(notification_calls == 2);
|
2016-02-26 17:49:07 +00:00
|
|
|
}
|
2016-03-22 18:37:05 +00:00
|
|
|
|
|
|
|
SECTION("moving a matching row by deleting all other rows") {
|
|
|
|
r->begin_transaction();
|
|
|
|
table->clear();
|
|
|
|
table->add_empty_row(2);
|
|
|
|
table->set_int(0, 0, 15);
|
|
|
|
table->set_int(0, 1, 5);
|
|
|
|
r->commit_transaction();
|
|
|
|
advance_and_notify(*r);
|
|
|
|
|
|
|
|
write([&] {
|
|
|
|
table->move_last_over(0);
|
|
|
|
table->add_empty_row();
|
|
|
|
table->set_int(0, 1, 3);
|
|
|
|
});
|
|
|
|
|
|
|
|
REQUIRE(notification_calls == 3);
|
|
|
|
REQUIRE(change.deletions.empty());
|
|
|
|
REQUIRE_INDICES(change.insertions, 1);
|
|
|
|
}
|
2016-02-26 17:49:07 +00:00
|
|
|
}
|
|
|
|
}
|
2016-01-08 18:13:05 +00:00
|
|
|
|
|
|
|
TEST_CASE("Async Results error handling") {
|
|
|
|
InMemoryTestFile config;
|
|
|
|
config.cache = false;
|
|
|
|
config.automatic_change_notifications = false;
|
|
|
|
config.schema = std::make_unique<Schema>(Schema{
|
|
|
|
{"object", "", {
|
|
|
|
{"value", PropertyTypeInt},
|
|
|
|
}},
|
|
|
|
});
|
|
|
|
|
|
|
|
auto r = Realm::get_shared_realm(config);
|
|
|
|
auto coordinator = _impl::RealmCoordinator::get_existing_coordinator(config.path);
|
|
|
|
Results results(r, *config.schema->find("object"), *r->read_group()->get_table("class_object"));
|
|
|
|
|
2016-03-04 18:54:13 +00:00
|
|
|
class OpenFileLimiter {
|
|
|
|
public:
|
|
|
|
OpenFileLimiter()
|
|
|
|
{
|
|
|
|
// Set the max open files to zero so that opening new files will fail
|
|
|
|
getrlimit(RLIMIT_NOFILE, &m_old);
|
|
|
|
rlimit rl = m_old;
|
|
|
|
rl.rlim_cur = 0;
|
|
|
|
setrlimit(RLIMIT_NOFILE, &rl);
|
|
|
|
}
|
|
|
|
|
|
|
|
~OpenFileLimiter()
|
|
|
|
{
|
|
|
|
setrlimit(RLIMIT_NOFILE, &m_old);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
rlimit m_old;
|
|
|
|
};
|
|
|
|
|
2016-01-08 18:13:05 +00:00
|
|
|
SECTION("error when opening the advancer SG") {
|
2016-03-04 18:54:13 +00:00
|
|
|
OpenFileLimiter limiter;
|
2016-01-08 18:13:05 +00:00
|
|
|
|
|
|
|
SECTION("error is delivered asynchronously") {
|
|
|
|
bool called = false;
|
2016-04-19 21:05:15 +00:00
|
|
|
auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(err);
|
|
|
|
called = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
REQUIRE(!called);
|
|
|
|
coordinator->on_change();
|
|
|
|
REQUIRE(!called);
|
|
|
|
r->notify();
|
|
|
|
REQUIRE(called);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("adding another callback does not send the error again") {
|
|
|
|
bool called = false;
|
2016-04-19 21:05:15 +00:00
|
|
|
auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(err);
|
|
|
|
REQUIRE_FALSE(called);
|
|
|
|
called = true;
|
|
|
|
});
|
|
|
|
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
|
|
|
|
bool called2 = false;
|
2016-04-19 21:05:15 +00:00
|
|
|
auto token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(err);
|
|
|
|
REQUIRE_FALSE(called2);
|
|
|
|
called2 = true;
|
|
|
|
});
|
|
|
|
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(called2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("error when opening the executor SG") {
|
|
|
|
SECTION("error is delivered asynchronously") {
|
|
|
|
bool called = false;
|
2016-04-19 21:05:15 +00:00
|
|
|
auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(err);
|
|
|
|
called = true;
|
|
|
|
});
|
2016-03-04 18:54:13 +00:00
|
|
|
OpenFileLimiter limiter;
|
2016-01-08 18:13:05 +00:00
|
|
|
|
|
|
|
REQUIRE(!called);
|
|
|
|
coordinator->on_change();
|
|
|
|
REQUIRE(!called);
|
|
|
|
r->notify();
|
|
|
|
REQUIRE(called);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("adding another callback does not send the error again") {
|
|
|
|
bool called = false;
|
2016-04-19 21:05:15 +00:00
|
|
|
auto token = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(err);
|
|
|
|
REQUIRE_FALSE(called);
|
|
|
|
called = true;
|
|
|
|
});
|
2016-03-04 18:54:13 +00:00
|
|
|
OpenFileLimiter limiter;
|
2016-01-08 18:13:05 +00:00
|
|
|
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
|
|
|
|
bool called2 = false;
|
2016-04-19 21:05:15 +00:00
|
|
|
auto token2 = results.add_notification_callback([&](CollectionChangeSet, std::exception_ptr err) {
|
2016-01-08 18:13:05 +00:00
|
|
|
REQUIRE(err);
|
|
|
|
REQUIRE_FALSE(called2);
|
|
|
|
called2 = true;
|
|
|
|
});
|
|
|
|
|
2016-03-10 19:02:59 +00:00
|
|
|
advance_and_notify(*r);
|
2016-01-08 18:13:05 +00:00
|
|
|
|
|
|
|
REQUIRE(called2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|