Skip to content

Commit

Permalink
Hardcode the index
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Mar 24, 2023
1 parent e4320bd commit 45e7c68
Showing 1 changed file with 41 additions and 35 deletions.
76 changes: 41 additions & 35 deletions scripts/ci-subtask.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,49 @@

# ./ci-subtask.sh <TOTAL_TASK_N> <TASK_INDEX> <INTEGRATION_TEST_ONLY>

# Get package test list.
packages=(`go list ./...`)
dirs=(`find . -iname "*_test.go" -exec dirname {} \; | sort -u | sed -e "s/^\./github.com\/tikv\/pd/"`)
tasks=($(comm -12 <(printf "%s\n" "${packages[@]}") <(printf "%s\n" "${dirs[@]}")))
# Get integration test list.
makefile_dirs=(`find . -iname "Makefile" -exec dirname {} \; | sort -u`)
submod_dirs=(`find . -iname "go.mod" -exec dirname {} \; | sort -u`)
integration_tasks=$(comm -12 <(printf "%s\n" "${makefile_dirs[@]}") <(printf "%s\n" "${submod_dirs[@]}") | grep "./tests/integrations/*")

all_tasks=("${tasks[@]}" "${integration_tasks[@]}")
if [[ $3 ]]; then
# Get integration test list.
makefile_dirs=($(find . -iname "Makefile" -exec dirname {} \; | sort -u))
submod_dirs=($(find . -iname "go.mod" -exec dirname {} \; | sort -u))
integration_tasks=$(comm -12 <(printf "%s\n" "${makefile_dirs[@]}") <(printf "%s\n" "${submod_dirs[@]}") | grep "./tests/integrations/*")
# Currently, we only have 3 integration tests, so we can hardcode the task index.
for t in ${integration_tasks[@]}; do
if [[ "$t" = "./tests/integrations/client" && "$2" = 9 ]]; then
printf "%s " "$t"
break
elif [[ "$t" = "./tests/integrations/tso" && "$2" = 7 ]]; then
printf "%s " "$t"
break
elif [[ "$t" = "./tests/integrations/mcs" && "$2" = 2 ]]; then
printf "%s " "$t"
break
fi
done
else
# Get package test list.
packages=($(go list ./...))
dirs=($(find . -iname "*_test.go" -exec dirname {} \; | sort -u | sed -e "s/^\./github.com\/tikv\/pd/"))
tasks=($(comm -12 <(printf "%s\n" "${packages[@]}") <(printf "%s\n" "${dirs[@]}")))

weight () {
[[ $1 =~ "tests/integrations" ]] && return 50
[[ $1 == "github.com/tikv/pd/server/api" ]] && return 30
[[ $1 == "github.com/tikv/pd/pkg/schedule" ]] && return 30
[[ $1 =~ "pd/tests" ]] && return 5
return 1
}
weight() {
[[ $1 == "github.com/tikv/pd/server/api" ]] && return 30
[[ $1 == "github.com/tikv/pd/pkg/schedule" ]] && return 30
[[ $1 =~ "pd/tests" ]] && return 5
return 1
}

scores=(`seq "$1" | xargs -I{} echo 0`)
scores=($(seq "$1" | xargs -I{} echo 0))

res=()
for t in ${all_tasks[@]}; do
min_i=0
for i in ${!scores[@]}; do
[[ ${scores[i]} -lt ${scores[$min_i]} ]] && min_i=$i
res=()
for t in ${tasks[@]}; do
min_i=0
for i in ${!scores[@]}; do
[[ ${scores[i]} -lt ${scores[$min_i]} ]] && min_i=$i
done
weight $t
scores[$min_i]=$((${scores[$min_i]} + $?))
[[ $(($min_i + 1)) -eq $2 ]] && res+=($t)
done
weight $t
scores[$min_i]=$((${scores[$min_i]} + $?))
if [[ $(($min_i+1)) -eq $2 ]]; then
# Integration test only.
if [[ $3 && "$t" =~ "tests/integrations" ]]; then
res+=($t)
elif [[ ! $3 && "$t" =~ "github.com/tikv/pd" ]]; then
res+=($t)
fi
fi
done

printf "%s " "${res[@]}"
printf "%s " "${res[@]}"
fi

0 comments on commit 45e7c68

Please sign in to comment.