summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-07-05 11:13:04 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-07-05 12:11:22 -0400
commit390bb2badbc53345945b83fdcb2402f3f9cb4964 (patch)
tree09a01bbc4d14524ed5d8985fe7ade67d86c319d6 /src
parentb5466d26199389c192814bf9f7e5d618ca6ec588 (diff)
downloadmongo-390bb2badbc53345945b83fdcb2402f3f9cb4964.tar.gz
SERVER-28248 Fix move construction of NamespaceMetadataChangeNotifications::ScopedNotification
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/s/namespace_metadata_change_notifications.h8
-rw-r--r--src/mongo/db/s/namespace_metadata_change_notifications_test.cpp21
2 files changed, 28 insertions, 1 deletions
diff --git a/src/mongo/db/s/namespace_metadata_change_notifications.h b/src/mongo/db/s/namespace_metadata_change_notifications.h
index 832e18a9976..8fd98fe6640 100644
--- a/src/mongo/db/s/namespace_metadata_change_notifications.h
+++ b/src/mongo/db/s/namespace_metadata_change_notifications.h
@@ -59,13 +59,19 @@ public:
* out of scope, if it has not been signalled yet.
*/
class ScopedNotification {
+ MONGO_DISALLOW_COPYING(ScopedNotification);
+
public:
ScopedNotification(NamespaceMetadataChangeNotifications* notifications,
std::shared_ptr<NotificationToken> token)
: _notifications(notifications), _token(std::move(token)) {}
+ ScopedNotification(ScopedNotification&&) = default;
+
~ScopedNotification() {
- _notifications->_unregisterNotificationToken(std::move(_token));
+ if (_token) {
+ _notifications->_unregisterNotificationToken(std::move(_token));
+ }
}
void get(OperationContext* opCtx) {
diff --git a/src/mongo/db/s/namespace_metadata_change_notifications_test.cpp b/src/mongo/db/s/namespace_metadata_change_notifications_test.cpp
index c43a8c9774a..66b4e28c33b 100644
--- a/src/mongo/db/s/namespace_metadata_change_notifications_test.cpp
+++ b/src/mongo/db/s/namespace_metadata_change_notifications_test.cpp
@@ -95,5 +95,26 @@ TEST_F(NamespaceMetadataChangeNotificationsTest, GiveUpWaitingForNotify) {
notifications.notifyChange(kNss);
}
+TEST_F(NamespaceMetadataChangeNotificationsTest, MoveConstructionWaitForNotify) {
+ NamespaceMetadataChangeNotifications notifications;
+
+ auto scopedNotif = notifications.createNotification(kNss);
+ auto movedScopedNotif = std::move(scopedNotif);
+
+ {
+ auto opCtx = client()->makeOperationContext();
+ opCtx->setDeadlineAfterNowBy(Milliseconds{0});
+ ASSERT_THROWS_CODE(
+ movedScopedNotif.get(opCtx.get()), UserException, ErrorCodes::ExceededTimeLimit);
+ }
+
+ notifications.notifyChange(kNss);
+
+ {
+ auto opCtx = client()->makeOperationContext();
+ movedScopedNotif.get(opCtx.get());
+ }
+}
+
} // namespace
} // namespace mongo