Skip to content

Commit 753b810

Browse files
committed
Add sidekiq-orchestrator bats tests
1 parent 8db2341 commit 753b810

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

examples/example_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def persistence_adapter
4848
end
4949

5050
def logger_adapter
51-
Dynflow::LoggerAdapters::Simple.new $stderr, Logger::FATAL
51+
Dynflow::LoggerAdapters::Simple.new $stderr, Logger::INFO
5252
end
5353

5454
def run_web_console(world = ExampleHelper.world)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)