Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test suite partitioning #1110

Merged
merged 36 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e0c8c41
WIP Add test partitioning capability
Aug 22, 2023
45f8c70
Add CLI options for test partitioning
Aug 22, 2023
e1ea3fb
Add test partitioning code
Aug 22, 2023
f3e4b45
Improve skip messaging
Aug 22, 2023
fd0dcb2
Add locks and comments to the partitioning code
Aug 23, 2023
baf8176
Add more comments to partitioning code
Aug 23, 2023
fe73c9d
Fix error message
Aug 23, 2023
92902a9
Merge branch 'main' into test-partitioning
Aug 24, 2023
21d205c
Add files with test lists for partition monitoring
Aug 24, 2023
d5a8591
Fix linter issues
Aug 25, 2023
6a8c141
Add more info to partitioning tests
Aug 25, 2023
152ad8c
Remove unused test TestAccVcdVAppRawMulti
Aug 25, 2023
c610abd
Fix linter warnings
Aug 25, 2023
fc7625f
Fix tags handling for partitioning
Aug 25, 2023
f01df70
Update tags handling
Aug 25, 2023
fae5a75
Merge branch 'main' into test-partitioning
Aug 25, 2023
04c0b4a
Increase Go version for security check
Aug 25, 2023
c1f0401
Increase Go version for security check
Aug 25, 2023
50d16ef
Add provisional script to start multiple tests
Aug 28, 2023
c872456
Add go version to security output
Aug 28, 2023
31254c0
Merge branch 'main' into test-partitioning
Aug 28, 2023
7ebbd08
Remove redundant pre/post checks
Sep 4, 2023
ee6732a
Improve test partitioning
Sep 7, 2023
28dea2e
Fix warnings in partitioning_test
Sep 7, 2023
efc02dd
Merge branch 'main' into test-partitioning
Sep 13, 2023
ee1534f
Merge branch 'main' into test-partitioning
Sep 15, 2023
c63ed28
Add changelog entry
Sep 19, 2023
df8aa00
Fix always skipping TestAccVcdLBAppRule
Sep 20, 2023
8ba296b
Remove redundant preTestChecks and postTestChecks
Sep 20, 2023
2dfdeb5
Prevent skipping some tests with -vcd-add-provider
Sep 20, 2023
b8f2c23
Add partitioned testing docs
Sep 21, 2023
c6213c9
Remove unneeded script
Sep 21, 2023
7d9a734
Add explanatory note about tagged tests
Sep 21, 2023
5fec6f0
Add exclude lines for partitioned tests files
Sep 21, 2023
f7d36e2
Fix docs
Sep 21, 2023
67dee8c
Update docs
Sep 21, 2023
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
1 change: 1 addition & 0 deletions .changes/v3.11.0/1110-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add ability to split the test suite across several VCDs [GH-1110]
1 change: 1 addition & 0 deletions scripts/gosec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function get_gosec {
function run_gosec {
if [ -n "$gosec" ]
then
go version
$gosec -tests -tags ALL ./...
exit_code=$?
if [ "$exit_code" != "0" ]
Expand Down
119 changes: 119 additions & 0 deletions scripts/start-multi-node-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env bash

# Quality set for bash scripts:
# [set -e] fails on error
set -e

# [set -u ] stops the script on unset variables
set -u

# [set -o pipefail] triggers a failure if one of the commands in the pipe fail
set -o pipefail

node=$1
shift
partitions=$#
relative_configs=$@

if [[ $partitions < 2 ]]
then
echo "Syntax: ./scripts/start-multi-node-test.sh node-number config1 config2 [config3 [config4 ...]]"
exit 1
fi

if [ ! -d scripts ]
then
echo "This script must be launched at the top of the repository, as ./scripts/start-multi-node-test.sh"
exit 1
fi

multi_dir="split$partitions"

if [ -d "$multi_dir" ]
then
echo "directory '$multi_dir' already exists"
exit 1
fi

function exists_in_path {
what=$1
for dir in $(echo $PATH | tr ':' ' ')
do
wanted=$dir/$what
if [ -x $wanted ]
then
echo $wanted
return
fi
done
}

for needed in tmux git realpath jq
Didainius marked this conversation as resolved.
Show resolved Hide resolved
do
found_need=$(exists_in_path $needed)
if [ -z "$found_need" ]
then
echo "needed tool $needed not found"
exit 1
fi
done

count=0
for tb in $relative_configs
do
if [ ! -f $tb ]
then
echo "$tb not found"
exit 1
fi
configs[$count]=$(realpath $tb)
count=$((count+1))
done

current_repo_url=$(git config --get remote.origin.url)
if [ -z "$current_repo_url" ]
then
echo "error retrieving current repository URL"
exit 1
fi

current_commit=$(git rev-parse HEAD)
if [ -z "$current_commit" ]
then
echo "error retrieving current commit hash"
exit 1
fi

mkdir "${multi_dir}" || exit 1
cd ${multi_dir} || exit 1

echo "configs ${configs[*]}"
echo "partitions ${partitions}"

for n in $(seq 1 $partitions)
do
git clone ${current_repo_url}
if [ "$?" != "0" ]
then
echo "error cloning current repository"
exit 1
fi
if [ ! -d terraform-provider-vcd ]
then
echo "terraform-provider-vcd not cloned in node $n"
exit 1
fi
mv terraform-provider-vcd "node$n"
cd "node$n/vcd"
pwd
index=$(($n-1))
cp ${configs[$index]} vcd_test_config.json

# TODO: this change is only needed while developing the current PR in branch
git checkout test-partitioning
# TODO: start tmux session with test
# go test -tags functional -v -vcd-partitions=$partitions -vcd-partition-node=$n -vcd-short 2>&1 > testacc-node$n.txt
Didainius marked this conversation as resolved.
Show resolved Hide resolved
cd -

done

37 changes: 35 additions & 2 deletions vcd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"testing"
"text/template"
Expand Down Expand Up @@ -55,7 +56,9 @@ func init() {
setStringFlag(&vcdSkipPattern, "vcd-skip-pattern", "VCD_SKIP_PATTERN", "Skip tests that match the pattern (implies vcd-pre-post-checks")
setBoolFlag(&skipLeftoversRemoval, "vcd-skip-leftovers-removal", "VCD_SKIP_LEFTOVERS_REMOVAL", "Do not attempt removal of leftovers at the end of the test suite")
setBoolFlag(&silentLeftoversRemoval, "vcd-silent-leftovers-removal", "VCD_SILENT_LEFTOVERS_REMOVAL", "Omit details during removal of leftovers")

setStringFlag(&testListFileName, "vcd-partition-tests-file", "VCD_PARTITION_TESTS_FILE", "Name of the file containing the tests to run in the current partition node")
Didainius marked this conversation as resolved.
Show resolved Hide resolved
setIntFlag(&numberOfPartitions, "vcd-partitions", "VCD_PARTITIONS", "")
setIntFlag(&partitionNode, "vcd-partition-node", "VCD_PARTITION_NODE", "")
}

// Structure to get info from a config json file that the user specifies
Expand Down Expand Up @@ -389,7 +392,17 @@ func GetVarsFromTemplate(tmpl string) []string {
// configuration.
// Returns the text of a ready-to-use Terraform directive. It also saves the filled
// template to a file, for further troubleshooting.
func templateFill(tmpl string, data StringMap) string {
func templateFill(tmpl string, inputData StringMap) string {

// Copying the input data, to prevent side effects in the original string map:
// When we use the option -vcd-add-provider, the data will also contain the fields
// needed to populate the provider. Some of those fields are empty (e.g. "Token")
// If the data is evaluated (testParamsNotEmpty) after filling the template, the
// test gets skipped for what happen to be mysterious reasons.
data := make(StringMap)
for k, v := range inputData {
data[k] = v
}

// Gets the name of the function containing the template
caller := callFuncName()
Expand Down Expand Up @@ -887,6 +900,13 @@ func TestMain(m *testing.M) {
// Runs all test functions
exitCode := m.Run()

if numberOfPartitions != 0 {
entTestFileName := getTestFileName("end", testConfig.Provider.VcdVersion)
err := os.WriteFile(entTestFileName, []byte(fmt.Sprintf("%d", exitCode)), 0600)
if err != nil {
fmt.Printf("error writing to file '%s': %s\n", entTestFileName, err)
}
}
if vcdShowCount {
fmt.Printf("Pass: %5d - Skip: %5d - Fail: %5d\n", vcdPassCount, vcdSkipCount, vcdFailCount)
}
Expand Down Expand Up @@ -1127,6 +1147,18 @@ func setStringFlag(varPointer *string, name, envVar, help string) {
flag.StringVar(varPointer, name, *varPointer, help)
}

func setIntFlag(varPointer *int, name, envVar, help string) {
if envVar != "" && os.Getenv(envVar) != "" {
var err error
value := os.Getenv(envVar)
*varPointer, err = strconv.Atoi(value)
if err != nil {
panic(fmt.Sprintf("error converting value '%s' to integer: %s", value, err))
}
}
flag.IntVar(varPointer, name, *varPointer, help)
}

type envHelper struct {
vars map[string]string
}
Expand Down Expand Up @@ -1392,6 +1424,7 @@ func timeStamp() string {
// contains a pattern that matches the test name.
// 6. If the flag -vcd-re-run-failed is true, it will only run the tests that failed in the previous run
func preTestChecks(t *testing.T) {
handlePartitioning(testConfig.Provider.VcdVersion, testConfig.Provider.Url, t)
// if the test runs without -vcd-pre-post-checks, all post-checks will be skipped
if !vcdPrePostChecks {
return
Expand Down
2 changes: 2 additions & 0 deletions vcd/datasource_vcd_nsxt_edgegateway_qos_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestAccVcdDatasourceNsxtGatewayQosProfile(t *testing.T) {
preTestChecks(t)
if vcdShortTest {
t.Skip(acceptanceTestsSkipped)
return
Expand Down Expand Up @@ -46,6 +47,7 @@ func TestAccVcdDatasourceNsxtGatewayQosProfile(t *testing.T) {
},
},
})
postTestChecks(t)
}

const testAccVcdDatasourceNsxtGatewayQosProfile = `
Expand Down
Loading