-
Notifications
You must be signed in to change notification settings - Fork 208
PHPC-1163: Prohibit session with unacknowledged write concern #814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
--TEST-- | ||
PHPC-1163: Unacknowledged write concern should omit implicit session | ||
--XFAIL-- | ||
Depends on CDRIVER-2615 | ||
--SKIPIF-- | ||
<?php if (PHP_INT_SIZE !== 8) { die("skip Can't represent 64-bit ints on a 32-bit platform"); } ?> | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
<?php NEEDS('STANDALONE'); ?> | ||
<?php CLEANUP(STANDALONE); ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
class Test implements MongoDB\Driver\Monitoring\CommandSubscriber | ||
{ | ||
public function run() | ||
{ | ||
$manager = new MongoDB\Driver\Manager(STANDALONE, ['w' => 0]); | ||
|
||
MongoDB\Driver\Monitoring\addSubscriber($this); | ||
|
||
$bulk = new MongoDB\Driver\BulkWrite; | ||
$bulk->insert(['x' => 1]); | ||
|
||
echo "Testing executeBulkWrite\n"; | ||
$manager->executeBulkWrite(NS, $bulk); | ||
|
||
$command = new MongoDB\Driver\Command([ | ||
'insert' => COLLECTION_NAME, | ||
'documents' => [['x' => 1]], | ||
]); | ||
|
||
/* Note: executeCommand() and executeReadCommand() are not tested | ||
* because they do not inherit the client-level write concern. */ | ||
|
||
echo "\nTesting executeWriteCommand\n"; | ||
$manager->executeWriteCommand(DATABASE_NAME, $command); | ||
|
||
/* We can safely re-use the insert command with executeReadWriteCommand | ||
* because there is no readConcern to inherit. */ | ||
echo "\nTesting executeReadWriteCommand\n"; | ||
$manager->executeReadWriteCommand(DATABASE_NAME, $command); | ||
|
||
MongoDB\Driver\Monitoring\removeSubscriber($this); | ||
} | ||
|
||
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event) | ||
{ | ||
if ($event->getCommandName() === 'insert') { | ||
$command = $event->getCommand(); | ||
$hasSession = isset($command->lsid); | ||
$writeConcern = isset($command->writeConcern) ? $command->writeConcern: null; | ||
|
||
printf("insert command write concern: %s\n", json_encode($writeConcern)); | ||
printf("insert command has session: %s\n", $hasSession ? 'yes' : 'no'); | ||
} | ||
} | ||
|
||
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event) | ||
{ | ||
} | ||
|
||
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event) | ||
{ | ||
} | ||
} | ||
|
||
(new Test)->run(); | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
Testing executeBulkWrite | ||
insert command write concern: {"w":0} | ||
insert command has session: no | ||
|
||
Testing executeWriteCommand | ||
insert command write concern: {"w":0} | ||
insert command has session: no | ||
|
||
Testing executeReadWriteCommand | ||
insert command write concern: {"w":0} | ||
insert command has session: no | ||
===DONE=== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--TEST-- | ||
MongoDB\Driver\Manager::executeBulkWrite() cannot combine session with unacknowledged write concern | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
<?php NEEDS_CRYPTO(); ?> | ||
<?php NEEDS('STANDALONE'); ?> | ||
<?php NEEDS_ATLEAST_MONGODB_VERSION(STANDALONE, "3.6"); ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
echo throws(function() { | ||
$manager = new MongoDB\Driver\Manager(STANDALONE); | ||
|
||
$bulk = new MongoDB\Driver\BulkWrite; | ||
$bulk->insert(['x' => 1]); | ||
|
||
$manager->executeBulkWrite(NS, $bulk, [ | ||
'session' => $manager->startSession(), | ||
'writeConcern' => new MongoDB\Driver\WriteConcern(0), | ||
]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
echo throws(function() { | ||
$manager = new MongoDB\Driver\Manager(STANDALONE, ['w' => 0]); | ||
|
||
$bulk = new MongoDB\Driver\BulkWrite; | ||
$bulk->insert(['x' => 1]); | ||
|
||
$manager->executeBulkWrite(NS, $bulk, [ | ||
'session' => $manager->startSession(), | ||
]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Cannot combine "session" option with an unacknowledged write concern | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Cannot combine "session" option with an unacknowledged write concern | ||
===DONE=== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--TEST-- | ||
MongoDB\Driver\Manager::executeCommand() cannot combine session with unacknowledged write concern | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
<?php NEEDS_CRYPTO(); ?> | ||
<?php NEEDS('STANDALONE'); ?> | ||
<?php NEEDS_ATLEAST_MONGODB_VERSION(STANDALONE, "3.6"); ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
echo throws(function() { | ||
$manager = new MongoDB\Driver\Manager(STANDALONE); | ||
|
||
$command = new MongoDB\Driver\Command([ | ||
'insert' => COLLECTION_NAME, | ||
'documents' => [['x' => 1]], | ||
]); | ||
|
||
$manager->executeCommand(DATABASE_NAME, $command, [ | ||
'session' => $manager->startSession(), | ||
'writeConcern' => new MongoDB\Driver\WriteConcern(0), | ||
]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Cannot combine "session" option with an unacknowledged write concern | ||
===DONE=== |
49 changes: 49 additions & 0 deletions
49
tests/manager/manager-executeReadWriteCommand_error-002.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--TEST-- | ||
MongoDB\Driver\Manager::executeReadWriteCommand() cannot combine session with unacknowledged write concern | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
<?php NEEDS_CRYPTO(); ?> | ||
<?php NEEDS('STANDALONE'); ?> | ||
<?php NEEDS_ATLEAST_MONGODB_VERSION(STANDALONE, "3.6"); ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
/* insert should not normally be used with executeReadWriteCommand(), but we are | ||
* only testing executeReadWriteCommand()'s option validation. */ | ||
echo throws(function() { | ||
$manager = new MongoDB\Driver\Manager(STANDALONE); | ||
|
||
$command = new MongoDB\Driver\Command([ | ||
'insert' => COLLECTION_NAME, | ||
'documents' => [['x' => 1]], | ||
]); | ||
|
||
$manager->executeReadWriteCommand(DATABASE_NAME, $command, [ | ||
'session' => $manager->startSession(), | ||
'writeConcern' => new MongoDB\Driver\WriteConcern(0), | ||
]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
echo throws(function() { | ||
$manager = new MongoDB\Driver\Manager(STANDALONE, ['w' => 0]); | ||
|
||
$command = new MongoDB\Driver\Command([ | ||
'insert' => COLLECTION_NAME, | ||
'documents' => [['x' => 1]], | ||
]); | ||
|
||
$manager->executeReadWriteCommand(DATABASE_NAME, $command, [ | ||
'session' => $manager->startSession(), | ||
]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Cannot combine "session" option with an unacknowledged write concern | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Cannot combine "session" option with an unacknowledged write concern | ||
===DONE=== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--TEST-- | ||
MongoDB\Driver\Manager::executeWriteCommand() cannot combine session with unacknowledged write concern | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?> | ||
<?php NEEDS_CRYPTO(); ?> | ||
<?php NEEDS('STANDALONE'); ?> | ||
<?php NEEDS_ATLEAST_MONGODB_VERSION(STANDALONE, "3.6"); ?> | ||
--FILE-- | ||
<?php | ||
require_once __DIR__ . "/../utils/basic.inc"; | ||
|
||
echo throws(function() { | ||
$manager = new MongoDB\Driver\Manager(STANDALONE); | ||
|
||
$command = new MongoDB\Driver\Command([ | ||
'insert' => COLLECTION_NAME, | ||
'documents' => [['x' => 1]], | ||
]); | ||
|
||
$manager->executeWriteCommand(DATABASE_NAME, $command, [ | ||
'session' => $manager->startSession(), | ||
'writeConcern' => new MongoDB\Driver\WriteConcern(0), | ||
]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
echo throws(function() { | ||
$manager = new MongoDB\Driver\Manager(STANDALONE, ['w' => 0]); | ||
|
||
$command = new MongoDB\Driver\Command([ | ||
'insert' => COLLECTION_NAME, | ||
'documents' => [['x' => 1]], | ||
]); | ||
|
||
$manager->executeWriteCommand(DATABASE_NAME, $command, [ | ||
'session' => $manager->startSession(), | ||
]); | ||
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; | ||
|
||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECT-- | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Cannot combine "session" option with an unacknowledged write concern | ||
OK: Got MongoDB\Driver\Exception\InvalidArgumentException | ||
Cannot combine "session" option with an unacknowledged write concern | ||
===DONE=== |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests pass locally after applying the patch from CDRIVER-2615, but feel free to verify on your own. In any event, that fix won't show up until libmongoc 1.10.