Skip to content

Commit

Permalink
fix: [torrust#342] broken E2E tests after renaming Category::category…
Browse files Browse the repository at this point in the history
…_id field

Some E2E tests were failing becuase a category field in a response was
renamed. I have reestablished the old name `category_id`.
  • Loading branch information
josecelano committed Nov 14, 2023
1 parent e78607d commit f8aa238
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 32 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ jobs:
name: Make Build Clean
run: cargo clean

- id: test
name: Run Integration Tests
run: ./contrib/dev-tools/container/e2e/run-e2e-tests.sh
- id: test-sqlite
name: Run Integration Tests (SQLite)
run: ./contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh

- id: test-mysql
name: Run Integration Tests (MySQL)
run: ./contrib/dev-tools/container/e2e/mysql/run-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TORRUST_TRACKER_USER_UID=$CURRENT_USER_ID
export TORRUST_IDX_BACK_USER_UID
export TORRUST_TRACKER_USER_UID

# todo: remove duplicate funtion
wait_for_container_to_be_healthy() {
local container_name="$1"
local max_retries="$2"
Expand Down Expand Up @@ -42,28 +43,6 @@ cargo install imdl || exit 1
# Install app (no docker) that will run the test suite against the E2E testing
# environment (in docker).
cp .env.local .env || exit 1
./contrib/dev-tools/init/install-local.sh || exit 1

# TEST USING SQLITE
echo "Running E2E tests using SQLite ..."

# Start E2E testing environment
./contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh || exit 1

wait_for_container_to_be_healthy torrust-mysql-1 10 3
# todo: implement healthchecks for tracker and index and wait until they are healthy
#wait_for_container torrust-tracker-1 10 3
#wait_for_container torrust-idx-back-1 10 3
sleep 20s

# Just to make sure that everything is up and running
docker ps

# Run E2E tests with shared app instance
TORRUST_INDEX_E2E_SHARED=true TORRUST_INDEX_E2E_PATH_CONFIG="./share/default/config/index.container.sqlite3.toml" cargo test || exit 1

# Stop E2E testing environment
./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh || exit 1

# TEST USING MYSQL
echo "Running E2E tests using MySQL ..."
Expand Down
13 changes: 13 additions & 0 deletions contrib/dev-tools/container/e2e/sqlite/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# This script is only intended to be used for local development or testing environments.

# Generate storage directory if it does not exist
mkdir -p ./storage/index/lib/database

# Generate the sqlite database if it does not exist
if ! [ -f "./storage/index/lib/database/sqlite3.db" ]; then
# todo: it should get the path from tracker.toml and only do it when we use sqlite
sqlite3 ./storage/index/lib/database/sqlite3.db "VACUUM;"
fi

67 changes: 67 additions & 0 deletions contrib/dev-tools/container/e2e/sqlite/run-e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

CURRENT_USER_NAME=$(whoami)
CURRENT_USER_ID=$(id -u)
echo "User name: $CURRENT_USER_NAME"
echo "User id: $CURRENT_USER_ID"

TORRUST_IDX_BACK_USER_UID=$CURRENT_USER_ID
TORRUST_TRACKER_USER_UID=$CURRENT_USER_ID
export TORRUST_IDX_BACK_USER_UID
export TORRUST_TRACKER_USER_UID

# todo: remove duplicate funtion
wait_for_container_to_be_healthy() {
local container_name="$1"
local max_retries="$2"
local retry_interval="$3"
local retry_count=0

while [ $retry_count -lt "$max_retries" ]; do
container_health="$(docker inspect --format='{{json .State.Health}}' "$container_name")"
if [ "$container_health" != "{}" ]; then
container_status="$(echo "$container_health" | jq -r '.Status')"
if [ "$container_status" == "healthy" ]; then
echo "Container $container_name is healthy"
return 0
fi
fi

retry_count=$((retry_count + 1))
echo "Waiting for container $container_name to become healthy (attempt $retry_count of $max_retries)..."
sleep "$retry_interval"
done

echo "Timeout reached, container $container_name is not healthy"
return 1
}

# Install tool to create torrent files.
# It's needed by some tests to generate and parse test torrent files.
cargo install imdl || exit 1

# Install app (no docker) that will run the test suite against the E2E testing
# environment (in docker).
cp .env.local .env || exit 1
./contrib/dev-tools/container/e2e/sqlite/install.sh || exit 1

# TEST USING SQLITE
echo "Running E2E tests using SQLite ..."

# Start E2E testing environment
./contrib/dev-tools/container/e2e/sqlite/e2e-env-up.sh || exit 1

wait_for_container_to_be_healthy torrust-mysql-1 10 3
# todo: implement healthchecks for tracker and index and wait until they are healthy
#wait_for_container torrust-tracker-1 10 3
#wait_for_container torrust-idx-back-1 10 3
sleep 20s

# Just to make sure that everything is up and running
docker ps

# Run E2E tests with shared app instance
TORRUST_INDEX_E2E_SHARED=true TORRUST_INDEX_E2E_PATH_CONFIG="./share/default/config/index.container.sqlite3.toml" cargo test || exit 1

# Stop E2E testing environment
./contrib/dev-tools/container/e2e/sqlite/e2e-env-down.sh || exit 1
4 changes: 0 additions & 4 deletions contrib/dev-tools/container/install.sh

This file was deleted.

1 change: 1 addition & 0 deletions contrib/dev-tools/init/install-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ if ! [ -f "./storage/index/lib/database/sqlite3.db" ]; then
# todo: it should get the path from tracker.toml and only do it when we use sqlite
sqlite3 ./storage/index/lib/database/sqlite3.db "VACUUM;"
fi

5 changes: 4 additions & 1 deletion tests/common/contexts/torrent/asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ pub fn assert_expected_torrent_details(torrent: &TorrentDetails, expected_torren
("info_hash", torrent.info_hash == expected_torrent.info_hash),
("title", torrent.title == expected_torrent.title),
("description", torrent.description == expected_torrent.description),
("category.category_id", torrent.category.id == expected_torrent.category.id),
(
"category.category_id",
torrent.category.category_id == expected_torrent.category.category_id,
),
("category.name", torrent.category.name == expected_torrent.category.name),
("file_size", torrent.file_size == expected_torrent.file_size),
("seeders", torrent.seeders == expected_torrent.seeders),
Expand Down
2 changes: 1 addition & 1 deletion tests/common/contexts/torrent/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct TorrentDetails {

#[derive(Deserialize, PartialEq, Debug)]
pub struct Category {
pub id: CategoryId,
pub category_id: CategoryId,
pub name: String,
pub num_torrents: u64,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/web/api/v1/contexts/torrent/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ mod for_guests {
title: test_torrent.index_info.title.clone(),
description: test_torrent.index_info.description,
category: Category {
id: software_predefined_category_id(),
category_id: software_predefined_category_id(),
name: test_torrent.index_info.category,
num_torrents: 19, // Ignored in assertion
},
Expand Down

0 comments on commit f8aa238

Please sign in to comment.