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(frontend-canister): Add retries to the curl invocations #3068

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 51 additions & 0 deletions e2e/tests-dfx/upgrade_assets_canister.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bats

load ../utils/_
load ../utils/releases

setup() {
standard_setup

dfx_new
}

teardown() {
dfx_stop

standard_teardown
}

# The e2e matrix should ensure that this test is not run on ic-ref, as the Wasm does
# heavy computation
@test "asset canister can be upgraded from the latest release version when storing a lot of data" {
# As a starting point for the load, we looked at OpenChat's usage.
# As of 2023-02-10, they had 40MB of assets spread over 135 files.
# We'll use a bigger example (~3x in number of files, ~20x in total size) to add a safety margin.
local -r total_files=400
local file_size
if [ "$(uname)" == "Darwin" ]; then
file_size="2m"
else
file_size="2M"
fi

local -r canister_name=e2e_project_frontend

local -r asset_dir="src/${canister_name}/assets"
for a in $(seq 1 $total_files); do
dd if=/dev/urandom of="${asset_dir}/large-asset-${a}.bin" bs="$file_size" count=1 1>/dev/null
done

dfx_start
dfx canister create --all
dfx build

# Install the canister using the Wasm from the latest release
local -r release_asset_wasm_dir=$(mktemp -d)
get_from_latest_release_tarball src/distributed/assetstorage.wasm.gz "$release_asset_wasm_dir"
export DFX_ASSETS_WASM="${release_asset_wasm_dir}/assetstorage.wasm.gz"
assert_command dfx canister install $canister_name

use_default_asset_wasm
assert_command dfx deploy $canister_name --upgrade-unchanged
}
26 changes: 26 additions & 0 deletions e2e/utils/releases.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Print the latest dfx version available on GitHub releases
get_latest_dfx_version() {
latest_version=$(curl -sL --retry 5 --retry-all-errors "https://api.github.com/repos/dfinity/sdk/releases/latest" | jq -r ".tag_name")
echo "$latest_version"
}

# Extract a particular file from the latest release tarball, and save it to the specified destination
# Usage: get_from_latest_release_tarball <file_path> <destination>
get_from_latest_release_tarball() {
local -r file_path=$1
local -r destination=$2
local -r tarball_url=$(curl -sL --retry 5 --retry-all-errors "https://api.github.com/repos/dfinity/sdk/releases/latest" | jq -r ".tarball_url")

local -r temp_dir=$(mktemp -d)
curl -sL --retry 5 --retry-all-errors "$tarball_url" -o "${temp_dir}/release.tar.gz" || (echo "It's really curl that failed" && return 1)

if [ "$(uname)" == "Darwin" ]; then
tar -xzf "$temp_dir/release.tar.gz" -C "$temp_dir" "*/$file_path"
elif [ "$(uname)" == "Linux" ]; then
tar -xzf "$temp_dir/release.tar.gz" -C "$temp_dir" --wildcards "*/$file_path"
fi

local -r file_name=$(basename "$file_path")
local -r extracted_file=$(find "$temp_dir" -type f -name "$file_name")
mv "$extracted_file" "$destination"
}
1 change: 1 addition & 0 deletions scripts/workflows/e2e-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_scripts(prefix):
{"backend": "ic-ref", "test": "dfx/new"},
{"backend": "ic-ref", "test": "dfx/print"},
{"backend": "ic-ref", "test": "dfx/signals"},
{"backend": "ic-ref", "test": "dfx/upgrade_assets_canister"},
],
}

Expand Down