async-rspec 1.14.0 → 1.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/async/rspec/reactor.rb +31 -29
- data/lib/async/rspec/ssl.rb +6 -6
- data/lib/async/rspec/version.rb +1 -1
- metadata +21 -29
- data/.editorconfig +0 -6
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.travis.yml +0 -18
- data/Gemfile +0 -10
- data/README.md +0 -130
- data/Rakefile +0 -6
- data/async-rspec.gemspec +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34164069084058e87dd043f816b73f6c480d4998d105581213d7eb1e89ce3084
|
4
|
+
data.tar.gz: 46f3d8e14a447fbee85151cb6a3272e361fa287bbabed35805b5b79114916993
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8168f6c7a6846b4aa836417e005575bb4a5fa125a050145aefa4a31039d1909339d73b0227df97858a745dbde447d6fa72f00914dba6a3c511ef5eb4dce9a48
|
7
|
+
data.tar.gz: bdf7b373ce4fcbb11c149a4f3be47a318f508fc02ff57d5775ac01a3874310646b31af49bf5e0bf7a97752b4e0a0878890d3cada5a582b975325b41152412996
|
data/lib/async/rspec/reactor.rb
CHANGED
@@ -20,10 +20,10 @@
|
|
20
20
|
|
21
21
|
require_relative 'leaks'
|
22
22
|
|
23
|
+
require 'kernel/sync'
|
23
24
|
require 'kernel/async'
|
24
|
-
|
25
25
|
require 'async/reactor'
|
26
|
-
require 'async/
|
26
|
+
require 'async/task'
|
27
27
|
|
28
28
|
module Async
|
29
29
|
module RSpec
|
@@ -34,13 +34,12 @@ module Async
|
|
34
34
|
|
35
35
|
def run_in_reactor(reactor, duration = nil)
|
36
36
|
result = nil
|
37
|
-
|
38
37
|
timer_task = nil
|
39
38
|
|
40
39
|
if duration
|
41
40
|
timer_task = reactor.async do |task|
|
42
41
|
# Wait for the timeout, at any point this task might be cancelled if the user code completes:
|
43
|
-
task.annotate("
|
42
|
+
task.annotate("Timer task duration=#{duration}.")
|
44
43
|
task.sleep(duration)
|
45
44
|
|
46
45
|
# The timeout expired, so generate an error:
|
@@ -48,30 +47,28 @@ module Async
|
|
48
47
|
reactor.print_hierarchy(buffer)
|
49
48
|
|
50
49
|
# Raise an error so it is logged:
|
51
|
-
raise TimeoutError, "
|
50
|
+
raise TimeoutError, "Run time exceeded duration #{duration}s:\n#{buffer.string}"
|
52
51
|
end
|
53
52
|
end
|
54
53
|
|
55
|
-
reactor.
|
56
|
-
|
54
|
+
spec_task = reactor.async do |spec_task|
|
55
|
+
spec_task.annotate("running example")
|
57
56
|
|
58
|
-
|
59
|
-
spec_task.annotate("running example")
|
60
|
-
|
61
|
-
result = yield
|
62
|
-
|
63
|
-
timer_task&.stop
|
64
|
-
|
65
|
-
raise Async::Stop
|
66
|
-
end
|
57
|
+
result = yield(spec_task)
|
67
58
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
59
|
+
# We are finished, so stop the timer task if it was started:
|
60
|
+
timer_task&.stop
|
61
|
+
|
62
|
+
# Now stop the entire reactor:
|
63
|
+
raise Async::Stop
|
64
|
+
end
|
65
|
+
|
66
|
+
begin
|
67
|
+
timer_task&.wait
|
68
|
+
spec_task.wait
|
69
|
+
ensure
|
70
|
+
spec_task.stop
|
71
|
+
end
|
75
72
|
|
76
73
|
return result
|
77
74
|
end
|
@@ -79,8 +76,7 @@ module Async
|
|
79
76
|
|
80
77
|
::RSpec.shared_context Reactor do
|
81
78
|
include Reactor
|
82
|
-
|
83
|
-
let(:reactor) {Async::Reactor.new(selector: Async::Debug::Selector.new)}
|
79
|
+
let(:reactor) {@reactor}
|
84
80
|
|
85
81
|
include_context Async::RSpec::Leaks
|
86
82
|
|
@@ -88,11 +84,17 @@ module Async
|
|
88
84
|
duration = example.metadata.fetch(:timeout, 10)
|
89
85
|
|
90
86
|
begin
|
91
|
-
|
92
|
-
|
87
|
+
Sync do |task|
|
88
|
+
@reactor = task.reactor
|
89
|
+
|
90
|
+
task.annotate(self.class)
|
91
|
+
|
92
|
+
run_in_reactor(@reactor, duration) do
|
93
|
+
example.run
|
94
|
+
end
|
95
|
+
ensure
|
96
|
+
@reactor = nil
|
93
97
|
end
|
94
|
-
ensure
|
95
|
-
reactor.close
|
96
98
|
end
|
97
99
|
end
|
98
100
|
end
|
data/lib/async/rspec/ssl.rb
CHANGED
@@ -41,8 +41,8 @@ module Async
|
|
41
41
|
|
42
42
|
::RSpec.shared_context SSL::CertificateAuthority do
|
43
43
|
# This key size is generally considered insecure, but it's fine for testing.
|
44
|
-
let(:certificate_authority_key) {OpenSSL::PKey::RSA.new(
|
45
|
-
let(:certificate_authority_name) {OpenSSL::X509::Name.parse("O=
|
44
|
+
let(:certificate_authority_key) {OpenSSL::PKey::RSA.new(2048)}
|
45
|
+
let(:certificate_authority_name) {OpenSSL::X509::Name.parse("O=TestCA/CN=localhost")}
|
46
46
|
|
47
47
|
# The certificate authority is used for signing and validating the certificate which is used for communciation:
|
48
48
|
let(:certificate_authority) do
|
@@ -83,7 +83,7 @@ module Async
|
|
83
83
|
include_context SSL::CertificateAuthority
|
84
84
|
|
85
85
|
# The private key to use on the server side:
|
86
|
-
let(:key) {OpenSSL::PKey::RSA.new(
|
86
|
+
let(:key) {OpenSSL::PKey::RSA.new(2048)}
|
87
87
|
let(:certificate_name) {OpenSSL::X509::Name.parse("O=Test/CN=localhost")}
|
88
88
|
|
89
89
|
# The certificate used for actual communication:
|
@@ -115,7 +115,7 @@ module Async
|
|
115
115
|
|
116
116
|
let(:keys) do
|
117
117
|
Hash[
|
118
|
-
hosts.collect{|name| [name, OpenSSL::PKey::RSA.new(
|
118
|
+
hosts.collect{|name| [name, OpenSSL::PKey::RSA.new(2048)]}
|
119
119
|
]
|
120
120
|
end
|
121
121
|
|
@@ -177,8 +177,8 @@ module Async
|
|
177
177
|
include_context SSL::CertificateAuthority
|
178
178
|
|
179
179
|
# The private key to use on the server side:
|
180
|
-
let(:key) {OpenSSL::PKey::RSA.new(
|
181
|
-
let(:invalid_key) {OpenSSL::PKey::RSA.new(
|
180
|
+
let(:key) {OpenSSL::PKey::RSA.new(2048)}
|
181
|
+
let(:invalid_key) {OpenSSL::PKey::RSA.new(2048)}
|
182
182
|
let(:certificate_name) {OpenSSL::X509::Name.parse("O=Test/CN=localhost")}
|
183
183
|
|
184
184
|
# The certificate used for actual communication:
|
data/lib/async/rspec/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec-
|
28
|
+
name: rspec-files
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec-
|
42
|
+
name: rspec-memory
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
@@ -56,18 +56,18 @@ dependencies:
|
|
56
56
|
name: async
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: async-io
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -95,34 +95,25 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: covered
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
111
|
-
description:
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
112
|
email:
|
113
|
-
- samuel.williams@oriontransfer.co.nz
|
114
113
|
executables: []
|
115
114
|
extensions: []
|
116
115
|
extra_rdoc_files: []
|
117
116
|
files:
|
118
|
-
- ".editorconfig"
|
119
|
-
- ".gitignore"
|
120
|
-
- ".rspec"
|
121
|
-
- ".travis.yml"
|
122
|
-
- Gemfile
|
123
|
-
- README.md
|
124
|
-
- Rakefile
|
125
|
-
- async-rspec.gemspec
|
126
117
|
- lib/async/rspec.rb
|
127
118
|
- lib/async/rspec/buffer.rb
|
128
119
|
- lib/async/rspec/leaks.rb
|
@@ -132,9 +123,10 @@ files:
|
|
132
123
|
- lib/async/rspec/ssl.rb
|
133
124
|
- lib/async/rspec/version.rb
|
134
125
|
homepage: https://github.com/socketry/async-rspec
|
135
|
-
licenses:
|
126
|
+
licenses:
|
127
|
+
- MIT
|
136
128
|
metadata: {}
|
137
|
-
post_install_message:
|
129
|
+
post_install_message:
|
138
130
|
rdoc_options: []
|
139
131
|
require_paths:
|
140
132
|
- lib
|
@@ -149,8 +141,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
141
|
- !ruby/object:Gem::Version
|
150
142
|
version: '0'
|
151
143
|
requirements: []
|
152
|
-
rubygems_version: 3.
|
153
|
-
signing_key:
|
144
|
+
rubygems_version: 3.2.22
|
145
|
+
signing_key:
|
154
146
|
specification_version: 4
|
155
147
|
summary: Helpers for writing specs against the async gem.
|
156
148
|
test_files: []
|
data/.editorconfig
DELETED
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
|
4
|
-
matrix:
|
5
|
-
include:
|
6
|
-
- rvm: 2.4
|
7
|
-
- rvm: 2.5
|
8
|
-
- rvm: 2.6
|
9
|
-
- rvm: 2.6
|
10
|
-
env: COVERAGE=BriefSummary,Coveralls
|
11
|
-
- rvm: ruby-head
|
12
|
-
- rvm: jruby-head
|
13
|
-
env: JRUBY_OPTS="--debug -X+O"
|
14
|
-
- rvm: truffleruby
|
15
|
-
allow_failures:
|
16
|
-
- rvm: ruby-head
|
17
|
-
- rvm: jruby-head
|
18
|
-
- rvm: truffleruby
|
data/Gemfile
DELETED
data/README.md
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
# Async::RSpec
|
2
|
-
|
3
|
-
Provides useful `RSpec.shared_context`s for testing code that builds on top of [async].
|
4
|
-
|
5
|
-
[async]: https://github.com/socketry/async
|
6
|
-
|
7
|
-
[](http://travis-ci.org/socketry/async-rspec)
|
8
|
-
[](https://codeclimate.com/github/socketry/async-rspec)
|
9
|
-
[](https://coveralls.io/r/socketry/async-rspec)
|
10
|
-
|
11
|
-
## Installation
|
12
|
-
|
13
|
-
Add this line to your application's Gemfile:
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
gem 'async-rspec'
|
17
|
-
```
|
18
|
-
|
19
|
-
And then execute:
|
20
|
-
|
21
|
-
$ bundle
|
22
|
-
|
23
|
-
Or install it yourself as:
|
24
|
-
|
25
|
-
$ gem install async-rspec
|
26
|
-
|
27
|
-
Finally, add this require statement to the top of `spec/spec_helper.rb`
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
require 'async/rspec'
|
31
|
-
```
|
32
|
-
|
33
|
-
## Usage
|
34
|
-
|
35
|
-
### Async Reactor
|
36
|
-
|
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.
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
require 'async/io'
|
41
|
-
|
42
|
-
RSpec.describe Async::IO do
|
43
|
-
include_context Async::RSpec::Reactor
|
44
|
-
|
45
|
-
let(:pipe) {IO.pipe}
|
46
|
-
let(:input) {Async::IO::Generic.new(pipe.first)}
|
47
|
-
let(:output) {Async::IO::Generic.new(pipe.last)}
|
48
|
-
|
49
|
-
it "should send and receive data within the same reactor" do
|
50
|
-
message = nil
|
51
|
-
|
52
|
-
output_task = reactor.async do
|
53
|
-
message = input.read(1024)
|
54
|
-
end
|
55
|
-
|
56
|
-
reactor.async do
|
57
|
-
output.write("Hello World")
|
58
|
-
end
|
59
|
-
|
60
|
-
output_task.wait
|
61
|
-
expect(message).to be == "Hello World"
|
62
|
-
|
63
|
-
input.close
|
64
|
-
output.close
|
65
|
-
end
|
66
|
-
end
|
67
|
-
```
|
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: 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
|
-
|
100
|
-
## Contributing
|
101
|
-
|
102
|
-
1. Fork it
|
103
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
104
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
105
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
106
|
-
5. Create new Pull Request
|
107
|
-
|
108
|
-
## License
|
109
|
-
|
110
|
-
Released under the MIT license.
|
111
|
-
|
112
|
-
Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
|
113
|
-
|
114
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
115
|
-
of this software and associated documentation files (the "Software"), to deal
|
116
|
-
in the Software without restriction, including without limitation the rights
|
117
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
118
|
-
copies of the Software, and to permit persons to whom the Software is
|
119
|
-
furnished to do so, subject to the following conditions:
|
120
|
-
|
121
|
-
The above copyright notice and this permission notice shall be included in
|
122
|
-
all copies or substantial portions of the Software.
|
123
|
-
|
124
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
125
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
126
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
127
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
128
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
129
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
130
|
-
THE SOFTWARE.
|
data/Rakefile
DELETED
data/async-rspec.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
require_relative 'lib/async/rspec/version'
|
3
|
-
|
4
|
-
Gem::Specification.new do |spec|
|
5
|
-
spec.name = "async-rspec"
|
6
|
-
spec.version = Async::RSpec::VERSION
|
7
|
-
spec.authors = ["Samuel Williams"]
|
8
|
-
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
9
|
-
|
10
|
-
spec.summary = "Helpers for writing specs against the async gem."
|
11
|
-
spec.homepage = "https://github.com/socketry/async-rspec"
|
12
|
-
|
13
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
14
|
-
f.match(%r{^(test|spec|features)/})
|
15
|
-
end
|
16
|
-
|
17
|
-
spec.require_paths = ["lib"]
|
18
|
-
|
19
|
-
spec.add_dependency "rspec", "~> 3.0"
|
20
|
-
spec.add_dependency "rspec-memory", "~> 1.0"
|
21
|
-
spec.add_dependency "rspec-files", "~> 1.0"
|
22
|
-
|
23
|
-
# Since we test the shared contexts, we need some bits of async:
|
24
|
-
spec.add_development_dependency "async", "~> 1.24"
|
25
|
-
|
26
|
-
spec.add_development_dependency "covered"
|
27
|
-
spec.add_development_dependency "bundler"
|
28
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
-
end
|