Skip to content

Commit

Permalink
fix: make init-script.sh idempotent #1173 (#1194)
Browse files Browse the repository at this point in the history
Signed-off-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>
Signed-off-by: Hyperledger Bot <hyperledger-bot@hyperledger.org>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hyperledger Bot <hyperledger-bot@hyperledger.org>
  • Loading branch information
3 people committed Jun 21, 2024
1 parent 9050094 commit 1712062
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
28 changes: 24 additions & 4 deletions infrastructure/shared/postgres/init-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,31 @@ function create_user_and_database() {
local database=$1
local app_user=${database}-application-user
echo " Creating user and database '$database'"

# Check if user exists
user_exists=$(psql -U "$POSTGRES_USER" -tAc "SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = '$app_user'")
if [ "$user_exists" != "1" ]; then
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER "$app_user" WITH PASSWORD 'password';
EOSQL
else
echo " User '$app_user' already exists, skipping creation."
fi

# Check if database exists
db_exists=$(psql -U "$POSTGRES_USER" -tAc "SELECT 1 FROM pg_database WHERE datname = '$database'")
if [ "$db_exists" != "1" ]; then
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE DATABASE $database;
EOSQL
else
echo " Database '$database' already exists, skipping creation."
fi

# Grant privileges
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL
CREATE USER "$app_user" WITH PASSWORD 'password';
CREATE DATABASE $database;
\c $database
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO "$app_user";
\c $database
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO "$app_user";
EOSQL
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"webpack": "webpack"
},
"dependencies": {
"@hyperledger/identus-cloud-agent-client-ts": "^1.33.0",
"@hyperledger/identus-cloud-agent-client-ts": "^1.36.1",
"uuid": "^9.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
/*global __ENV*/
/* global __ENV */

import { Options } from "k6/options";
import { Options } from 'k6/options'

export const defaultOptions: Options = {
setupTimeout: '120s',
scenarios: {
smoke: {
// a simple test to ensure performance tests work and requests don't fail
executor: "shared-iterations",
executor: 'shared-iterations',
vus: 1,
iterations: 1,
tags: { scenario_label: __ENV.SCENARIO_LABEL || "defaultScenarioLabel" }, // add label for filtering in observability platform
},
tags: { scenario_label: __ENV.SCENARIO_LABEL || 'defaultScenarioLabel' } // add label for filtering in observability platform
}
},
thresholds: {
http_req_failed: [
// fail if any requests fail during smoke test
{
threshold: "rate==0",
abortOnFail: true,
},
threshold: 'rate==0',
abortOnFail: true
}
],
http_req_duration: [
{ threshold: "p(95)<5000", abortOnFail: false }, // 95% of requests should complete within 5 seconds, but don't fail tests
// TODO: this threshold is too high, it should be adjusted to the actual performance requirements to lower value
{ threshold: 'p(95)<11000', abortOnFail: false } // 95% of requests should complete within 5 seconds, but don't fail tests
],
checks: [{ threshold: "rate==1", abortOnFail: true }], // fail if any checks fail (the checks are defined in test code which is executed)

checks: [{ threshold: 'rate==1', abortOnFail: true }] // fail if any checks fail (the checks are defined in test code which is executed)
}
}
8 changes: 4 additions & 4 deletions tests/performance-tests/agent-performance-tests-k6/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -993,10 +993,10 @@
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==

"@hyperledger/identus-cloud-agent-client-ts@^1.33.0":
version "1.33.0"
resolved "https://npm.pkg.github.com/download/@hyperledger/identus-cloud-agent-client-ts/1.33.0/6f0f6f6a36ceb0790981ad3ba425db1d6b0103cd#6f0f6f6a36ceb0790981ad3ba425db1d6b0103cd"
integrity sha512-kVF/PnkV2T+G8TX0frHq7ENeK8RQCrif+HapyMj0CtWrfPmm5Qlh7XeFqY1H80HOMTanB9i15PwIabb717rkhQ==
"@hyperledger/identus-cloud-agent-client-ts@^1.36.1":
version "1.36.1"
resolved "https://npm.pkg.github.com/download/@hyperledger/identus-cloud-agent-client-ts/1.36.1/81ea78bfb60603eb293172b33994517db893faac#81ea78bfb60603eb293172b33994517db893faac"
integrity sha512-EXP4G+bKy1Jlf5w0mtoPULjQqVBjnG0L4iUVrmK96N4duJP1P7CrEL09qchk6axPXH67DmoLHISwQPTLN2FMVQ==
dependencies:
es6-promise "^4.2.4"
url-parse "^1.4.3"
Expand Down

0 comments on commit 1712062

Please sign in to comment.