Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions test/harness_selftest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,17 @@ check "check_num still fails two unequal numbers" \
check "check_num accepts a decimal and a sign" \
"$(_probe check_num "decimal" "-1.5" "-1.5")" "0"

check "check_text refuses two empty strings, where plain check passes" \
"$(_probe check_text "empty vs empty" "" "")" "1"
check "check_text refuses one empty side" \
"$(_probe check_text "one empty" "abc" "")" "1"
check "check_text compares two md5 hashes, which check_num cannot" \
"$(_probe check_text "md5" "9dd4e461268c8034f5c8564e155c67a6" "9dd4e461268c8034f5c8564e155c67a6")" "0"
check "check_text still fails two different strings" \
"$(_probe check_text "differ" "abc" "def")" "1"
check "check_num refuses an md5, which is why check_text exists" \
"$(_probe check_num "md5" "9dd4e461268c8034f5c8564e155c67a6" "9dd4e461268c8034f5c8564e155c67a6")" "1"

check "check_ratio refuses an empty measurement" \
"$(_probe check_ratio "empty" "" "100" "0.5")" "1"
check "check_ratio refuses a zero denominator rather than dividing by it" \
Expand Down
27 changes: 27 additions & 0 deletions test/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,33 @@ pgc_is_number() { # $1 -> 0 when $1 is a number
return 0
}

# check_text LABEL GOT WANT -- check, with both sides required to be non-empty.
#
# check_num covers a measurement that is a NUMBER. Plenty of oracles are not: an
# md5 over an ordered result, a plan node name, a returned string. check_num
# rejects those outright -- it refuses two identical md5 hashes, because an md5
# is not a number -- so a suite comparing one has nothing to reach for and falls
# back to plain check, where "" equals "" and prints PASS (#418).
#
# That is the same defect, on the larger half: 35 places in this tree compare an
# md5(string_agg(...)) oracle, and every one of them is a down cluster or an
# errored query away from comparing nothing with nothing.
#
# Deliberately weaker than check_num: it asserts presence, not shape. A caller
# that knows the shape should say so, and native_index_projection.sh's agree()
# additionally requires 32 hex characters before it trusts either side.
check_text() {
local name="$1" got="$2" want="$3"
if [ -z "$got" ] || [ -z "$want" ]; then
PGC_CHECKS=$((PGC_CHECKS + 1))
PGC_FAIL=1
echo "FAIL $name: a side is empty, so nothing was compared:" \
"got [$got] want [$want]"
return 1
fi
check "$name" "$got" "$want"
}

# check_num LABEL GOT WANT -- check, with both sides required to be numbers.
check_num() {
local name="$1" got="$2" want="$3"
Expand Down
10 changes: 5 additions & 5 deletions test/native_index_projection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ check "partial index finds the row inside its predicate" \
# prints PASS (#418). This oracle is the strongest assertion in the file, so it is the
# worst one to have silently comparing two empty strings.
#
# Local guard on purpose. #418 proposes `check_num` in `test/lib.sh` and
# @ChronicallyJD owns it; this file should adopt that helper when it lands and drop
# the check below.
# The emptiness half is `check_text` in `test/lib.sh` now (#418, #422), so this file no
# longer carries its own version of it. The shape half stays here: an md5 is 32 hex
# characters, and this file knows that where the shared helper only knows "not empty".
agree() { # $1 label, $2 predicate, $3 selected expression
local viaix viaseq
viaix=$(qset "SET enable_seqscan=off; SET enable_bitmapscan=off" \
Expand All @@ -105,11 +105,11 @@ agree() { # $1 label, $2 predicate, $3 selected expression
"SELECT md5(string_agg(t::text, ',' ORDER BY t))
FROM (SELECT $3 AS t FROM w WHERE $2) s")
if ! grep -qE '^[0-9a-f]{32}$' <<<"$viaix" || ! grep -qE '^[0-9a-f]{32}$' <<<"$viaseq"; then
check "$1 (both sides must be a real result, not empty)" \
check "$1 (both sides must be a real md5, not empty or an error)" \
"index=[$viaix] seq=[$viaseq]" "two md5 hashes"
return
fi
check "$1" "$viaix" "$viaseq"
check_text "$1" "$viaix" "$viaseq"
}
agree "plain index agrees with a sequential scan" "k BETWEEN 1000 AND 9999" "k"
agree "late-column index agrees" "c18 > repeat('x',80)||'99000'" "k"
Expand Down
Loading