Skip to content

Commit

Permalink
Merge pull request #3 from ba-st/tests_for_migration_failures
Browse files Browse the repository at this point in the history
Tests for migration failures
  • Loading branch information
gcotelli authored Dec 12, 2023
2 parents 4857767 + f5d18f8 commit 92c4213
Show file tree
Hide file tree
Showing 6 changed files with 307 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .docker/failed-migration-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env bash

readonly ANSI_BOLD="\\033[1m"
readonly ANSI_RED="\\033[31m"
readonly ANSI_GREEN="\\033[32m"
readonly ANSI_BLUE="\\033[34m"
readonly ANSI_RESET="\\033[0m"

function print_info() {
if [ -t 1 ]; then
printf "${ANSI_BOLD}${ANSI_BLUE}%s${ANSI_RESET}\\n" "$1"
else
echo "$1"
fi
}

function print_success() {
if [ -t 1 ]; then
printf "${ANSI_BOLD}${ANSI_GREEN}%s${ANSI_RESET}\\n" "$1"
else
echo "$1"
fi
}

function print_error() {
if [ -t 1 ]; then
printf "${ANSI_BOLD}${ANSI_RED}%s${ANSI_RESET}\\n" "$1" 1>&2
else
echo "$1" 1>&2
fi
}

function executeInDocker() {
docker exec gs64-migration "$@"
}

function assertMigrationLogIncludes() {
executeInDocker ./scripts/assertMigrationLogIncludesMessage.sh "$1"
}

function assertConsistencyLogIncludes() {
executeInDocker ./scripts/assertConsistencyLogIncludesMessage.sh "$1"
}

set -e

print_info "Starting stone"

docker pull ghcr.io/ba-st/gs64-rowan:v3.7.0

docker run --rm --detach --name gs64-migration \
-e TZ="America/Argentina/Buenos_Aires" \
--cap-add=SYS_RESOURCE \
--volume="$PWD":/opt/gemstone/projects/GemStone-64-Migration-Tools:ro \
--volume="$PWD"/.docker/scripts:/opt/gemstone/scripts:ro \
ghcr.io/ba-st/gs64-rowan:v3.7.0

sleep 1

print_info "Loading Migration Tools"

executeInDocker ./load-rowan-project.sh \
GemStone-64-Migration-Tools \
GemStone-64-Migration-Tools-Deployment

print_info "Loading Migration Examples base version"

executeInDocker git clone -b base \
https://github.com/ba-st/GS64-Migration-Examples.git \
/opt/gemstone/projects/GS64-Migration-Examples

executeInDocker ./load-rowan-project.sh \
GS64-Migration-Examples \
GS64-Migration-Examples

print_info "Configuring instance migrator"

executeInDocker ./scripts/installInstanceMigrator.sh

print_info "Loading Migration Examples failed_migration version"

docker exec --workdir /opt/gemstone/projects/GS64-Migration-Examples \
gs64-migration \
git checkout failed_migration

executeInDocker ./load-rowan-project.sh \
GS64-Migration-Examples \
GS64-Migration

print_info "Checking migration result"

executeInDocker ./scripts/checkMigrationFailed.sh
assertMigrationLogIncludes "Migration finished with errors."
assertMigrationLogIncludes "2 instances raised a MigrationError"
assertMigrationLogIncludes "There are 1 classes with new versions, but no migration command applicable. Review your migration scripts."
assertMigrationLogIncludes "ClassWithInstanceVariableToBeAdded"
assertMigrationLogIncludes "There are 1 removed classes but having live instances in the repository."
assertMigrationLogIncludes "ClassToBeRenamed"
print_success " - Migration failed as expected [OK]"

print_info "Running consistency checks"

executeInDocker ./scripts/runFailingConsistencyChecks.sh
assertConsistencyLogIncludes "1 classes have more than one version"
assertConsistencyLogIncludes "ClassWithInstanceVariableToBeAdded"
assertConsistencyLogIncludes "3 classes are unpublished"
assertConsistencyLogIncludes "ClassWithInstanceVariableToBeAdded"
assertConsistencyLogIncludes "ClassToBeRenamed"
assertConsistencyLogIncludes "ClassToChangeSuperclassToStatefull"
print_success " - Consistency checks failed as expected [OK]"

print_info "Stopping stone"
docker stop gs64-migration
98 changes: 98 additions & 0 deletions .docker/failed-reporting-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash

readonly ANSI_BOLD="\\033[1m"
readonly ANSI_RED="\\033[31m"
readonly ANSI_GREEN="\\033[32m"
readonly ANSI_BLUE="\\033[34m"
readonly ANSI_RESET="\\033[0m"

function print_info() {
if [ -t 1 ]; then
printf "${ANSI_BOLD}${ANSI_BLUE}%s${ANSI_RESET}\\n" "$1"
else
echo "$1"
fi
}

function print_success() {
if [ -t 1 ]; then
printf "${ANSI_BOLD}${ANSI_GREEN}%s${ANSI_RESET}\\n" "$1"
else
echo "$1"
fi
}

function print_error() {
if [ -t 1 ]; then
printf "${ANSI_BOLD}${ANSI_RED}%s${ANSI_RESET}\\n" "$1" 1>&2
else
echo "$1" 1>&2
fi
}

function executeInDocker() {
docker exec gs64-migration "$@"
}

function assertMigrationLogIncludes() {
docker exec gs64-migration ./scripts/assertMigrationLogIncludesMessage.sh "$1"
}

set -e

print_info "Starting stone"

docker pull ghcr.io/ba-st/gs64-rowan:v3.7.0

docker run --rm --detach --name gs64-migration \
-e TZ="America/Argentina/Buenos_Aires" \
--cap-add=SYS_RESOURCE \
--volume="$PWD":/opt/gemstone/projects/GemStone-64-Migration-Tools:ro \
--volume="$PWD"/.docker/scripts:/opt/gemstone/scripts:ro \
ghcr.io/ba-st/gs64-rowan:v3.7.0

sleep 1

print_info "Loading Migration Tools"

executeInDocker ./load-rowan-project.sh \
GemStone-64-Migration-Tools \
GemStone-64-Migration-Tools-Deployment

print_info "Loading Migration Examples base version"

executeInDocker git clone -b base \
https://github.com/ba-st/GS64-Migration-Examples.git \
/opt/gemstone/projects/GS64-Migration-Examples

executeInDocker ./load-rowan-project.sh \
GS64-Migration-Examples \
GS64-Migration-Examples

print_info "Configuring instance migration reporter"

executeInDocker ./scripts/installInstanceMigrationReporter.sh

print_info "Loading Migration Examples failed_migration version"

docker exec --workdir /opt/gemstone/projects/GS64-Migration-Examples \
gs64-migration \
git checkout failed_migration

executeInDocker ./load-rowan-project.sh \
GS64-Migration-Examples \
GS64-Migration-Examples

print_info "Running Assertions"
assertMigrationLogIncludes "2 classes have new versions"
assertMigrationLogIncludes "ClassToChangeSuperclassToStatefull"
assertMigrationLogIncludes "ClassWithInstanceVariableToBeAdded"
print_success " - Number of classes with new versions [OK]"

assertMigrationLogIncludes "2 classes were removed"
assertMigrationLogIncludes "ClassToBeRenamed"
assertMigrationLogIncludes "ClassToRemoveWithoutInstances"
print_success " - Number of removed classes [OK]"

print_info "Stopping stone"
docker stop gs64-migration
24 changes: 24 additions & 0 deletions .docker/scripts/assertConsistencyLogIncludesMessage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
readonly ANSI_BOLD="\\033[1m"
readonly ANSI_RED="\\033[31m"
readonly ANSI_RESET="\\033[0m"

function print_error() {
if [ -t 1 ]; then
printf "${ANSI_BOLD}${ANSI_RED}%s${ANSI_RESET}\\n" "$1" 1>&2
else
echo "$1" 1>&2
fi
}

message=$1
output=/opt/gemstone/logs/consistency-checks.log

if [ "$(grep -c "$message" "$output")" -eq 0 ]; then
print_error "Expected output: '$message' not found in the consistency checks log"
print_error "Output contents:"
cat "$output"
exit 1
fi

exit 0
55 changes: 55 additions & 0 deletions .docker/scripts/checkMigrationFailed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

readonly ANSI_BOLD="\\033[1m"
readonly ANSI_RED="\\033[31m"
readonly ANSI_GREEN="\\033[32m"
readonly ANSI_BLUE="\\033[34m"
readonly ANSI_RESET="\\033[0m"

function print_error() {
if [ -t 1 ]; then
printf "${ANSI_BOLD}${ANSI_RED}%s${ANSI_RESET}\\n" "$1" 1>&2
else
echo "$1" 1>&2
fi
}

function print_success() {
if [ -t 1 ]; then
printf "${ANSI_BOLD}${ANSI_GREEN}%s${ANSI_RESET}\\n" "$1"
else
echo "$1"
fi
}

function print_info() {
if [ -t 1 ]; then
printf "${ANSI_BOLD}${ANSI_BLUE}%s${ANSI_RESET}\\n" "$1"
else
echo "$1"
fi
}

if topaz -i -q <<EOF
set gemstone gs64stone user SystemUser pass ${GS64_SYSTEM_USER_PASSWORD}
iferror exit 1
login
expectvalue false
run
Rowan platform instanceMigrator migrationWasSuccessful
%
logout
exit 0
EOF
then
print_success "Migration failed as expected"
print_info "Details of the process:\n"
cat /opt/gemstone/logs/loading-rowan-projects.log
exit 0
else
print_error "##########################################"
print_error " Migration succeded when expected to fail"
print_error "##########################################"
cat /opt/gemstone/logs/loading-rowan-projects.log
exit 1
fi
13 changes: 13 additions & 0 deletions .docker/scripts/runFailingConsistencyChecks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

topaz -i -q <<EOF > "${GEMSTONE_LOG_DIR}/consistency-checks.log"
set gemstone gs64stone user SystemUser pass ${GS64_SYSTEM_USER_PASSWORD}
iferror exit 1
login
expectvalue false
run
Rowan platform instanceMigrator runConsistencyChecks
%
logout
exit 0
EOF
4 changes: 4 additions & 0 deletions .github/workflows/migration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ jobs:
run: ./.docker/reporting-tests.sh
- name: Run instance migration tests using Docker
run: ./.docker/migration-tests.sh
- name: Run failed instance migration reporting tests using Docker
run: ./.docker/failed-reporting-tests.sh
- name: Run failed instance migration tests using Docker
run: ./.docker/failed-migration-tests.sh

0 comments on commit 92c4213

Please sign in to comment.