|
| 1 | +#!/usr/bin/env bats |
| 2 | +# Example bats test file for Dynflow |
| 3 | + |
| 4 | +# Load helper functions |
| 5 | +load helpers/containers |
| 6 | +load helpers/common |
| 7 | + |
| 8 | +# Setup runs before each test |
| 9 | +setup() { |
| 10 | + # Setup environment variables |
| 11 | + setup_test_env |
| 12 | + |
| 13 | + # Ensure containers are running |
| 14 | + if ! is_postgres_running; then |
| 15 | + start_postgres |
| 16 | + fi |
| 17 | + if ! is_redis_running; then |
| 18 | + start_redis |
| 19 | + fi |
| 20 | +} |
| 21 | + |
| 22 | +# Teardown runs after each test |
| 23 | +teardown() { |
| 24 | + ( |
| 25 | + cd "$TEST_PIDDIR" |
| 26 | + for pidfile in $(ls -1 .); do |
| 27 | + kill -15 $(cat "$pidfile") |
| 28 | + done |
| 29 | + ) |
| 30 | + rm -rf "$TEST_TMPDIR" |
| 31 | +} |
| 32 | + |
| 33 | +@test "only one orchestrator can be active at a time" { |
| 34 | + cd "$(get_project_root)" |
| 35 | + |
| 36 | + run_background 'o1' bundle exec sidekiq -r ./examples/remote_executor.rb -q dynflow_orchestrator |
| 37 | + wait_for 30 1 grep 'dynflow: Acquired orchestrator lock, entering active mode.' "${TEST_TMPDIR}/o1.log" |
| 38 | + |
| 39 | + run_background 'o2' bundle exec sidekiq -r ./examples/remote_executor.rb -q dynflow_orchestrator |
| 40 | + wait_for 30 1 grep 'dynflow: Orchestrator lock already taken, entering passive mode.' "${TEST_TMPDIR}/o2.log" |
| 41 | +} |
| 42 | + |
| 43 | +@test "multiple orchestrators can be active with multiple redis dbs" { |
| 44 | + cd "$(get_project_root)" |
| 45 | + |
| 46 | + run_background 'o1' bundle exec sidekiq -r ./examples/remote_executor.rb -q dynflow_orchestrator |
| 47 | + wait_for 30 1 grep 'dynflow: Acquired orchestrator lock, entering active mode.' "${TEST_TMPDIR}/o1.log" |
| 48 | + |
| 49 | + export REDIS_URL=${REDIS_URL%/0}/1 |
| 50 | + run_background 'o2' bundle exec sidekiq -r ./examples/remote_executor.rb -q dynflow_orchestrator |
| 51 | + wait_for 30 1 grep 'dynflow: Acquired orchestrator lock, entering active mode.' "${TEST_TMPDIR}/o1.log" |
| 52 | +} |
| 53 | + |
| 54 | +@test "orchestrators do fail over" { |
| 55 | + cd "$(get_project_root)" |
| 56 | + |
| 57 | + run_background 'o1' bundle exec sidekiq -r ./examples/remote_executor.rb -q dynflow_orchestrator |
| 58 | + wait_for 30 1 grep 'dynflow: Acquired orchestrator lock, entering active mode.' "${TEST_TMPDIR}/o1.log" |
| 59 | + |
| 60 | + run_background 'o2' bundle exec sidekiq -r ./examples/remote_executor.rb -q dynflow_orchestrator |
| 61 | + wait_for 30 1 grep 'dynflow: Orchestrator lock already taken, entering passive mode.' "${TEST_TMPDIR}/o2.log" |
| 62 | + |
| 63 | + kill -15 "$(cat "$TEST_PIDDIR/o1.pid")" |
| 64 | + wait_for 120 1 grep 'dynflow: Acquired orchestrator lock, entering active mode.' "${TEST_TMPDIR}/o2.log" |
| 65 | +} |
0 commit comments