commit:     18ccbe44a8dfad05bdaac3cf2ccca6ec1ce68103
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Tue Jul  9 18:53:20 2024 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Tue Jul  9 19:29:20 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=18ccbe44

dev-python/pymongo: Split test suite to workaround mongodb crash

Bug: https://bugs.gentoo.org/934389
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 dev-python/pymongo/pymongo-4.7.2.ebuild | 94 ++++++++++++++++++++-------------
 1 file changed, 57 insertions(+), 37 deletions(-)

diff --git a/dev-python/pymongo/pymongo-4.7.2.ebuild 
b/dev-python/pymongo/pymongo-4.7.2.ebuild
index fedcb4086de1..0b7255b485fd 100644
--- a/dev-python/pymongo/pymongo-4.7.2.ebuild
+++ b/dev-python/pymongo/pymongo-4.7.2.ebuild
@@ -99,6 +99,16 @@ python_test() {
                # fragile to timing? fails because we're getting too many logs
                
test/test_connection_logging.py::TestConnectionLoggingConnectionPoolOptions::test_maxConnecting_should_be_included_in_connection_pool_created_message_when_specified
        )
+       local run_separately=(
+               # need to run some tests separately and then restart mongodb
+               # to prevent it from crashing
+               # https://bugs.gentoo.org/934389
+               # note that this list must not overlap with EPYTEST_DESELECT
+               test/test_change_stream.py
+               test/test_collation.py
+               test/test_database.py
+               test/test_gridfs.py
+       )
 
        if ! use test-full; then
                # .invalid is guaranteed to return NXDOMAIN per RFC 6761
@@ -114,45 +124,55 @@ python_test() {
        local dbpath=${TMPDIR}/mongo.db
        local logpath=${TMPDIR}/mongod.log
 
-       # Now, the hard part: we need to find a free port for mongod.
-       # We're just trying to run it random port numbers and check the log
-       # for bind errors. It shall be noted that 'mongod --fork' does not
-       # return failure when it fails to bind.
-
-       mkdir -p "${dbpath}" || die
-       while true; do
-               ebegin "Trying to start mongod on port ${DB_PORT}"
-
-               LC_ALL=C \
-               mongod --dbpath "${dbpath}" --nojournal \
-                       --bind_ip ${DB_IP} --port ${DB_PORT} \
-                       --unixSocketPrefix "${TMPDIR}" \
-                       --logpath "${logpath}" --fork \
-               && sleep 2
-
-               # Now we need to check if the server actually started...
-               if [[ ${?} -eq 0 && -S "${TMPDIR}"/mongodb-${DB_PORT}.sock ]]; 
then
-                       # yay!
-                       eend 0
-                       break
-               elif grep -q 'Address already in use' "${logpath}"; then
-                       # ay, someone took our port!
-                       eend 1
-                       : $(( DB_PORT += 1 ))
-                       continue
-               else
-                       eend 1
-                       eerror "Unable to start mongod for tests. See the 
server log:"
-                       eerror "        ${logpath}"
-                       die "Unable to start mongod for tests."
-               fi
+       local stage failed=
+       for stage in 1 2; do
+               # Now, the hard part: we need to find a free port for mongod.
+               # We're just trying to run it random port numbers and check the 
log
+               # for bind errors. It shall be noted that 'mongod --fork' does 
not
+               # return failure when it fails to bind.
+
+               mkdir -p "${dbpath}" || die
+               while true; do
+                       ebegin "Trying to start mongod on port ${DB_PORT}"
+
+                       LC_ALL=C \
+                       mongod --dbpath "${dbpath}" --nojournal \
+                               --bind_ip ${DB_IP} --port ${DB_PORT} \
+                               --unixSocketPrefix "${TMPDIR}" \
+                               --logpath "${logpath}" --fork \
+                       && sleep 2
+
+                       # Now we need to check if the server actually started...
+                       if [[ ${?} -eq 0 && -S 
"${TMPDIR}"/mongodb-${DB_PORT}.sock ]]; then
+                               # yay!
+                               eend 0
+                               break
+                       elif grep -q 'Address already in use' "${logpath}"; then
+                               # ay, someone took our port!
+                               eend 1
+                               : $(( DB_PORT += 1 ))
+                               continue
+                       else
+                               eend 1
+                               eerror "Unable to start mongod for tests. See 
the server log:"
+                               eerror "        ${logpath}"
+                               die "Unable to start mongod for tests."
+                       fi
+               done
+
+               case ${stage} in
+                       1)
+                               nonfatal epytest "${run_separately[@]}" || 
failed=1
+                               ;;
+                       2)
+                               EPYTEST_DESELECT+=( "${run_separately[@]}" )
+                               nonfatal epytest || failed=1
+                               ;;
+               esac
+
+               mongod --dbpath "${dbpath}" --shutdown || die
        done
 
-       local failed
-       nonfatal epytest || failed=1
-
-       mongod --dbpath "${dbpath}" --shutdown || die
-
        [[ ${failed} ]] && die "Tests fail with ${EPYTHON}"
 
        rm -rf "${dbpath}" || die

Reply via email to