Skip to content

Commit 549decf

Browse files
authored
Merge branch 'main' into dconeybe/ApkSizeSdkParseErrorMessage
2 parents 8cbc943 + a00e2be commit 549decf

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed

firebase-dataconnect/emulator/emulator.sh

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ function parse_args {
3737

3838
local OPTIND=1
3939
local OPTERR=0
40-
while getopts ":c:p:v:hw" arg ; do
40+
while getopts ":c:p:v:hwg" arg ; do
4141
case "$arg" in
4242
c) emulator_binary="${OPTARG}" ;;
43+
g) emulator_binary="gradle" ;;
4344
p) postgresql_string="${OPTARG}" ;;
4445
v) preview_flags="${OPTARG}" ;;
4546
w) wipe_and_restart_postgres_pod=1 ;;
@@ -58,13 +59,26 @@ function parse_args {
5859
exit 2
5960
;;
6061
*)
61-
echo "INTERNAL ERROR: unknown argument: $arg" >&2
62-
exit 1
62+
log_error_and_exit "INTERNAL ERROR: unknown argument: $arg"
6363
;;
6464
esac
6565
done
6666

67-
export DATACONNECT_EMULATOR_BINARY_PATH="${emulator_binary}"
67+
if [[ $emulator_binary != "gradle" ]] ; then
68+
export DATACONNECT_EMULATOR_BINARY_PATH="${emulator_binary}"
69+
else
70+
run_command "${SCRIPT_DIR}/../../gradlew" -p "${SCRIPT_DIR}/../.." --configure-on-demand :firebase-dataconnect:connectors:downloadDebugDataConnectExecutable
71+
local gradle_emulator_binaries=("${SCRIPT_DIR}"/../connectors/build/intermediates/dataconnect/debug/executable/*)
72+
if [[ ${#gradle_emulator_binaries[@]} -ne 1 ]]; then
73+
log_error_and_exit "expected exactly 1 emulator binary from gradle, but got ${#gradle_emulator_binaries[@]}: ${gradle_emulator_binaries[*]}"
74+
fi
75+
local gradle_emulator_binary="${gradle_emulator_binaries[@]}"
76+
if [[ ! -e $gradle_emulator_binary ]] ; then
77+
log_error_and_exit "emulator binary from gradle does not exist: ${gradle_emulator_binary}"
78+
fi
79+
export DATACONNECT_EMULATOR_BINARY_PATH="${gradle_emulator_binary}"
80+
fi
81+
6882
export FIREBASE_DATACONNECT_POSTGRESQL_STRING="${postgresql_string}"
6983
export DATA_CONNECT_PREVIEW="${preview_flags}"
7084

@@ -90,8 +104,12 @@ function print_help {
90104
echo
91105
echo "Options:"
92106
echo " -c <data_connect_emulator_binary_path>"
93-
echo " Uses the Data Connect Emulator binary at the given path. If not specified, "
94-
echo " or if specified as the empty string, then the emulator binary is downloaded."
107+
echo " Uses the Data Connect Emulator binary at the given path. A value of \"gradle\" "
108+
echo " will use the same binary as the Gradle build. If not specified, or if specified "
109+
echo " as the empty string, then the emulator binary is downloaded."
110+
echo
111+
echo " -g"
112+
echo " Shorthand for: -c gradle"
95113
echo
96114
echo " -p <postgresql_connection_string>"
97115
echo " Uses the given string to connect to the PostgreSQL server. If not specified "
@@ -116,4 +134,9 @@ function log {
116134
echo "${LOG_PREFIX}$*"
117135
}
118136

137+
function log_error_and_exit {
138+
echo "${LOG_PREFIX}ERROR: $*" >&2
139+
exit 1
140+
}
141+
119142
main "$@"

firebase-dataconnect/src/androidTest/kotlin/com/google/firebase/dataconnect/QuerySubscriptionIntegrationTest.kt

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import kotlinx.coroutines.FlowPreview
4141
import kotlinx.coroutines.TimeoutCancellationException
4242
import kotlinx.coroutines.async
4343
import kotlinx.coroutines.flow.catch
44-
import kotlinx.coroutines.flow.collect
4544
import kotlinx.coroutines.flow.distinctUntilChanged
4645
import kotlinx.coroutines.flow.first
4746
import kotlinx.coroutines.flow.flowOn
@@ -446,8 +445,18 @@ class QuerySubscriptionIntegrationTest : DataConnectIntegrationTestBase() {
446445
schema.getPerson(personId).withDataDeserializer(serializer<GetPersonDataNoName2>())
447446

448447
turbineScope {
449-
val noName1Flow = noName1Query.subscribe().flow.distinctUntilChanged().testIn(backgroundScope)
450-
val noName2Flow = noName2Query.subscribe().flow.distinctUntilChanged().testIn(backgroundScope)
448+
val noName1Flow =
449+
noName1Query
450+
.subscribe()
451+
.flow
452+
.distinctUntilChanged(::areEquivalentQuerySubscriptionResults)
453+
.testIn(backgroundScope)
454+
val noName2Flow =
455+
noName2Query
456+
.subscribe()
457+
.flow
458+
.distinctUntilChanged(::areEquivalentQuerySubscriptionResults)
459+
.testIn(backgroundScope)
451460
withClue("noName1Flow-0") { noName1Flow.awaitPersonWithName("Name0") }
452461
withClue("noName2Flow-0") { noName2Flow.awaitPersonWithName("Name0") }
453462

@@ -636,5 +645,37 @@ class QuerySubscriptionIntegrationTest : DataConnectIntegrationTestBase() {
636645
val person = withClue("data.person") { data.person.shouldNotBeNull() }
637646
withClue("person.name") { person.name shouldBe name }
638647
}
648+
649+
/**
650+
* Returns `true` if, and only if, the receiver is a non-null instance of
651+
* [DataConnectOperationException] that indicates that the failure is due to decoding of the
652+
* server response failed.
653+
*/
654+
fun Throwable?.isDecodingServerResponseFailed(): Boolean =
655+
this is DataConnectOperationException && this.response.errors.isEmpty()
656+
657+
/**
658+
* Returns `true` if, and only if, the receiver's result is a failure that indicates that
659+
* decoding of the server response failed.
660+
*/
661+
fun QuerySubscriptionResult<*, *>.isDecodingServerResponseFailed(): Boolean =
662+
result.exceptionOrNull().isDecodingServerResponseFailed()
663+
664+
/**
665+
* Checks if two [QuerySubscriptionResult] instances are "equivalent"; that is, they are both
666+
* equal when compared using the `==` operator, or they are both failures due to decoding of the
667+
* server response failed.
668+
*
669+
* This is useful when testing flows because the same decoding failure can happen more than once
670+
* in a row based on other asynchronous operations but testing for "distinctness" will consider
671+
* those two failures as "distinct" when the test wants them to be treated as "equal".
672+
*
673+
* See https://github.com/firebase/firebase-android-sdk/pull/7210 for a full explanation.
674+
*/
675+
fun areEquivalentQuerySubscriptionResults(
676+
old: QuerySubscriptionResult<*, *>,
677+
new: QuerySubscriptionResult<*, *>
678+
): Boolean =
679+
(old == new) || (old.isDecodingServerResponseFailed() && new.isDecodingServerResponseFailed())
639680
}
640681
}

0 commit comments

Comments
 (0)