Skip to content

Commit d4be63c

Browse files
authored
PHPC-2036: Sync causal consistency tests (#1298)
Synced with mongodb/specifications@568093c Adds missing prose test 7 and removes prose test 10. This also adds prose test references to all files.
1 parent 0960a20 commit d4be63c

12 files changed

+69
-40
lines changed

tests/causal-consistency/causal-consistency-001.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
22
Causal consistency: new session has no operation time
3+
--DESCRIPTION--
4+
Causal consistency spec prose test #1
5+
https://github.com/mongodb/specifications/blob/master/source/causal-consistency/causal-consistency.rst#test-plan
36
--SKIPIF--
47
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
58
<?php skip_if_not_libmongoc_crypto(); ?>

tests/causal-consistency/causal-consistency-002.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
22
Causal consistency: first read in session does not include afterClusterTime
3+
--DESCRIPTION--
4+
Causal consistency spec prose test #2
5+
https://github.com/mongodb/specifications/blob/master/source/causal-consistency/causal-consistency.rst#test-plan
36
--SKIPIF--
47
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
58
<?php skip_if_not_libmongoc_crypto(); ?>

tests/causal-consistency/causal-consistency-003.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
22
Causal consistency: first read or write in session updates operationTime
3+
--DESCRIPTION--
4+
Causal consistency spec prose test #3
5+
https://github.com/mongodb/specifications/blob/master/source/causal-consistency/causal-consistency.rst#test-plan
36
--SKIPIF--
47
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
58
<?php skip_if_not_libmongoc_crypto(); ?>

tests/causal-consistency/causal-consistency-004.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
22
Causal consistency: first read or write in session updates operationTime (even on error)
3+
--DESCRIPTION--
4+
Causal consistency spec prose test #3
5+
https://github.com/mongodb/specifications/blob/master/source/causal-consistency/causal-consistency.rst#test-plan
36
--SKIPIF--
47
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
58
<?php skip_if_not_libmongoc_crypto(); ?>

tests/causal-consistency/causal-consistency-005.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
22
Causal consistency: second read's afterClusterTime uses last reply's operationTime
3+
--DESCRIPTION--
4+
Causal consistency spec prose test #4 and #5
5+
https://github.com/mongodb/specifications/blob/master/source/causal-consistency/causal-consistency.rst#test-plan
36
--SKIPIF--
47
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
58
<?php skip_if_not_libmongoc_crypto(); ?>

tests/causal-consistency/causal-consistency-006.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
22
Causal consistency: second read's afterClusterTime uses last reply's operationTime (even on error)
3+
--DESCRIPTION--
4+
Causal consistency spec prose test #4 and #5
5+
https://github.com/mongodb/specifications/blob/master/source/causal-consistency/causal-consistency.rst#test-plan
36
--SKIPIF--
47
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
58
<?php skip_if_not_libmongoc_crypto(); ?>

tests/causal-consistency/causal-consistency-007.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
22
Causal consistency: reads in non-causally consistent session never include afterClusterTime
3+
--DESCRIPTION--
4+
Causal consistency spec prose test #6
5+
https://github.com/mongodb/specifications/blob/master/source/causal-consistency/causal-consistency.rst#test-plan
36
--SKIPIF--
47
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
58
<?php skip_if_not_libmongoc_crypto(); ?>
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
--TEST--
2-
Causal consistency: default read concern includes afterClusterTime but not level
2+
Causal consistency: reads in causally consistent session never include afterClusterTime for unsupported deployment
3+
--DESCRIPTION--
4+
Causal consistency spec prose test #7
5+
https://github.com/mongodb/specifications/blob/master/source/causal-consistency/causal-consistency.rst#test-plan
36
--SKIPIF--
47
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
58
<?php skip_if_not_libmongoc_crypto(); ?>
6-
<?php skip_if_not_replica_set_or_sharded_cluster_with_replica_set(); ?>
7-
<?php skip_if_server_version('<', '3.6'); ?>
9+
<?php skip_if_not_standalone(); ?>
810
--FILE--
911
<?php
1012
require_once __DIR__ . "/../utils/basic.inc";
@@ -13,7 +15,7 @@ require_once __DIR__ . "/../utils/observer.php";
1315
(new CommandObserver)->observe(
1416
function() {
1517
$manager = create_test_manager();
16-
$session = $manager->startSession();
18+
$session = $manager->startSession(['causalConsistency' => true]);
1719

1820
$query = new MongoDB\Driver\Query([]);
1921
$manager->executeQuery(NS, $query, ['session' => $session]);
@@ -22,19 +24,14 @@ require_once __DIR__ . "/../utils/observer.php";
2224
function(stdClass $command)
2325
{
2426
$hasAfterClusterTime = isset($command->readConcern->afterClusterTime);
25-
printf("Read concern includes afterClusterTime: %s\n", ($hasAfterClusterTime ? 'yes' : 'no'));
26-
27-
$hasLevel = isset($command->readConcern->level);
28-
printf("Read concern includes level: %s\n", ($hasLevel ? 'yes' : 'no'));
27+
printf("Read includes afterClusterTime: %s\n", ($hasAfterClusterTime ? 'yes' : 'no'));
2928
}
3029
);
3130

3231
?>
3332
===DONE===
3433
<?php exit(0); ?>
3534
--EXPECT--
36-
Read concern includes afterClusterTime: no
37-
Read concern includes level: no
38-
Read concern includes afterClusterTime: yes
39-
Read concern includes level: no
35+
Read includes afterClusterTime: no
36+
Read includes afterClusterTime: no
4037
===DONE===

tests/causal-consistency/causal-consistency-009.phpt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
2-
Causal consistency: custom read concern merges afterClusterTime and level
2+
Causal consistency: default read concern includes afterClusterTime but not level
3+
--DESCRIPTION--
4+
Causal consistency spec prose test #8
5+
https://github.com/mongodb/specifications/blob/master/source/causal-consistency/causal-consistency.rst#test-plan
36
--SKIPIF--
47
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
58
<?php skip_if_not_libmongoc_crypto(); ?>
@@ -15,8 +18,7 @@ require_once __DIR__ . "/../utils/observer.php";
1518
$manager = create_test_manager();
1619
$session = $manager->startSession();
1720

18-
$readConcern = new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY);
19-
$query = new MongoDB\Driver\Query([], ['readConcern' => $readConcern]);
21+
$query = new MongoDB\Driver\Query([]);
2022
$manager->executeQuery(NS, $query, ['session' => $session]);
2123
$manager->executeQuery(NS, $query, ['session' => $session]);
2224
},
@@ -35,7 +37,7 @@ require_once __DIR__ . "/../utils/observer.php";
3537
<?php exit(0); ?>
3638
--EXPECT--
3739
Read concern includes afterClusterTime: no
38-
Read concern includes level: yes
40+
Read concern includes level: no
3941
Read concern includes afterClusterTime: yes
40-
Read concern includes level: yes
42+
Read concern includes level: no
4143
===DONE===
Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
--TEST--
2-
Causal consistency: unacknowledged write does not update operationTime
2+
Causal consistency: custom read concern merges afterClusterTime and level
3+
--DESCRIPTION--
4+
Causal consistency spec prose test #9
5+
https://github.com/mongodb/specifications/blob/master/source/causal-consistency/causal-consistency.rst#test-plan
36
--SKIPIF--
47
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
58
<?php skip_if_not_libmongoc_crypto(); ?>
69
<?php skip_if_not_replica_set_or_sharded_cluster_with_replica_set(); ?>
710
<?php skip_if_server_version('<', '3.6'); ?>
8-
<?php skip_if_not_clean(); ?>
911
--FILE--
1012
<?php
1113
require_once __DIR__ . "/../utils/basic.inc";
14+
require_once __DIR__ . "/../utils/observer.php";
1215

13-
$manager = create_test_manager();
14-
$session = $manager->startSession();
16+
(new CommandObserver)->observe(
17+
function() {
18+
$manager = create_test_manager();
19+
$session = $manager->startSession();
1520

16-
echo "Initial operation time:\n";
17-
var_dump($session->getOperationTime());
21+
$readConcern = new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY);
22+
$query = new MongoDB\Driver\Query([], ['readConcern' => $readConcern]);
23+
$manager->executeQuery(NS, $query, ['session' => $session]);
24+
$manager->executeQuery(NS, $query, ['session' => $session]);
25+
},
26+
function(stdClass $command)
27+
{
28+
$hasAfterClusterTime = isset($command->readConcern->afterClusterTime);
29+
printf("Read concern includes afterClusterTime: %s\n", ($hasAfterClusterTime ? 'yes' : 'no'));
1830

19-
$bulk = new MongoDB\Driver\BulkWrite;
20-
$bulk->insert(['x' => 1]);
21-
$writeConcern = new MongoDB\Driver\WriteConcern(0);
22-
23-
/* Ignore the InvalidArgumentException for trying to combine an unacknowledged
24-
* write concern with an explicit session. */
25-
try {
26-
$manager->executeBulkWrite(NS, $bulk, ['session' => $session, 'writeConcern' => $writeConcern]);
27-
} catch (MongoDB\Driver\Exception\InvalidArgumentException $e) {}
28-
29-
echo "\nOperation time after unacknowledged write:\n";
30-
var_dump($session->getOperationTime());
31+
$hasLevel = isset($command->readConcern->level);
32+
printf("Read concern includes level: %s\n", ($hasLevel ? 'yes' : 'no'));
33+
}
34+
);
3135

3236
?>
3337
===DONE===
3438
<?php exit(0); ?>
3539
--EXPECT--
36-
Initial operation time:
37-
NULL
38-
39-
Operation time after unacknowledged write:
40-
NULL
40+
Read concern includes afterClusterTime: no
41+
Read concern includes level: yes
42+
Read concern includes afterClusterTime: yes
43+
Read concern includes level: yes
4144
===DONE===

0 commit comments

Comments
 (0)