Skip to content

Commit ab1f4ff

Browse files
committed
Better parallelization safeguards
1 parent fa5f39a commit ab1f4ff

File tree

4 files changed

+12
-22
lines changed

4 files changed

+12
-22
lines changed

tests/datastore_firestore/conftest.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,9 @@ def client():
5757

5858
@pytest.fixture(scope="function")
5959
def collection(client):
60-
yield client.collection("firestore_collection_" + str(uuid.uuid4()))
61-
62-
63-
@pytest.fixture(scope="function", autouse=True)
64-
def reset_firestore(client):
65-
for coll in client.collections():
66-
client.recursive_delete(coll)
60+
collection_ = client.collection("firestore_collection_" + str(uuid.uuid4()))
61+
yield collection_
62+
client.recursive_delete(collection_)
6763

6864

6965
@pytest.fixture(scope="session")

tests/datastore_firestore/test_client.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,19 @@
2323

2424

2525
@pytest.fixture()
26-
def existing_document(collection, reset_firestore):
27-
# reset_firestore must be run before, not after this fixture
26+
def sample_data(collection):
2827
doc = collection.document("document")
2928
doc.set({"x": 1})
3029
return doc
3130

3231

33-
def _exercise_client(client, collection, existing_document):
32+
def _exercise_client(client, collection, sample_data):
3433
assert len([_ for _ in client.collections()]) >= 1
35-
doc = [_ for _ in client.get_all([existing_document])][0]
34+
doc = [_ for _ in client.get_all([sample_data])][0]
3635
assert doc.to_dict()["x"] == 1
3736

3837

39-
def test_firestore_client(client, collection, existing_document):
38+
def test_firestore_client(client, collection, sample_data):
4039
_test_scoped_metrics = [
4140
("Datastore/operation/Firestore/collections", 1),
4241
("Datastore/operation/Firestore/get_all", 1),
@@ -56,15 +55,12 @@ def test_firestore_client(client, collection, existing_document):
5655
)
5756
@background_task(name="test_firestore_client")
5857
def _test():
59-
_exercise_client(client, collection, existing_document)
58+
_exercise_client(client, collection, sample_data)
6059

6160
_test()
6261

6362

6463
@background_task()
65-
def test_firestore_client_generators(client, collection, assert_trace_for_generator):
66-
doc = collection.document("test")
67-
doc.set({})
68-
64+
def test_firestore_client_generators(client, collection, sample_data, assert_trace_for_generator):
6965
assert_trace_for_generator(client.collections)
70-
assert_trace_for_generator(client.get_all, [doc])
66+
assert_trace_for_generator(client.get_all, [sample_data])

tests/datastore_firestore/test_query.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424

2525

2626
@pytest.fixture(autouse=True)
27-
def sample_data(collection, reset_firestore):
28-
# reset_firestore must be run before, not after this fixture
27+
def sample_data(collection):
2928
for x in range(1, 6):
3029
collection.add({"x": x})
3130

tests/datastore_firestore/test_transaction.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323

2424

2525
@pytest.fixture(autouse=True)
26-
def sample_data(collection, reset_firestore):
27-
# reset_firestore must be run before, not after this fixture
26+
def sample_data(collection):
2827
for x in range(1, 4):
2928
collection.add({"x": x}, "doc%d" % x)
3029

0 commit comments

Comments
 (0)