test/caddy_test.rb in caddy-1.0.0 vs test/caddy_test.rb in caddy-1.0.1
- old
+ new
@@ -4,10 +4,11 @@
def setup
Caddy.stop
Caddy.refresher = -> {}
Caddy.refresh_interval = 30
Caddy.error_handler = nil
+ sleep(0.05)
end
def test_basic_lookup
Caddy.refresher = -> { {foo: "bar"} }
Caddy.start
@@ -27,16 +28,31 @@
sleep(3)
assert_operator Caddy[:baz], :>=, 2
end
+ def test_stale_value
+ ran_once = false
+ Caddy.refresher = lambda do
+ raise "boom" if ran_once
+ ran_once = true
+ {baz: "bizz"}
+ end
+ Caddy.refresh_interval = 2
+ Caddy.start
+ sleep(3)
+
+ assert_equal "bizz", Caddy[:baz]
+ end
+
def test_restart
Caddy.refresher = -> { {foo: "baz"} }
Caddy.start
sleep(0.1)
Caddy.stop
Caddy.restart
+ sleep(0.1)
assert_equal "baz", Caddy[:foo]
end
def test_error_handling
@@ -51,26 +67,45 @@
def test_incepted_error_handling
Caddy.refresher = -> { raise "boom" }
Caddy.error_handler = -> (_) { raise "boomboom" }
Caddy.start
+ sleep(0.1)
end
def test_bad_error_handler
Caddy.refresher = -> { raise "boom" }
Caddy.error_handler = "no"
Caddy.start
+ sleep(0.1)
end
def test_timeout
- Caddy.refresher = -> { sleep 5 }
- Caddy.refresh_interval = 1
+ timed_out = nil
+ Caddy.refresher = -> { sleep 1 }
+ Caddy.error_handler = -> (ex) { timed_out = ex }
+ Caddy.refresh_interval = 0.5
Caddy.start
+ sleep(2)
+
+ assert_kind_of Concurrent::TimeoutError, timed_out
+ Caddy.stop
+ sleep(2)
end
+ def test_no_handler_timeout
+ Caddy.refresher = -> { sleep 1 }
+ Caddy.refresh_interval = 0.5
+ Caddy.start
+ sleep(2)
+ Caddy.stop
+ sleep(2)
+ end
+
def test_no_handler
Caddy.refresher = -> { raise "boom" }
Caddy.start
+ sleep(0.1)
end
def test_requires_refesher
Caddy.refresher = nil