Skip to content

Commit 3855eff

Browse files
authored
PYTHON-4842 - Convert test.test_create_entities to async (mongodb#1919)
1 parent 1b6c0d3 commit 3855eff

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Copyright 2021-present MongoDB, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from __future__ import annotations
15+
16+
import sys
17+
import unittest
18+
19+
sys.path[0:0] = [""]
20+
21+
from test.asynchronous import AsyncIntegrationTest
22+
from test.asynchronous.unified_format import UnifiedSpecTestMixinV1
23+
24+
_IS_SYNC = False
25+
26+
27+
class TestCreateEntities(AsyncIntegrationTest):
28+
async def test_store_events_as_entities(self):
29+
self.scenario_runner = UnifiedSpecTestMixinV1()
30+
spec = {
31+
"description": "blank",
32+
"schemaVersion": "1.2",
33+
"createEntities": [
34+
{
35+
"client": {
36+
"id": "client0",
37+
"storeEventsAsEntities": [
38+
{
39+
"id": "events1",
40+
"events": [
41+
"PoolCreatedEvent",
42+
],
43+
}
44+
],
45+
}
46+
},
47+
],
48+
"tests": [{"description": "foo", "operations": []}],
49+
}
50+
self.scenario_runner.TEST_SPEC = spec
51+
await self.scenario_runner.asyncSetUp()
52+
await self.scenario_runner.run_scenario(spec["tests"][0])
53+
await self.scenario_runner.entity_map["client0"].close()
54+
final_entity_map = self.scenario_runner.entity_map
55+
self.assertIn("events1", final_entity_map)
56+
self.assertGreater(len(final_entity_map["events1"]), 0)
57+
for event in final_entity_map["events1"]:
58+
self.assertIn("PoolCreatedEvent", event["name"])
59+
60+
async def test_store_all_others_as_entities(self):
61+
self.scenario_runner = UnifiedSpecTestMixinV1()
62+
spec = {
63+
"description": "Find",
64+
"schemaVersion": "1.2",
65+
"createEntities": [
66+
{
67+
"client": {
68+
"id": "client0",
69+
"uriOptions": {"retryReads": True},
70+
}
71+
},
72+
{"database": {"id": "database0", "client": "client0", "databaseName": "dat"}},
73+
{
74+
"collection": {
75+
"id": "collection0",
76+
"database": "database0",
77+
"collectionName": "dat",
78+
}
79+
},
80+
],
81+
"tests": [
82+
{
83+
"description": "test loops",
84+
"operations": [
85+
{
86+
"name": "loop",
87+
"object": "testRunner",
88+
"arguments": {
89+
"storeIterationsAsEntity": "iterations",
90+
"storeSuccessesAsEntity": "successes",
91+
"storeFailuresAsEntity": "failures",
92+
"storeErrorsAsEntity": "errors",
93+
"numIterations": 5,
94+
"operations": [
95+
{
96+
"name": "insertOne",
97+
"object": "collection0",
98+
"arguments": {"document": {"_id": 1, "x": 44}},
99+
},
100+
{
101+
"name": "insertOne",
102+
"object": "collection0",
103+
"arguments": {"document": {"_id": 2, "x": 44}},
104+
},
105+
],
106+
},
107+
}
108+
],
109+
}
110+
],
111+
}
112+
113+
await self.client.dat.dat.delete_many({})
114+
self.scenario_runner.TEST_SPEC = spec
115+
await self.scenario_runner.asyncSetUp()
116+
await self.scenario_runner.run_scenario(spec["tests"][0])
117+
await self.scenario_runner.entity_map["client0"].close()
118+
entity_map = self.scenario_runner.entity_map
119+
self.assertEqual(len(entity_map["errors"]), 4)
120+
for error in entity_map["errors"]:
121+
self.assertEqual(error["type"], "DuplicateKeyError")
122+
self.assertEqual(entity_map["failures"], [])
123+
self.assertEqual(entity_map["successes"], 2)
124+
self.assertEqual(entity_map["iterations"], 5)
125+
126+
127+
if __name__ == "__main__":
128+
unittest.main()

test/test_create_entities.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from test import IntegrationTest
2222
from test.unified_format import UnifiedSpecTestMixinV1
2323

24+
_IS_SYNC = True
25+
2426

2527
class TestCreateEntities(IntegrationTest):
2628
def test_store_events_as_entities(self):

tools/synchro.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def async_only_test(f: str) -> bool:
199199
"test_common.py",
200200
"test_connection_logging.py",
201201
"test_connections_survive_primary_stepdown_spec.py",
202+
"test_create_entities.py",
202203
"test_crud_unified.py",
203204
"test_cursor.py",
204205
"test_database.py",

0 commit comments

Comments
 (0)