8000 Update README. · socketry/async-rspec@fe712cc · GitHub
[go: up one dir, main page]

Skip to content

Commit fe712cc

Browse files
committed
Update README.
1 parent 69272af commit fe712cc

File tree

1 file changed

+32
-46
lines changed

1 file changed

+32
-46
lines changed

README.md

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -32,52 +32,7 @@ require 'async/rspec'
3232

3333
## Usage
3434

35-
### Leaks
36-
37-
Leaking sockets and other kinds of IOs are a problem for long running services. `Async::RSpec::Leaks` tracks all open sockets both before and after the spec. If any are left open, a `RuntimeError` is raised and the spec fails.
38-
39-
```ruby
40-
RSpec.describe "leaky ios" do
41-
include_context Async::RSpec::Leaks
42-
43-
# The following fails:
44-
it "leaks io" do
45-
@input, @output = IO.pipe
46-
end
47-
end
48-
```
49-
50-
In some cases, the Ruby garbage collector will close IOs. In the above case, it's possible that just writing `IO.pipe` will not leak as Ruby will garbage collect the resulting IOs immediately. It's still incorrect to not close IOs, so don't depend on this behaviour.
51-
52-
### Allocations
53-
54-
Allocating large amounts of objects can lead to memery problems. `Async::RSpec::Memory` adds a `limit_allocations` matcher, which tracks the number of allocations and memory size for each object type and allows you to specify expected limits.
55-
56-
```ruby
57-
RSpec.describe "memory allocations" do
58-
include_context Async::RSpec::Memory
59-
60-
it "limits allocation counts" do
61-
expect do
62-
6.times{String.new}
63-
end.to limit_allocations(String => 10) # 10 strings can be allocated
64-
end
65-
66-
it "limits allocation counts (hash)" do
67-
expect do
68-
6.times{String.new}
69-
end.to limit_allocations(String => {count: 10}) # 10 strings can be allocated
70-
end
71-
72-
it "limits allocation size" do
73-
expect do
74-
6.times{String.new("foo")}
75-
end.to limit_allocations(String => {size: 1024}) # 1 KB of strings can be allocated
76-
end
77-
end
78-
```
79-
80-
### Reactor
35+
### Async Reactor
8136

8237
Many specs need to run within a reactor. A shared context is provided which includes all the relevant bits, including the above leaks checks. If your spec fails to run in less than 10 seconds, an `Async::TimeoutError` raises to prevent your test suite from hanging.
8338

@@ -111,6 +66,37 @@ RSpec.describe Async::IO do
11166
end
11267
```
11368

69+
### Changing Timeout
70+
71+
You can change the timeout by specifying it as an option:
72+
73+
```ruby
74+
RSpec.describe MySlowThing, timeout: 60 do
75+
# ...
76+
end
77+
```
78+
79+
### File Descriptor Leaks
80+
81+
Leaking sockets and other kinds of IOs are a problem for long running services. `Async::RSpec::Leaks` tracks all open sockets both before and after the spec. If any are left open, a `RuntimeError` is raised and the spec fails.
82+
83+
```ruby
84+
RSpec.describe "leaky ios" do
85+
include_context Async::RSpec::Leaks
86+
87+
# The following fails:
88+
it "leaks io" do
89+
@input, @output = IO.pipe
90+
end
91+
end
92+
```
93+
94+
In some cases, the Ruby garbage collector will close IOs. In the above case, it's possible that just writing `IO.pipe` will not leak as Ruby will garbage collect the resulting IOs immediately. It's still incorrect to not close IOs, so don't depend on this behaviour.
95+
96+
### Allocations
97+
98+
This functionality was moved to [`rspec-memory`](https://github.com/socketry/rspec-memory).
99+
114100
## Contributing
115101

116102
1. Fork it

0 commit comments

Comments
 (0)
0