-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PBM-1223 check logical backup when distributed txn was started before…
… backup
- Loading branch information
1 parent
5bd9250
commit 5942c08
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,82 @@ | ||
import pytest | ||
import pymongo | ||
import bson | ||
import testinfra | ||
import time | ||
import os | ||
import docker | ||
import threading | ||
import concurrent.futures | ||
|
||
from datetime import datetime | ||
from cluster import Cluster | ||
|
||
documents=[{"a": 1}, {"b": 2}, {"c": 3}, {"d": 4}] | ||
|
||
@pytest.fixture(scope="package") | ||
def docker_client(): | ||
return docker.from_env() | ||
|
||
@pytest.fixture(scope="package") | ||
def config(): | ||
return { "mongos": "mongos", | ||
"configserver": | ||
{"_id": "rscfg", "members": [{"host":"rscfg01"},{"host": "rscfg02"},{"host": "rscfg03" }]}, | ||
"shards":[ | ||
{"_id": "rs1", "members": [{"host":"rs101"},{"host": "rs102"},{"host": "rs103" }]}, | ||
{"_id": "rs2", "members": [{"host":"rs201"},{"host": "rs202"},{"host": "rs203" }]} | ||
]} | ||
|
||
@pytest.fixture(scope="package") | ||
def cluster(config): | ||
return Cluster(config) | ||
|
||
@pytest.fixture(scope="function") | ||
def start_cluster(cluster,request): | ||
try: | ||
cluster.destroy() | ||
cluster.create() | ||
cluster.setup_pbm() | ||
os.chmod("/backups",0o777) | ||
os.system("rm -rf /backups/*") | ||
result = cluster.exec_pbm_cli("config --set storage.type=filesystem --set storage.filesystem.path=/backups --set backup.compression=none --out json") | ||
assert result.rc == 0 | ||
Cluster.log("Setup PBM with fs storage:\n" + result.stdout) | ||
client=pymongo.MongoClient(cluster.connection) | ||
client.admin.command("enableSharding", "test") | ||
client.admin.command("shardCollection", "test.test", key={"_id": "hashed"}) | ||
yield True | ||
|
||
finally: | ||
if request.config.getoption("--verbose"): | ||
cluster.get_logs() | ||
cluster.destroy(cleanup_backups=True) | ||
|
||
@pytest.mark.testcase(test_case_key="T249", test_step_key=1) | ||
@pytest.mark.timeout(300,func_only=True) | ||
def test_logical(start_cluster,cluster): | ||
cluster.check_pbm_status() | ||
client = pymongo.MongoClient(cluster.connection) | ||
db = client.test | ||
collection = db.test | ||
with client.start_session() as session: | ||
with session.start_transaction(): | ||
Cluster.log("Transaction started\n") | ||
collection.insert_one({"e": 5}, session=session) | ||
collection.insert_one({"f": 6}, session=session) | ||
collection.insert_one({"g": 7}, session=session) | ||
collection.insert_one({"h": 8}, session=session) | ||
collection.insert_one({"i": 9}, session=session) | ||
background_backup=concurrent.futures.ThreadPoolExecutor().submit(cluster.make_backup, 'logical') | ||
time.sleep(1) | ||
collection.insert_one({"j": 10}, session=session) | ||
collection.insert_one({"k": 11}, session=session) | ||
collection.insert_one({"l": 12}, session=session) | ||
session.commit_transaction() | ||
Cluster.log("Transaction commited\n") | ||
backup=background_backup.result() | ||
assert pymongo.MongoClient(cluster.connection)["test"]["test"].count_documents({}) == 8 | ||
cluster.make_restore(backup,check_pbm_status=True) | ||
Check failure on line 79 in pbm-functional/pytest/test_PBM-1223.py GitHub Actions / JUnit Test Reporttest_PBM-1223.test_logical
Raw output
|
||
assert pymongo.MongoClient(cluster.connection)["test"]["test"].count_documents({}) == 8 | ||
assert pymongo.MongoClient(cluster.connection)["test"].command("collstats", "test").get("sharded", False) | ||
Cluster.log("Finished successfully\n") |
This file contains 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