message: Add a test verifying that Results doesn't pin extra versions
diff: #include "sync/sync_session.hpp"
  #endif
  +namespace realm {
  +class TestHelper {
  +public:
  + static SharedGroup& get_shared_group(SharedRealm const& shared_realm)
  + {
  + return *Realm::Internal::get_shared_group(*shared_realm);
  + }
  +};
  +}
  using namespace realm;
  using namespace std::string_literals;
  @@ -1897,7 +1906,7 @@ TEST_CASE("results: notifications after move") {
  }
  }
  -TEST_CASE("results: implicit background notifier") {
  +TEST_CASE("results: notifier with no callbacks") {
  _impl::RealmCoordinator::assert_no_open_realms();
  InMemoryTestFile config;
  @@ -1917,6 +1926,11 @@ TEST_CASE("results: implicit background notifier") {
  results.last(); // force evaluation and creation of TableView
  SECTION("refresh() does not block due to implicit notifier") {
  + // Create and then immediately remove a callback because
  + // `automatic_change_notifications = false` makes Results not implicitly
  + // create a notifier
  + results.add_notification_callback([](CollectionChangeSet const&, std::exception_ptr) {});
  +
  auto r2 = coordinator->get_realm();
  r2->begin_transaction();
  r2->read_group().get_table("class_object")->add_empty_row();
  @@ -1926,6 +1940,8 @@ TEST_CASE("results: implicit background notifier") {
  }
  SECTION("refresh() does not attempt to deliver stale results") {
  + results.add_notification_callback([](CollectionChangeSet const&, std::exception_ptr) {});
  +
  // Create version 1
  r->begin_transaction();
  table->add_empty_row();
  @@ -1942,6 +1958,29 @@ TEST_CASE("results: implicit background notifier") {
  // they're for version 1 and the realm is at 2)
  r->refresh();
  }
  +
  + SECTION("should not pin the source version even after the Realm has been closed") {
  + auto r2 = coordinator->get_realm();
  + REQUIRE(r != r2);
  + r->close();
  +
  + auto& shared_group = TestHelper::get_shared_group(r2);
  + // There's always at least 2 live versions because the previous version
  + // isn't clean up until the *next* commit
  + REQUIRE(shared_group.get_number_of_versions() == 2);
  +
  + auto table = r2->read_group().get_table("class_object");
  +
  + r2->begin_transaction();
  + table->add_empty_row();
  + r2->commit_transaction();
  + r2->begin_transaction();
  + table->add_empty_row();
  + r2->commit_transaction();
  +
  + // Would now be 3 if the closed Realm is still pinning the version it was at
  + REQUIRE(shared_group.get_number_of_versions() == 2);
  + }
  }
  TEST_CASE("results: error messages") {
  