From a00823544ec7b3ff2788d02f704900439c0eeeef Mon Sep 17 00:00:00 2001 From: realaravinth Date: Mon, 9 May 2022 11:27:06 +0530 Subject: [PATCH] hotfix: run tests one at a time SUMMARY The test suite messy and inefficient in every imaginable way. It creates a DB connection pool for every unit test and Postgres failed with the following error: code: "53300", message: "sorry, too many clients already This hotfix runs tests via scripts/tests.sh, which executes one test at a time. Ideally, the connection pool must be shared across the whole test suite but this requires a major refactor of the test suite and even the app code. A refactor towards this is in progress in the `db-abstract` branch, which I hope to complete within this week. fixes #22 --- Makefile | 3 ++- scripts/tests.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 scripts/tests.sh diff --git a/Makefile b/Makefile index 418a555b..c51a9181 100644 --- a/Makefile +++ b/Makefile @@ -75,7 +75,8 @@ run: frontend ## Run app in debug mode cargo run test: frontend-test frontend ## Run all available tests - cargo test --all-features --no-fail-fast + ./scripts/tests.sh +# cargo test --all-features --no-fail-fast xml-test-coverage: migrate ## Generate code coverage report in XML format cargo tarpaulin -t 1200 --out Xml diff --git a/scripts/tests.sh b/scripts/tests.sh new file mode 100755 index 00000000..3b1e608f --- /dev/null +++ b/scripts/tests.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# hotfix for DB error: too many connections, can't create new client +# +# I tried running cargo test with the `--jobs` parameter set to 1 but that didn't +# seem to solve the issue. This scr will run the whole test suite but one test at a time. + + +for ut in \ + api::v1::meta::tests::build_details_works \ + api::v1::mcaptcha::easy::tests::isoloated_test::easy_configuration_works \ + api::v1::meta::tests::health_works \ + api::v1::pow::tests::scope_pow_works \ + api::v1::account::test::uname_email_exists_works \ + api::v1::mcaptcha::easy::tests::easy_works \ + api::v1::pow::get_config::tests::get_pow_config_works \ + api::v1::pow::verify_pow::tests::verify_pow_works \ + api::v1::mcaptcha::update::tests::update_and_get_mcaptcha_works \ + date::tests::print_date_test \ + api::v1::tests::auth::serverside_password_validation_works \ + docs::tests::docs_works \ + email::verification::tests::email_verification_works \ + errors::tests::error_works \ + pages::errors::tests::error_pages_work \ + pages::panel::notifications::tests::print_date_test \ + api::v1::notifications::add::tests::notification_works \ + api::v1::account::test::username_update_works \ + pages::panel::sitekey::tests::get_sitekey_routes_work \ + api::v1::mcaptcha::test::level_routes_work \ + pages::routes::tests::sitemap_works \ + api::v1::tests::protected::protected_routes_work \ + pages::tests::public_pages_tempaltes_work \ + static_assets::filemap::tests::filemap_works \ + static_assets::static_files::tests::favicons_work \ + static_assets::static_files::tests::static_assets_work \ + pages::tests::protected_pages_templates_work \ + test::version_source_code_url_works \ + widget::test::captcha_widget_route_works \ + pages::panel::sitekey::edit::test::edit_sitekey_work \ + api::v1::pow::verify_token::tests::validate_captcha_token_works \ + api::v1::notifications::get::tests::notification_get_works \ + api::v1::notifications::mark_read::tests::notification_mark_read_works \ + api::v1::account::test::email_udpate_password_validation_del_userworks \ + api::v1::tests::auth::auth_works \ + pages::panel::sitekey::view::test::view_sitekey_work \ + api::v1::account::password::tests::update_password_works \ + pages::panel::sitekey::list::test::list_sitekeys_work +do + cargo test -- $ut +done