Skip to content

PHPLIB-694: Spec tests for snapshot sessions #851

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 2 commits into from
Aug 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,14 @@ axes:
# display_name: "1.10.0"
# variables:
# EXTENSION_VERSION: "1.10.0"
- id: "latest-stable"
display_name: "Latest Stable (1.10.x)"
variables:
EXTENSION_VERSION: "stable"
- id: "upcoming-stable"
display_name: "1.10-dev"
variables:
EXTENSION_BRANCH: "v1.10"
# - id: "latest-stable"
# display_name: "Latest Stable (1.10.x)"
# variables:
# EXTENSION_VERSION: "stable"
# - id: "upcoming-stable"
# display_name: "1.10-dev"
# variables:
# EXTENSION_BRANCH: "v1.10"
- id: "latest-dev"
display_name: "1.11-dev (master)"
variables:
Expand Down Expand Up @@ -574,7 +574,7 @@ buildvariants:
# Tests all PHP versions on all operating systems.
# Only tests against latest MongoDB and ext-mongodb versions
- matrix_name: "test-php-versions"
matrix_spec: {"os-php7": "*", "php-versions": "*", "edge-versions": "latest-stable", "driver-versions": "latest-stable" }
matrix_spec: {"os-php7": "*", "php-versions": "*", "edge-versions": "latest-stable", "driver-versions": "latest-dev" }
exclude_spec:
# rhel71-power8 fails due to not reaching pecl
- { "os-php7": "rhel71-power8", "php-versions": "*", edge-versions: "*", "driver-versions": "*" }
Expand All @@ -600,7 +600,7 @@ buildvariants:
# Only tests on Ubuntu 18.04, with latest stable PHP and driver versions
# Tests against various topologies
- matrix_name: "test-mongodb-versions"
matrix_spec: {"os-php7": "rhel70-test", "php-edge-versions": "latest-stable", "versions": "*", "driver-versions": "latest-stable" }
matrix_spec: {"os-php7": "rhel70-test", "php-edge-versions": "latest-stable", "versions": "*", "driver-versions": "latest-dev" }
display_name: "MongoDB ${versions}, PHP ${php-edge-versions}, ${os-php7}, ext-mongodb ${driver-versions}"
tasks:
- name: "test-standalone"
Expand All @@ -611,22 +611,22 @@ buildvariants:
# Enables --prefer-lowest for composer to test oldest dependencies against all server versions
# TODO: driver-versions can be changed back to lowest-supported when that version is enabled in the axis
- matrix_name: "test-dependencies"
matrix_spec: { "dependencies": "lowest", "os-php7": "rhel70-test", "php-edge-versions": "oldest-supported", "versions": "*", "driver-versions": "latest-stable" }
matrix_spec: { "dependencies": "lowest", "os-php7": "rhel70-test", "php-edge-versions": "oldest-supported", "versions": "*", "driver-versions": "latest-dev" }
display_name: "Dependencies: ${dependencies}, MongoDB ${versions}, PHP ${php-edge-versions}, ${os-php7}, ext-mongodb ${driver-versions}"
tasks:
- name: "test-standalone"
- name: "test-replica_set"
- name: "test-sharded_cluster"

- matrix_name: "atlas-data-lake-test"
matrix_spec: { "php-edge-versions": "latest-stable", "driver-versions": "latest-stable" }
matrix_spec: { "php-edge-versions": "latest-stable", "driver-versions": "latest-dev" }
display_name: "Atlas Data Lake test"
run_on: rhel70
tasks:
- name: "test-atlas-data-lake"

- matrix_name: "test-versioned-api"
matrix_spec: { "php-edge-versions": "latest-stable", "versions": ["5.0", "latest"], "driver-versions": "latest-stable" }
matrix_spec: { "php-edge-versions": "latest-stable", "versions": ["5.0", "latest"], "driver-versions": "latest-dev" }
display_name: "Versioned API - ${versions}"
run_on: rhel70
tasks:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"php": "^7.1 || ^8.0",
"ext-hash": "*",
"ext-json": "*",
"ext-mongodb": "^1.10.0",
"ext-mongodb": "^1.11.0",
"jean85/pretty-package-versions": "^1.2 || ^2.0.1",
"symfony/polyfill-php80": "^1.19"
},
Expand Down
6 changes: 5 additions & 1 deletion tests/UnifiedSpecTests/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ private static function prepareBucketOptions(array $options): array

private static function prepareSessionOptions(array $options): array
{
Util::assertHasOnlyKeys($options, ['causalConsistency', 'defaultTransactionOptions']);
Util::assertHasOnlyKeys($options, ['causalConsistency', 'defaultTransactionOptions', 'snapshot']);

if (array_key_exists('causalConsistency', $options)) {
assertIsBool($options['causalConsistency']);
Expand All @@ -463,6 +463,10 @@ private static function prepareSessionOptions(array $options): array
$options['defaultTransactionOptions'] = self::prepareDefaultTransactionOptions((array) $options['defaultTransactionOptions']);
}

if (array_key_exists('snapshot', $options)) {
assertIsBool($options['snapshot']);
}

return $options;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/UnifiedSpecTests/UnifiedSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ public function provideGridFSTests()
return $this->provideTests(__DIR__ . '/gridfs/*.json');
}

/**
* @dataProvider provideSessionsTests
*/
public function testSessions(UnifiedTestCase $test): void
{
self::$runner->run($test);
}

public function provideSessionsTests()
{
return $this->provideTests(__DIR__ . '/sessions/*.json');
}

/**
* @dataProvider provideTransactionsTests
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"description": "snapshot-sessions-not-supported-client-error",
"schemaVersion": "1.0",
"runOnRequirements": [
{
"minServerVersion": "3.6",
"maxServerVersion": "4.4.99"
}
],
"createEntities": [
{
"client": {
"id": "client0",
"observeEvents": [
"commandStartedEvent",
"commandFailedEvent"
]
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "database0"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "collection0"
}
},
{
"session": {
"id": "session0",
"client": "client0",
"sessionOptions": {
"snapshot": true
}
}
}
],
"initialData": [
{
"collectionName": "collection0",
"databaseName": "database0",
"documents": [
{
"_id": 1,
"x": 11
}
]
}
],
"tests": [
{
"description": "Client error on find with snapshot",
"operations": [
{
"name": "find",
"object": "collection0",
"arguments": {
"session": "session0",
"filter": {}
},
"expectError": {
"isClientError": true,
"errorContains": "Snapshot reads require MongoDB 5.0 or later"
}
}
],
"expectEvents": [
{
"client": "client0",
"events": []
}
]
},
{
"description": "Client error on aggregate with snapshot",
"operations": [
{
"name": "aggregate",
"object": "collection0",
"arguments": {
"session": "session0",
"pipeline": []
},
"expectError": {
"isClientError": true,
"errorContains": "Snapshot reads require MongoDB 5.0 or later"
}
}
],
"expectEvents": [
{
"client": "client0",
"events": []
}
]
},
{
"description": "Client error on distinct with snapshot",
"operations": [
{
"name": "distinct",
"object": "collection0",
"arguments": {
"fieldName": "x",
"filter": {},
"session": "session0"
},
"expectError": {
"isClientError": true,
"errorContains": "Snapshot reads require MongoDB 5.0 or later"
}
}
],
"expectEvents": [
{
"client": "client0",
"events": []
}
]
}
]
}
Loading