|
31 | 31 | expect(clock.total).to be_within(2 * Sus::Fixtures::Time::QUANTUM).of(0.02) |
32 | 32 | end |
33 | 33 |
|
| 34 | + with "#start" do |
| 35 | + it "handles multiple start/stop cycles" do |
| 36 | + 3.times do |
| 37 | + clock.start! |
| 38 | + # Calling start! again should be idempotent - no time should be added |
| 39 | + first_total = clock.total |
| 40 | + clock.start! |
| 41 | + second_total = clock.total |
| 42 | + |
| 43 | + # The total should not jump significantly just from calling start! again |
| 44 | + expect(second_total - first_total).to be < 0.001 |
| 45 | + clock.stop! |
| 46 | + end |
| 47 | + |
| 48 | + expect(clock.total).to be >= 0 |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + with "#stop" do |
| 53 | + it "handles stop without start" do |
| 54 | + result = clock.stop! |
| 55 | + expect(result).to be == 0 |
| 56 | + expect(clock.total).to be == 0 |
| 57 | + end |
| 58 | + |
| 59 | + it "handles multiple stops" do |
| 60 | + clock.start! |
| 61 | + first_stop = clock.stop! |
| 62 | + second_stop = clock.stop! |
| 63 | + |
| 64 | + expect(first_stop).to be == second_stop |
| 65 | + expect(clock.total).to be == first_stop |
| 66 | + end |
| 67 | + end |
| 68 | + |
34 | 69 | with "#total" do |
35 | 70 | with "initial duration" do |
36 | 71 | let(:clock) {subject.new(1.5)} |
|
48 | 83 | sleep(0.0001) |
49 | 84 | expect(clock.total).to be >= total |
50 | 85 | end |
| 86 | + |
| 87 | + it "preserves total during start/stop cycles" do |
| 88 | + # First cycle |
| 89 | + clock.start! |
| 90 | + sleep(0.001) |
| 91 | + first_total = clock.stop! |
| 92 | + |
| 93 | + # Second cycle |
| 94 | + clock.start! |
| 95 | + sleep(0.001) |
| 96 | + second_total = clock.stop! |
| 97 | + |
| 98 | + expect(second_total).to be > first_total |
| 99 | + expect(clock.total).to be == second_total |
| 100 | + end |
51 | 101 | end |
52 | 102 |
|
53 | 103 | with ".start" do |
|
77 | 127 | end |
78 | 128 | end |
79 | 129 |
|
80 | | - with "monotonicity" do |
| 130 | + with ".now" do |
81 | 131 | it "produces monotonic timestamps" do |
82 | 132 | first = Async::Clock.now |
83 | 133 | second = Async::Clock.now |
|
95 | 145 | expect(duration).to be >= 0 |
96 | 146 | end |
97 | 147 | end |
98 | | - |
99 | | - with "edge cases" do |
100 | | - it "handles multiple start/stop cycles" do |
101 | | - 3.times do |
102 | | - clock.start! |
103 | | - # Calling start! again should not change the start time |
104 | | - original_start = clock.instance_variable_get(:@started) |
105 | | - clock.start! |
106 | | - expect(clock.instance_variable_get(:@started)).to be == original_start |
107 | | - clock.stop! |
108 | | - end |
109 | | - |
110 | | - expect(clock.total).to be >= 0 |
111 | | - end |
112 | | - |
113 | | - it "handles stop without start" do |
114 | | - result = clock.stop! |
115 | | - expect(result).to be == 0 |
116 | | - expect(clock.total).to be == 0 |
117 | | - end |
118 | | - |
119 | | - it "handles multiple stops" do |
120 | | - clock.start! |
121 | | - first_stop = clock.stop! |
122 | | - second_stop = clock.stop! |
123 | | - |
124 | | - expect(first_stop).to be == second_stop |
125 | | - expect(clock.total).to be == first_stop |
126 | | - end |
127 | | - |
128 | | - it "preserves total during start/stop cycles" do |
129 | | - # First cycle |
130 | | - clock.start! |
131 | | - sleep(0.001) |
132 | | - first_total = clock.stop! |
133 | | - |
134 | | - # Second cycle |
135 | | - clock.start! |
136 | | - sleep(0.001) |
137 | | - second_total = clock.stop! |
138 | | - |
139 | | - expect(second_total).to be > first_total |
140 | | - expect(clock.total).to be == second_total |
141 | | - end |
142 | | - |
143 | | - it "includes running time in total" do |
144 | | - base_total = clock.total |
145 | | - expect(base_total).to be == 0 |
146 | | - |
147 | | - clock.start! |
148 | | - sleep(0.001) |
149 | | - running_total = clock.total |
150 | | - |
151 | | - expect(running_total).to be > base_total |
152 | | - expect(clock.instance_variable_get(:@started)).not.to be_nil |
153 | | - end |
154 | | - end |
155 | | - |
156 | 148 | end |
0 commit comments