Skip to content

Commit

Permalink
Deflake skylark_repository_test
Browse files Browse the repository at this point in the history
Use -p when mkdir, create the server directory in the
temporary directory and ensure we delete the server directory
on the tear_down.

--
MOS_MIGRATED_REVID=117728350
  • Loading branch information
damienmg committed Mar 21, 2016
1 parent 1fe0e97 commit fbcfd50
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/test/shell/bazel/skylark_repository_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,16 @@ EOF

function test_skylark_repository_download() {
# Prepare HTTP server with Python
mkdir "server_dir"
echo "This is one file" > server_dir/download_no_sha256.txt
echo "This is another file" > server_dir/download_with_sha256.txt
file_sha256="$(sha256sum server_dir/download_with_sha256.txt | head -c 64)"
local server_dir="${TEST_TMPDIR}/server_dir"
mkdir -p "${server_dir}"
local download_with_sha256="${server_dir}/download_with_sha256.txt"
local download_no_sha256="${server_dir}/download_no_sha256.txt"
echo "This is one file" > "${download_no_sha256}"
echo "This is another file" > "${download_with_sha256}"
file_sha256="$(sha256sum "${download_with_sha256}" | head -c 64)"

# Start HTTP server with Python
startup_server "server_dir"
startup_server "${server_dir}"

setup_skylark_repository
# Our custom repository rule
Expand All @@ -465,27 +468,32 @@ EOF
test -e "${output_base}/external/foo/download_with_sha256.txt" \
|| fail "download_with_sha256.txt is not downloaded"
# Test download
diff "${output_base}/external/foo/download_no_sha256.txt" server_dir/download_no_sha256.txt >/dev/null \
diff "${output_base}/external/foo/download_no_sha256.txt" \
"${download_no_sha256}" >/dev/null \
|| fail "download_no_sha256.txt is not downloaded successfully"
diff "${output_base}/external/foo/download_with_sha256.txt" server_dir/download_with_sha256.txt >/dev/null \
diff "${output_base}/external/foo/download_with_sha256.txt" \
"${download_with_sha256}" >/dev/null \
|| fail "download_with_sha256.txt is not downloaded successfully"

rm -rf "server_dir"
}

function test_skylark_repository_download_and_extract() {
# Prepare HTTP server with Python
mkdir "server_dir"
local server_dir="${TEST_TMPDIR}/server_dir"
mkdir -p "${server_dir}"
local file_prefix="${server_dir}/download_and_extract"

pushd ${TEST_TMPDIR}
echo "This is one file" > server_dir/download_and_extract1.txt
echo "This is another file" > server_dir/download_and_extract2.txt
echo "This is a third file" > server_dir/download_and_extract3.txt
tar -zcvf server_dir/download_and_extract1.tar.gz server_dir/download_and_extract1.txt
zip server_dir/download_and_extract2.zip server_dir/download_and_extract2.txt
zip server_dir/download_and_extract3.zip server_dir/download_and_extract3.txt
file_sha256="$(sha256sum server_dir/download_and_extract3.zip | head -c 64)"
popd

# Start HTTP server with Python
startup_server "server_dir"
startup_server "${server_dir}"

setup_skylark_repository
# Our custom repository rule
Expand Down Expand Up @@ -515,16 +523,14 @@ EOF
&& fail "temp file is not deleted successfully" || true
# Test download_and_extract
diff "${output_base}/external/foo/server_dir/download_and_extract1.txt" \
server_dir/download_and_extract1.txt >/dev/null \
"${file_prefix}1.txt" >/dev/null \
|| fail "download_and_extract1.tar.gz is not extracted successfully"
diff "${output_base}/external/foo/server_dir/download_and_extract2.txt" \
server_dir/download_and_extract2.txt >/dev/null \
"${file_prefix}2.txt" >/dev/null \
|| fail "download_and_extract2.zip is not extracted successfully"
diff "${output_base}/external/foo/server_dir/download_and_extract3.txt" \
server_dir/download_and_extract3.txt >/dev/null \
"${file_prefix}3.txt" >/dev/null \
|| fail "download_and_extract3.zip is not extracted successfully"

rm -rf "server_dir"
}

# Test native.bazel_version
Expand Down Expand Up @@ -571,6 +577,9 @@ EOF

function tear_down() {
shutdown_server
if [ -d "${TEST_TMPDIR}/server_dir" ]; then
rm -fr "${TEST_TMPDIR}/server_dir"
fi
true
}

Expand Down

0 comments on commit fbcfd50

Please sign in to comment.