You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-46Lines changed: 32 additions & 46 deletions
Original file line number
Diff line number
Diff line change
@@ -32,52 +32,7 @@ require 'async/rspec'
32
32
33
33
## Usage
34
34
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
81
36
82
37
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.
83
38
@@ -111,6 +66,37 @@ RSpec.describe Async::IO do
111
66
end
112
67
```
113
68
69
+
### Changing Timeout
70
+
71
+
You can change the timeout by specifying it as an option:
72
+
73
+
```ruby
74
+
RSpec.describe MySlowThing, timeout:60do
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).
0 commit comments