Skip to content

Commit

Permalink
fixed UT flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
fchastanet committed Jan 8, 2024
1 parent f637e31 commit 94a3674
Show file tree
Hide file tree
Showing 25 changed files with 234 additions and 68 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,33 @@ jobs:
include:
- vendor: ubuntu
bashImage: ubuntu:20.04
batsOptions: -j 5
batsOptions: -j 30
bashTarVersion: 4.4
runPrecommitTests: false
- vendor: ubuntu
bashImage: ubuntu:20.04
bashTarVersion: 5.0
batsOptions: -j 5
batsOptions: -j 30
runPrecommitTests: false
- vendor: ubuntu
bashImage: ubuntu:20.04
bashTarVersion: 5.1
batsOptions: -j 5
batsOptions: -j 30
runPrecommitTests: true
- vendor: alpine
bashTarVersion: 4.4
bashImage: amd64/bash:4.4-alpine3.18
batsOptions: -j 5
batsOptions: -j 30
runPrecommitTests: false
- vendor: alpine
bashTarVersion: 5.0
bashImage: amd64/bash:5.0-alpine3.18
batsOptions: -j 5
batsOptions: -j 30
runPrecommitTests: false
- vendor: alpine
bashTarVersion: 5.1
bashImage: amd64/bash:5.1-alpine3.18
batsOptions: -j 5
batsOptions: -j 30
runPrecommitTests: false
steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ cliCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
38 changes: 36 additions & 2 deletions bin/dbImport
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,12 @@ Version::checkMinimal() {

Assert::commandExists "${commandName}" "${help}" || return 2

# shellcheck disable=SC2034
local status=0
# shellcheck disable=SC2034
local -a pipeStatus=()
local version
version="$("${commandName}" "${argVersion}" 2>&1 | ${parseVersionCallback})"
version="$("${commandName}" "${argVersion}" 2>&1 | ${parseVersionCallback} || Bash::handlePipelineFailure status pipeStatus)"

Log::displayDebug "check ${commandName} version ${version} against minimal ${minimalVersion}"

Expand Down Expand Up @@ -975,6 +979,36 @@ Assert::tty() {
[[ -t 1 || -t 2 ]]
}

# @description ignore exit code 141 from simple command pipes
# @example use with:
# local resultingStatus=0
# local -a originalPipeStatus=()
# cmd1 | cmd2 || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true
# [[ "${resultingStatus}" = "0" ]]
# @arg $1 resultingStatusCode:&int (passed by reference) (optional) resulting status code
# @arg $2 originalStatus:int[] (passed by reference) (optional) copy of original PIPESTATUS array
# @env PIPESTATUS assuming that this function is called like in the example provided
# @see https://unix.stackexchange.com/a/709880/582856
Bash::handlePipelineFailure() {
local -a pipeStatusBackup=("${PIPESTATUS[@]}")
local -n handlePipelineFailure_resultingStatusCode=$1
local -n handlePipelineFailure_originalStatus=$2
# shellcheck disable=SC2034
handlePipelineFailure_originalStatus=("${pipeStatusBackup[@]}")
handlePipelineFailure_resultingStatusCode=0
local statusCode
for statusCode in "${pipeStatusBackup[@]}"; do
if ((statusCode == 141)); then
return 0
elif ((statusCode > 0)); then
# shellcheck disable=SC2034
handlePipelineFailure_resultingStatusCode="${statusCode}"
break
fi
done
return "${handlePipelineFailure_resultingStatusCode}"
}

# @description list files of dir with given extension and display it as a list one by line
#
# @arg $1 dir:String the directory to list
Expand Down Expand Up @@ -2194,7 +2228,7 @@ dbImportCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/dbImportProfile
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,7 @@ dbImportProfileCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
62 changes: 50 additions & 12 deletions bin/dbImportStream
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,36 @@ Assert::commandExists() {
return 0
}

# @description ignore exit code 141 from simple command pipes
# @example use with:
# local resultingStatus=0
# local -a originalPipeStatus=()
# cmd1 | cmd2 || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true
# [[ "${resultingStatus}" = "0" ]]
# @arg $1 resultingStatusCode:&int (passed by reference) (optional) resulting status code
# @arg $2 originalStatus:int[] (passed by reference) (optional) copy of original PIPESTATUS array
# @env PIPESTATUS assuming that this function is called like in the example provided
# @see https://unix.stackexchange.com/a/709880/582856
Bash::handlePipelineFailure() {
local -a pipeStatusBackup=("${PIPESTATUS[@]}")
local -n handlePipelineFailure_resultingStatusCode=$1
local -n handlePipelineFailure_originalStatus=$2
# shellcheck disable=SC2034
handlePipelineFailure_originalStatus=("${pipeStatusBackup[@]}")
handlePipelineFailure_resultingStatusCode=0
local statusCode
for statusCode in "${pipeStatusBackup[@]}"; do
if ((statusCode == 141)); then
return 0
elif ((statusCode > 0)); then
# shellcheck disable=SC2034
handlePipelineFailure_resultingStatusCode="${statusCode}"
break
fi
done
return "${handlePipelineFailure_resultingStatusCode}"
}

# @description get absolute conf file from specified conf folder deduced using these rules
# * from absolute file (ignores <confFolder> and <extension>)
# * relative to where script is executed (ignores <confFolder> and <extension>)
Expand Down Expand Up @@ -742,8 +772,12 @@ Version::checkMinimal() {

Assert::commandExists "${commandName}" "${help}" || return 2

# shellcheck disable=SC2034
local status=0
# shellcheck disable=SC2034
local -a pipeStatus=()
local version
version="$("${commandName}" "${argVersion}" 2>&1 | ${parseVersionCallback})"
version="$("${commandName}" "${argVersion}" 2>&1 | ${parseVersionCallback} || Bash::handlePipelineFailure status pipeStatus)"

Log::displayDebug "check ${commandName} version ${version} against minimal ${minimalVersion}"

Expand Down Expand Up @@ -2006,7 +2040,7 @@ dbImportStreamCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down Expand Up @@ -2149,7 +2183,7 @@ run() {
Version::checkMinimal "gawk" "--version" "5.0.1"

# create db instances
declare -Agx dbTargetInstance
local -Agx dbTargetInstance

Database::newInstance dbTargetInstance "${optionTargetDsn}"
Database::setQueryOptions dbTargetInstance "${dbTargetInstance[QUERY_OPTIONS]} --connect-timeout=5"
Expand All @@ -2158,7 +2192,11 @@ run() {
initializeDefaultTargetMysqlOptions dbTargetInstance "${argTargetDbName}"

# TODO character set should be retrieved from dump files if possible
declare remoteCharacterSet="${optionCharacterSet:-${defaultRemoteCharacterSet}}"
local remoteCharacterSet="${optionCharacterSet:-${defaultRemoteCharacterSet}}"

local status=0
# shellcheck disable=SC2034
local -a pipeStatus=()

# shellcheck disable=2086
(
Expand All @@ -2167,19 +2205,19 @@ run() {
elif [[ "${argDumpFile}" =~ \.gz$ ]]; then
zcat "${argDumpFile}"
fi
# zcat will continue to write to stdout whereas awk has finished if table has been found
# we detect this case because zcat will return code 141 because pipe closed
status=$?
if [[ "${status}" -eq "141" ]]; then true; else exit "${status}"; fi
) |
awk \
-v PROFILE_COMMAND="${profileCommandFile}" \
-v CHARACTER_SET="${remoteCharacterSet}" \
--source "${awkScript}" \
- | mysql \
"--defaults-extra-file=${dbTargetInstance['AUTH_FILE']}" \
${dbTargetInstance['DB_IMPORT_OPTIONS']} \
"${argTargetDbName}" || exit $?
- |
mysql \
"--defaults-extra-file=${dbTargetInstance['AUTH_FILE']}" \
${dbTargetInstance['DB_IMPORT_OPTIONS']} \
"${argTargetDbName}" ||
# zcat will continue to write to stdout whereas awk has finished if table has been found
# we detect this case because zcat will return code 141 because pipe closed
Bash::handlePipelineFailure status pipeStatus
}

if [[ "${BASH_FRAMEWORK_QUIET_MODE:-0}" = "1" ]]; then
Expand Down
42 changes: 38 additions & 4 deletions bin/dbQueryAllDatabases
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,12 @@ Version::checkMinimal() {

Assert::commandExists "${commandName}" "${help}" || return 2

# shellcheck disable=SC2034
local status=0
# shellcheck disable=SC2034
local -a pipeStatus=()
local version
version="$("${commandName}" "${argVersion}" 2>&1 | ${parseVersionCallback})"
version="$("${commandName}" "${argVersion}" 2>&1 | ${parseVersionCallback} || Bash::handlePipelineFailure status pipeStatus)"

Log::displayDebug "check ${commandName} version ${version} against minimal ${minimalVersion}"

Expand Down Expand Up @@ -890,6 +894,36 @@ Assert::tty() {
[[ -t 1 || -t 2 ]]
}

# @description ignore exit code 141 from simple command pipes
# @example use with:
# local resultingStatus=0
# local -a originalPipeStatus=()
# cmd1 | cmd2 || Bash::handlePipelineFailure resultingStatus originalPipeStatus || true
# [[ "${resultingStatus}" = "0" ]]
# @arg $1 resultingStatusCode:&int (passed by reference) (optional) resulting status code
# @arg $2 originalStatus:int[] (passed by reference) (optional) copy of original PIPESTATUS array
# @env PIPESTATUS assuming that this function is called like in the example provided
# @see https://unix.stackexchange.com/a/709880/582856
Bash::handlePipelineFailure() {
local -a pipeStatusBackup=("${PIPESTATUS[@]}")
local -n handlePipelineFailure_resultingStatusCode=$1
local -n handlePipelineFailure_originalStatus=$2
# shellcheck disable=SC2034
handlePipelineFailure_originalStatus=("${pipeStatusBackup[@]}")
handlePipelineFailure_resultingStatusCode=0
local statusCode
for statusCode in "${pipeStatusBackup[@]}"; do
if ((statusCode == 141)); then
return 0
elif ((statusCode > 0)); then
# shellcheck disable=SC2034
handlePipelineFailure_resultingStatusCode="${statusCode}"
break
fi
done
return "${handlePipelineFailure_resultingStatusCode}"
}

# @description list files of dir with given extension and display it as a list one by line
#
# @arg $1 dir:String the directory to list
Expand Down Expand Up @@ -1924,7 +1958,7 @@ dbQueryAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(specify\ the\ number\ of\ db\ to\ query\ in\ parallel)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: 1"
echo ' Default value: 1'
echo -e " ${__HELP_OPTION_COLOR}--bar${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-b${__HELP_NORMAL} {single}"
local -a helpArray
# shellcheck disable=SC2054
Expand All @@ -1935,7 +1969,7 @@ dbQueryAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(character\ to\ use\ to\ separate\ mysql\ column)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: |"
echo ' Default value: |'
echo
echo -e "${__HELP_TITLE_COLOR}QUERY OPTIONS:${__RESET_COLOR}"
echo -e " ${__HELP_OPTION_COLOR}--from-dsn${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-f <String>${__HELP_NORMAL} {single}"
Expand Down Expand Up @@ -1985,7 +2019,7 @@ dbQueryAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
6 changes: 3 additions & 3 deletions bin/dbScriptAllDatabases
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ dbScriptAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(specify\ the\ number\ of\ db\ to\ query\ in\ parallel)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: 1"
echo ' Default value: 1'
echo -e " ${__HELP_OPTION_COLOR}--bar${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-b${__HELP_NORMAL} {single}"
local -a helpArray
# shellcheck disable=SC2054
Expand Down Expand Up @@ -1919,7 +1919,7 @@ dbScriptAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(if\ output\ dir\ provided\,\ will\ log\ each\ db\ result\ to\ log\ file)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: none"
echo ' Default value: none'
echo ' Possible values: none|log'
echo
echo -e "${__HELP_TITLE_COLOR}GLOBAL OPTIONS:${__RESET_COLOR}"
Expand Down Expand Up @@ -1963,7 +1963,7 @@ dbScriptAllDatabasesCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/doc
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ docCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/gitIsAncestorOf
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ gitIsAncestorOfCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/gitIsBranch
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ gitIsBranchCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/gitRenameBranch
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ gitRenameBranchCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
2 changes: 1 addition & 1 deletion bin/installRequirements
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ installRequirementsCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
4 changes: 2 additions & 2 deletions bin/mysql2puml
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ mysql2pumlCommand() {
# shellcheck disable=SC2054
helpArray=(header\ configuration\ of\ the\ plant\ uml\ file)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo
echo -e "${__HELP_TITLE_COLOR}GLOBAL OPTIONS:${__RESET_COLOR}"
echo -e " ${__HELP_OPTION_COLOR}--bash-framework-config <String>${__HELP_NORMAL} {single}"
Expand Down Expand Up @@ -1594,7 +1594,7 @@ mysql2pumlCommand() {
# shellcheck disable=SC2054
helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped)
echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")"
echo " Default value: default"
echo ' Default value: default'
echo ' Possible values: default|default-force|noColor'
echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}"
local -a helpArray
Expand Down
Loading

0 comments on commit 94a3674

Please sign in to comment.