120 lines
4.1 KiB
Terraform
120 lines
4.1 KiB
Terraform
// 2026-03-21 — stress.tf: все стресс-сервисы для комплексного тестирования.
|
|
// Два рантайма: nodejs20 (2), python3.11 (5).
|
|
// Все depends_on = [sless_job.postgres_table_init_job] — таблица должна существовать.
|
|
|
|
|
|
# ── Node.js 20 ────────────────────────────────────────────────────────────────
|
|
|
|
# 3 параллельных PG-запроса через Promise.all. Проверяет async/await + nodejs20.
|
|
resource "sless_service" "stress_js_async" {
|
|
name = "stress-js-async"
|
|
runtime = "nodejs20"
|
|
entrypoint = "stress_js_async.run"
|
|
memory_mb = 128
|
|
timeout_sec = 20
|
|
source_dir = "${path.module}/code/stress-js-async"
|
|
|
|
env_vars = {
|
|
PGHOST = local.pg_host
|
|
PGPORT = "5432"
|
|
PGDATABASE = local.pg_database
|
|
PGUSER = local.pg_username
|
|
PGPASSWORD = local.pg_password
|
|
PGSSLMODE = "require"
|
|
}
|
|
|
|
depends_on = [sless_job.postgres_table_init_job]
|
|
}
|
|
|
|
# TypeError через undefined.toUpperCase(). Без PG. Проверяет перехват JS-ошибок.
|
|
resource "sless_service" "stress_js_badenv" {
|
|
name = "stress-js-badenv"
|
|
runtime = "nodejs20"
|
|
entrypoint = "stress_js_badenv.run"
|
|
memory_mb = 128
|
|
timeout_sec = 10
|
|
source_dir = "${path.module}/code/stress-js-badenv"
|
|
|
|
depends_on = [sless_job.postgres_table_init_job]
|
|
}
|
|
|
|
# ── Python 3.11 ───────────────────────────────────────────────────────────────
|
|
|
|
# Спит N секунд. Без PG. Проверяет timeout и сосуществование долгих запросов.
|
|
resource "sless_service" "stress_slow" {
|
|
name = "stress-slow"
|
|
runtime = "python3.11"
|
|
entrypoint = "stress_slow.run"
|
|
memory_mb = 128
|
|
timeout_sec = 35
|
|
source_dir = "${path.module}/code/stress-slow"
|
|
|
|
depends_on = [sless_job.postgres_table_init_job]
|
|
}
|
|
|
|
# CPU-нагрузка: сумма квадратов N чисел. Без PG. Проверяет compute-bound задачи.
|
|
resource "sless_service" "stress_bigloop" {
|
|
name = "stress-bigloop"
|
|
runtime = "python3.11"
|
|
entrypoint = "stress_bigloop.run"
|
|
memory_mb = 256
|
|
timeout_sec = 60
|
|
source_dir = "${path.module}/code/stress-bigloop"
|
|
|
|
depends_on = [sless_job.postgres_table_init_job]
|
|
}
|
|
|
|
# ZeroDivisionError. Без PG. Проверяет перехват Python-исключений → HTTP 500.
|
|
resource "sless_service" "stress_divzero" {
|
|
name = "stress-divzero"
|
|
runtime = "python3.11"
|
|
entrypoint = "stress_divzero.run"
|
|
memory_mb = 128
|
|
timeout_sec = 10
|
|
source_dir = "${path.module}/code/stress-divzero"
|
|
|
|
depends_on = [sless_job.postgres_table_init_job]
|
|
}
|
|
|
|
# Параллельный INSERT в terraform_demo_table через psycopg2. Проверяет PG-write.
|
|
resource "sless_service" "stress_writer" {
|
|
name = "stress-writer"
|
|
runtime = "python3.11"
|
|
entrypoint = "stress_writer.run"
|
|
memory_mb = 128
|
|
timeout_sec = 60
|
|
source_dir = "${path.module}/code/stress-writer"
|
|
|
|
env_vars = {
|
|
PGHOST = local.pg_host
|
|
PGPORT = "5432"
|
|
PGDATABASE = local.pg_database
|
|
PGUSER = local.pg_username
|
|
PGPASSWORD = local.pg_password
|
|
PGSSLMODE = "require"
|
|
}
|
|
|
|
depends_on = [sless_job.postgres_table_init_job]
|
|
}
|
|
|
|
# Агрегированная статистика terraform_demo_table (COUNT/MIN/MAX). Для мониторинга.
|
|
resource "sless_service" "pg_stats" {
|
|
name = "pg-stats"
|
|
runtime = "python3.11"
|
|
entrypoint = "pg_stats.get_stats"
|
|
memory_mb = 128
|
|
timeout_sec = 15
|
|
source_dir = "${path.module}/code/pg-stats"
|
|
|
|
env_vars = {
|
|
PGHOST = local.pg_host
|
|
PGPORT = "5432"
|
|
PGDATABASE = local.pg_database
|
|
PGUSER = local.pg_username
|
|
PGPASSWORD = local.pg_password
|
|
PGSSLMODE = "require"
|
|
}
|
|
|
|
depends_on = [sless_job.postgres_table_init_job]
|
|
}
|