-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathtest_default_scheduler.rb
More file actions
48 lines (37 loc) · 1.21 KB
/
test_default_scheduler.rb
File metadata and controls
48 lines (37 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
require 'test_helper'
require 'rx/subscriptions/helpers/await_helpers'
class TestDefaultScheduler < Minitest::Test
include AwaitHelpers
def setup
@scheduler = Rx::DefaultScheduler.instance
end
INTERVAL = 0.05
def test_schedule_with_state
state = []
task = ->(_, s) { s << 1 }
@scheduler.schedule_with_state(state, task)
await_array_length(state, 1, INTERVAL)
assert_equal([1], state)
end
def test_schedule_relative_with_state
state = []
task = ->(_, s) { s << 1 }
@scheduler.schedule_relative_with_state(state, 0.05, task)
await_array_length(state, 1, INTERVAL)
assert_equal([1], state)
end
def test_default_schedule_runs_in_its_own_thread
state = []
id = Thread.current.object_id
@scheduler.schedule -> { state << Thread.current.object_id }
await_array_length(state, 1, INTERVAL)
refute_equal([id], state)
end
def test_schedule_action_cancel
task = -> { flunk "This should not run." }
subscription = @scheduler.schedule_relative(0.05, task)
subscription.unsubscribe
sleep 0.1
end
end