Skip to content

Commit 2d9cc0f

Browse files
committed
Merge branch 'main' into feature/enable-tvos-packaging
2 parents 44eed81 + bff3d7a commit 2d9cc0f

File tree

21 files changed

+153
-110
lines changed

21 files changed

+153
-110
lines changed

.github/workflows/integration_tests.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,20 @@ jobs:
175175
else
176176
# If running in a PR, diff against the PR's base.
177177
# "git merge-base main branch_name" will give the common ancestor of both branches.
178-
MERGE_BASE=$(git merge-base origin/${{github.event.pull_request.head.ref}} origin/${{github.event.pull_request.base.ref}})
179-
echo "::warning ::Auto-diff origin/${{github.event.pull_request.head.ref}}..${MERGE_BASE}"
180-
git diff --name-only origin/${{github.event.pull_request.head.ref}}..${MERGE_BASE}
181-
echo "AUTO_DIFF_PARAM=--auto_diff origin/${{github.event.pull_request.head.ref}}..${MERGE_BASE}" >> $GITHUB_ENV
178+
MERGE_BASE=$(git merge-base origin/${{github.event.pull_request.head.ref}} origin/${{github.event.pull_request.base.ref}} || true)
179+
# If origin/<branch> is no longer valid, then just run all tests.
180+
if [[ -n "${MERGE_BASE}" ]]; then
181+
echo "::warning ::Auto-diff origin/${{github.event.pull_request.head.ref}}..${MERGE_BASE}"
182+
git diff --name-only origin/${{github.event.pull_request.head.ref}}..${MERGE_BASE}
183+
echo "AUTO_DIFF_PARAM=--auto_diff origin/${{github.event.pull_request.head.ref}}..${MERGE_BASE}" >> $GITHUB_ENV
184+
fi
182185
fi
183186
- id: export-result
184187
# e.g. 'ubuntu-latest,macos-latest' -> '["ubuntu-latest","macos-latest"]'
185188
run: |
186-
echo "::set-output name=apis::$( python scripts/gha/print_matrix_configuration.py -c -w integration_tests -k apis -o "${{github.event.inputs.apis}}" ${AUTO_DIFF_PARAM})"
187-
echo "::set-output name=matrix_platform::$( python scripts/gha/print_matrix_configuration.py -w integration_tests ${EXPANDED_MATRIX_PARAM} -k platform -o "${{github.event.inputs.platforms}}" ${AUTO_DIFF_PARAM})"
189+
apis=$( python scripts/gha/print_matrix_configuration.py -c -w integration_tests -k apis -o "${{github.event.inputs.apis}}" ${AUTO_DIFF_PARAM})
190+
echo "::set-output name=apis::${apis}"
191+
echo "::set-output name=matrix_platform::$( python scripts/gha/print_matrix_configuration.py -w integration_tests ${EXPANDED_MATRIX_PARAM} -k platform -o "${{github.event.inputs.platforms}}" --apis ${apis} ${AUTO_DIFF_PARAM})"
188192
echo "::set-output name=matrix_os::$( python scripts/gha/print_matrix_configuration.py -w integration_tests ${EXPANDED_MATRIX_PARAM} -k os -o "${{github.event.inputs.operating_systems}}" ${AUTO_DIFF_PARAM})"
189193
# If building against a packaged SDK, only use boringssl.
190194
if [[ -n "${{ github.event.inputs.test_packaged_sdk }}" ]]; then
@@ -808,6 +812,7 @@ jobs:
808812
run: |
809813
echo "::set-output name=device_type::$( python scripts/gha/print_matrix_configuration.py -d -k ${{ matrix.android_device }} )"
810814
- name: Run Android integration tests on Emulator locally
815+
timeout-minutes: 60
811816
if: steps.get-device-type.outputs.device_type == 'virtual'
812817
run: |
813818
python scripts/gha/test_simulator.py --testapp_dir testapps \
@@ -892,6 +897,7 @@ jobs:
892897
run: |
893898
echo "::set-output name=device_type::$( python scripts/gha/print_matrix_configuration.py -d -k ${{ matrix.ios_device }} )"
894899
- name: Run iOS integration tests on Simulator locally
900+
timeout-minutes: 60
895901
if: steps.get-device-type.outputs.device_type == 'virtual'
896902
run: |
897903
python scripts/gha/test_simulator.py --testapp_dir testapps \
@@ -973,6 +979,7 @@ jobs:
973979
- name: Install python deps
974980
run: pip install -r scripts/gha/requirements.txt
975981
- name: Run tvOS integration tests on Simulator locally
982+
timeout-minutes: 60
976983
run: |
977984
python scripts/gha/test_simulator.py --testapp_dir testapps \
978985
--tvos_device "${{ matrix.tvos_device }}" \

firestore/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,8 @@ add_custom_target(
342342
COMMENT "Copying internal Firestore headers"
343343
)
344344

345+
# This is needed due to Firestore's dependence on some firebase::app APIs that
346+
# are guarded by this flag, such as GetUserAgent and function_registry.
345347
set(FIREBASE_FIRESTORE_CPP_DEFINES -DINTERNAL_EXPERIMENTAL=1)
346348

347349
if (WIN32 AND NOT ANDROID AND NOT IOS)

firestore/integration_test_internal/src/bundle_test.cc

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ std::string CreateTestBundle(Firestore* db) {
6565
return CreateBundle(db->app()->options().project_id());
6666
}
6767

68+
void SetPromiseValueWhenUpdateIsFinal(
69+
LoadBundleTaskProgress progress,
70+
std::promise<void>& final_update_received) {
71+
if (progress.state() == LoadBundleTaskProgress::State::kError ||
72+
progress.state() == LoadBundleTaskProgress::State::kSuccess) {
73+
final_update_received.set_value();
74+
}
75+
}
76+
6877
class BundleTest : public FirestoreIntegrationTest {
6978
protected:
7079
void SetUp() override {
@@ -133,15 +142,19 @@ TEST_F(BundleTest, CanLoadBundlesWithProgressUpdates) {
133142
auto bundle = CreateTestBundle(db);
134143

135144
std::vector<LoadBundleTaskProgress> progresses;
145+
std::promise<void> final_update;
136146
Future<LoadBundleTaskProgress> result = db->LoadBundle(
137-
bundle, [&progresses](const LoadBundleTaskProgress& progress) {
147+
bundle,
148+
[&progresses, &final_update](const LoadBundleTaskProgress& progress) {
138149
progresses.push_back(progress);
150+
SetPromiseValueWhenUpdateIsFinal(progress, final_update);
139151
});
140152

141153
auto final_progress = AwaitResult(result);
142154

143155
// 4 progresses will be reported: initial, document 1, document 2, final
144156
// success.
157+
final_update.get_future().wait();
145158
ASSERT_EQ(progresses.size(), 4);
146159
EXPECT_THAT(progresses[0], InProgressWithLoadedDocuments(0));
147160
EXPECT_THAT(progresses[1], InProgressWithLoadedDocuments(1));
@@ -195,12 +208,16 @@ TEST_F(BundleTest, LoadBundlesForASecondTimeSkips) {
195208
VerifySuccessProgress(first_load);
196209

197210
std::vector<LoadBundleTaskProgress> progresses;
211+
std::promise<void> final_update;
198212
LoadBundleTaskProgress second_load = AwaitResult(db->LoadBundle(
199-
bundle, [&progresses](const LoadBundleTaskProgress& progress) {
213+
bundle,
214+
[&progresses, &final_update](const LoadBundleTaskProgress& progress) {
200215
progresses.push_back(progress);
216+
SetPromiseValueWhenUpdateIsFinal(progress, final_update);
201217
}));
202218

203219
// There will be 4 progress updates if it does not skip loading.
220+
final_update.get_future().wait();
204221
ASSERT_EQ(progresses.size(), 1);
205222
VerifySuccessProgress(progresses[0]);
206223
EXPECT_EQ(progresses[0], second_load);
@@ -220,13 +237,18 @@ TEST_F(BundleTest, LoadInvalidBundlesShouldFail) {
220237
};
221238
for (const auto& bundle : invalid_bundles) {
222239
std::vector<LoadBundleTaskProgress> progresses;
240+
std::promise<void> final_update;
223241
Future<LoadBundleTaskProgress> result = db->LoadBundle(
224-
bundle, [&progresses](const LoadBundleTaskProgress& progress) {
242+
bundle,
243+
[&progresses, &final_update](const LoadBundleTaskProgress& progress) {
225244
progresses.push_back(progress);
245+
SetPromiseValueWhenUpdateIsFinal(progress, final_update);
226246
});
227-
Await(result);
228247

248+
Await(result);
229249
EXPECT_NE(result.error(), Error::kErrorOk);
250+
251+
final_update.get_future().wait();
230252
ASSERT_EQ(progresses.size(), 1);
231253
VerifyErrorProgress(progresses[0]);
232254
}
@@ -306,13 +328,17 @@ TEST_F(BundleTest, LoadDocumentsFromOtherProjectsShouldFail) {
306328
Firestore* db = TestFirestore();
307329
auto bundle = CreateBundle("other-project");
308330
std::vector<LoadBundleTaskProgress> progresses;
331+
std::promise<void> final_update;
309332
Future<LoadBundleTaskProgress> result = db->LoadBundle(
310-
bundle, [&progresses](const LoadBundleTaskProgress& progress) {
333+
bundle,
334+
[&progresses, &final_update](const LoadBundleTaskProgress& progress) {
311335
progresses.push_back(progress);
336+
SetPromiseValueWhenUpdateIsFinal(progress, final_update);
312337
});
313338
Await(result);
314-
315339
EXPECT_NE(result.error(), Error::kErrorOk);
340+
341+
final_update.get_future().wait();
316342
ASSERT_EQ(progresses.size(), 2);
317343
EXPECT_THAT(progresses[0], InProgressWithLoadedDocuments(0));
318344
VerifyErrorProgress(progresses[1]);

firestore/integration_test_internal/src/util/integration_test_util.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
#include "firebase/app.h"
1010
#include "firebase/firestore.h"
1111
#include "firestore/src/common/hard_assert_common.h"
12+
13+
#if !defined(__ANDROID__)
1214
#include "firestore/src/main/firestore_main.h"
15+
#else
16+
#include "firestore/src/android/firestore_android.h"
17+
#endif // !defined(__ANDROID__)
1318

1419
namespace firebase {
1520
namespace firestore {

firestore/src/android/firestore_android.cc

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -440,25 +440,18 @@ WriteBatch FirestoreInternal::batch() const {
440440
return WriteBatch(new WriteBatchInternal(mutable_this(), result));
441441
}
442442

443-
Future<void> FirestoreInternal::RunTransaction(TransactionFunction* update,
444-
bool is_lambda) {
443+
Future<void> FirestoreInternal::RunTransaction(
444+
std::function<Error(Transaction&, std::string&)> update) {
445+
auto* lambda_update = new LambdaTransactionFunction(Move(update));
445446
Env env = GetEnv();
446447
Local<Object> transaction_function =
447-
TransactionInternal::Create(env, this, update);
448+
TransactionInternal::Create(env, this, lambda_update);
448449
Local<Task> task = env.Call(obj_, kRunTransaction, transaction_function);
449450

450451
if (!env.ok()) return {};
451452

452-
auto* completion =
453-
static_cast<LambdaTransactionFunction*>(is_lambda ? update : nullptr);
454453
return promises_->NewFuture<void>(env, AsyncFn::kRunTransaction, task,
455-
completion);
456-
}
457-
458-
Future<void> FirestoreInternal::RunTransaction(
459-
std::function<Error(Transaction&, std::string&)> update) {
460-
auto* lambda_update = new LambdaTransactionFunction(Move(update));
461-
return RunTransaction(lambda_update, /*is_lambda=*/true);
454+
lambda_update);
462455
}
463456

464457
Future<void> FirestoreInternal::DisableNetwork() {

firestore/src/android/firestore_android.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ namespace firestore {
2929
class Firestore;
3030
class ListenerRegistrationInternal;
3131
class Transaction;
32-
class TransactionFunction;
3332
class WriteBatch;
3433

3534
template <typename EnumT>
@@ -93,11 +92,6 @@ class FirestoreInternal {
9392

9493
WriteBatch batch() const;
9594

96-
// Runs transaction atomically.
97-
// TODO(b/191969448): Remove the is_lambda parameter if possible.
98-
Future<void> RunTransaction(TransactionFunction* update,
99-
bool is_lambda = false);
100-
10195
Future<void> RunTransaction(
10296
std::function<Error(Transaction&, std::string&)> update);
10397

firestore/src/android/lambda_transaction_function.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "app/src/assert.h"
1111
#include "firestore/src/android/firestore_android.h"
1212
#include "firestore/src/android/promise_android.h"
13+
#include "firestore/src/common/transaction_function.h"
1314
#include "firestore/src/include/firebase/firestore/transaction.h"
1415

1516
namespace firebase {

firestore/src/android/transaction_android.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "app/meta/move.h"
1010
#include "app/src/embedded_file.h"
1111
#include "firestore/src/android/wrapper.h"
12+
#include "firestore/src/common/transaction_function.h"
1213
#include "firestore/src/include/firebase/firestore/document_reference.h"
1314
#include "firestore/src/include/firebase/firestore/field_value.h"
1415
#include "firestore/src/include/firebase/firestore/map_field_value.h"

firestore/src/common/firestore.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,6 @@ WriteBatch Firestore::batch() const {
260260
return internal_->batch();
261261
}
262262

263-
Future<void> Firestore::RunTransaction(TransactionFunction* update) {
264-
if (!internal_) return FailedFuture<void>();
265-
return internal_->RunTransaction(update);
266-
}
267-
268263
Future<void> Firestore::RunTransaction(
269264
std::function<Error(Transaction&, std::string&)> update) {
270265
FIREBASE_ASSERT_MESSAGE(update, "invalid update parameter is passed in.");
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2021 Google LLC
2+
3+
#ifndef FIREBASE_FIRESTORE_SRC_COMMON_TRANSACTION_FUNCTION_H_
4+
#define FIREBASE_FIRESTORE_SRC_COMMON_TRANSACTION_FUNCTION_H_
5+
6+
#include <string>
7+
8+
#include "firebase/firestore/firestore_errors.h"
9+
10+
namespace firebase {
11+
namespace firestore {
12+
13+
class Transaction;
14+
15+
/**
16+
* An interface for providing code to be executed within a transaction
17+
* context.
18+
*/
19+
class TransactionFunction {
20+
public:
21+
virtual ~TransactionFunction() {}
22+
23+
/**
24+
* Subclass should override this method and put the transaction logic here.
25+
*
26+
* @param[in] transaction The transaction to run this function with.
27+
* @param[out] error_message You can set error message with this parameter.
28+
* @return Either Error::kErrorOk if successful or the error code from Error
29+
* that most closely matches the failure.
30+
*/
31+
virtual Error Apply(Transaction& transaction, std::string& error_message) = 0;
32+
};
33+
34+
} // namespace firestore
35+
} // namespace firebase
36+
37+
#endif // FIREBASE_FIRESTORE_SRC_COMMON_TRANSACTION_FUNCTION_H_

0 commit comments

Comments
 (0)