Skip to content

Commit

Permalink
Better parallelization safeguards
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPansino committed Jul 27, 2023
1 parent fa5f39a commit ab1f4ff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
10 changes: 3 additions & 7 deletions tests/datastore_firestore/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,9 @@ def client():

@pytest.fixture(scope="function")
def collection(client):
yield client.collection("firestore_collection_" + str(uuid.uuid4()))


@pytest.fixture(scope="function", autouse=True)
def reset_firestore(client):
for coll in client.collections():
client.recursive_delete(coll)
collection_ = client.collection("firestore_collection_" + str(uuid.uuid4()))
yield collection_
client.recursive_delete(collection_)


@pytest.fixture(scope="session")
Expand Down
18 changes: 7 additions & 11 deletions tests/datastore_firestore/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@


@pytest.fixture()
def existing_document(collection, reset_firestore):
# reset_firestore must be run before, not after this fixture
def sample_data(collection):
doc = collection.document("document")
doc.set({"x": 1})
return doc


def _exercise_client(client, collection, existing_document):
def _exercise_client(client, collection, sample_data):
assert len([_ for _ in client.collections()]) >= 1
doc = [_ for _ in client.get_all([existing_document])][0]
doc = [_ for _ in client.get_all([sample_data])][0]
assert doc.to_dict()["x"] == 1


def test_firestore_client(client, collection, existing_document):
def test_firestore_client(client, collection, sample_data):
_test_scoped_metrics = [
("Datastore/operation/Firestore/collections", 1),
("Datastore/operation/Firestore/get_all", 1),
Expand All @@ -56,15 +55,12 @@ def test_firestore_client(client, collection, existing_document):
)
@background_task(name="test_firestore_client")
def _test():
_exercise_client(client, collection, existing_document)
_exercise_client(client, collection, sample_data)

_test()


@background_task()
def test_firestore_client_generators(client, collection, assert_trace_for_generator):
doc = collection.document("test")
doc.set({})

def test_firestore_client_generators(client, collection, sample_data, assert_trace_for_generator):
assert_trace_for_generator(client.collections)
assert_trace_for_generator(client.get_all, [doc])
assert_trace_for_generator(client.get_all, [sample_data])
3 changes: 1 addition & 2 deletions tests/datastore_firestore/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@


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

Expand Down
3 changes: 1 addition & 2 deletions tests/datastore_firestore/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@


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

Expand Down

0 comments on commit ab1f4ff

Please sign in to comment.