Skip to content

Commit 3042fa8

Browse files
committed
Add coverage for Async::Container::Statistics.
1 parent 1e7b6a8 commit 3042fa8

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

test/async/container/statistics.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2025, by Samuel Williams.
5+
6+
require "async/container/statistics"
7+
8+
describe Async::Container::Statistics do
9+
let(:statistics) {subject.new}
10+
11+
with "#spawn!" do
12+
it "can count spawns" do
13+
expect(statistics.spawns).to be == 0
14+
15+
statistics.spawn!
16+
17+
expect(statistics.spawns).to be == 1
18+
end
19+
end
20+
21+
with "#restart!" do
22+
it "can count restarts" do
23+
expect(statistics.restarts).to be == 0
24+
25+
statistics.restart!
26+
27+
expect(statistics.restarts).to be == 1
28+
end
29+
end
30+
31+
with "#failure!" do
32+
it "can count failures" do
33+
expect(statistics.failures).to be == 0
34+
35+
statistics.failure!
36+
37+
expect(statistics.failures).to be == 1
38+
end
39+
end
40+
41+
with "#failed?" do
42+
it "can check for failures" do
43+
expect(statistics).not.to be(:failed?)
44+
45+
statistics.failure!
46+
47+
expect(statistics).to be(:failed?)
48+
end
49+
end
50+
51+
with "#<<" do
52+
it "can append statistics" do
53+
other = subject.new
54+
55+
other.spawn!
56+
other.restart!
57+
other.failure!
58+
59+
statistics << other
60+
61+
expect(statistics.spawns).to be == 1
62+
expect(statistics.restarts).to be == 1
63+
expect(statistics.failures).to be == 1
64+
end
65+
end
66+
end

0 commit comments

Comments
 (0)