Fix race conditions in DHCP test

The test named "correctly handles multiple DELs for the same container" in the ipam/dhcp package experiences race conditions when multiple goroutines concurrently access and modify the Args struct (of type CmdArgs).
To address these issues, a copy of the CmdArgs struct is now created in each function to eliminate data races.

Also, the test-linux.sh and test-windows.sh scripts have been updated to include the '-race' flag, enabling race detection during testing. This change helps prevent future race conditions by activating the Go race detector.

Signed-off-by: Alina Sudakov <asudakov@redhat.com>
This commit is contained in:
Alina Sudakov
2023-06-14 17:02:42 +03:00
parent 2b097c5a62
commit 48aa2f4eef
3 changed files with 13 additions and 5 deletions

View File

@ -15,7 +15,7 @@ source ./build_linux.sh
echo "Running tests"
function testrun {
sudo -E bash -c "umask 0; PATH=${GOPATH}/bin:$(pwd)/bin:${PATH} go test $@"
sudo -E bash -c "umask 0; PATH=${GOPATH}/bin:$(pwd)/bin:${PATH} go test -race $@"
}
COVERALLS=${COVERALLS:-""}
@ -31,7 +31,7 @@ PKG=${PKG:-$(go list ./... | xargs echo)}
i=0
for t in ${PKG}; do
if [ -n "${COVERALLS}" ]; then
COVERFLAGS="-covermode set -coverprofile ${i}.coverprofile"
COVERFLAGS="-covermode atomic -coverprofile ${i}.coverprofile"
fi
echo "${t}"
testrun "${COVERFLAGS:-""} ${t}"