async-rspec 1.12.2 → 1.13.0
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/.gitignore +1 -0
- data/async-rspec.gemspec +2 -0
- data/lib/async/rspec/leaks.rb +3 -24
- data/lib/async/rspec/memory.rb +2 -4
- data/lib/async/rspec/version.rb +1 -1
- metadata +30 -4
- data/lib/async/rspec/memory/limit_allocations.rb +0 -115
- data/lib/async/rspec/memory/trace.rb +0 -140
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97dcfa776e85aa05a958dccc0211b29022faf1fbe054a9c294070efd23785e97
|
4
|
+
data.tar.gz: 267e2a08e809376bba96b59f80face4062d8782bf67406678a10c458cda9320c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c68ec95f28cef903eeb5c806d76e8c22260a7ba662179c96c96b9eaa8af268c6fc5f8b519d9fbde914ad7933b7495ed4a1e6a1424f479e46b5ff295d5862938
|
7
|
+
data.tar.gz: aa6aee44bb59f53f89a7a90f287728c946cd41508729b8274b92770c5fdafeab75d0fe5b72e90c359767eaa5f9a04ee05e7ea27ab5bd039791c308f7bf74b66a
|
data/.gitignore
CHANGED
data/async-rspec.gemspec
CHANGED
@@ -17,6 +17,8 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
19
|
spec.add_dependency "rspec", "~> 3.0"
|
20
|
+
spec.add_dependency "rspec-memory", "~> 1.0"
|
21
|
+
spec.add_dependency "rspec-files", "~> 1.0"
|
20
22
|
|
21
23
|
# Since we test the shared contexts, we need some bits of async:
|
22
24
|
spec.add_development_dependency "async", "~> 1.8"
|
data/lib/async/rspec/leaks.rb
CHANGED
@@ -18,31 +18,10 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
+
require 'rspec/files'
|
22
|
+
|
21
23
|
module Async
|
22
24
|
module RSpec
|
23
|
-
|
24
|
-
def current_ios(gc: GC.start)
|
25
|
-
all_ios = ObjectSpace.each_object(::IO).to_a.sort_by(&:object_id)
|
26
|
-
|
27
|
-
# We are not interested in ios that have been closed already:
|
28
|
-
return all_ios.reject{|io| io.closed?}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
::RSpec.shared_context Leaks do
|
33
|
-
include Leaks
|
34
|
-
|
35
|
-
let(:before_ios) {current_ios}
|
36
|
-
let(:after_ios) {current_ios}
|
37
|
-
|
38
|
-
# We use around(:each) because it's the highest priority.
|
39
|
-
around(:each) do |example|
|
40
|
-
before_ios
|
41
|
-
|
42
|
-
example.run.tap do
|
43
|
-
expect(after_ios).to be == before_ios
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
25
|
+
Leaks = ::RSpec::Files::Leaks
|
47
26
|
end
|
48
27
|
end
|
data/lib/async/rspec/memory.rb
CHANGED
@@ -18,12 +18,10 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
|
21
|
+
require 'rspec/memory'
|
22
22
|
|
23
23
|
module Async
|
24
24
|
module RSpec
|
25
|
-
::RSpec
|
26
|
-
include Memory
|
27
|
-
end
|
25
|
+
Memory = ::RSpec::Memory
|
28
26
|
end
|
29
27
|
end
|
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.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-memory
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-files
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: async
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,8 +127,6 @@ files:
|
|
99
127
|
- lib/async/rspec/buffer.rb
|
100
128
|
- lib/async/rspec/leaks.rb
|
101
129
|
- lib/async/rspec/memory.rb
|
102
|
-
- lib/async/rspec/memory/limit_allocations.rb
|
103
|
-
- lib/async/rspec/memory/trace.rb
|
104
130
|
- lib/async/rspec/profile.rb
|
105
131
|
- lib/async/rspec/reactor.rb
|
106
132
|
- lib/async/rspec/ssl.rb
|
@@ -1,115 +0,0 @@
|
|
1
|
-
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
# Copyright, 2018, by Janko Marohnić.
|
3
|
-
#
|
4
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
-
# of this software and associated documentation files (the "Software"), to deal
|
6
|
-
# in the Software without restriction, including without limitation the rights
|
7
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
-
# copies of the Software, and to permit persons to whom the Software is
|
9
|
-
# furnished to do so, subject to the following conditions:
|
10
|
-
#
|
11
|
-
# The above copyright notice and this permission notice shall be included in
|
12
|
-
# all copies or substantial portions of the Software.
|
13
|
-
#
|
14
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
-
# THE SOFTWARE.
|
21
|
-
|
22
|
-
require_relative 'trace'
|
23
|
-
|
24
|
-
require 'rspec/expectations'
|
25
|
-
|
26
|
-
module Async
|
27
|
-
module RSpec
|
28
|
-
module Memory
|
29
|
-
# expect{...}.to allocate < 10.megabytes
|
30
|
-
#
|
31
|
-
class LimitAllocations
|
32
|
-
include ::RSpec::Matchers::Composable
|
33
|
-
|
34
|
-
def initialize(allocations = {}, count: nil, size: nil)
|
35
|
-
@count = count
|
36
|
-
@size = size
|
37
|
-
|
38
|
-
@allocations = {}
|
39
|
-
@errors = []
|
40
|
-
|
41
|
-
allocations.each do |klass, count|
|
42
|
-
self.of(klass, count: count)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def supports_block_expectations?
|
47
|
-
true
|
48
|
-
end
|
49
|
-
|
50
|
-
def of(klass, **limits)
|
51
|
-
@allocations[klass] = limits
|
52
|
-
|
53
|
-
return self
|
54
|
-
end
|
55
|
-
|
56
|
-
private def check(value, limit)
|
57
|
-
case limit
|
58
|
-
when Range
|
59
|
-
unless limit.include? value
|
60
|
-
yield "expected within #{limit}"
|
61
|
-
end
|
62
|
-
when Integer
|
63
|
-
unless value == limit
|
64
|
-
yield "expected exactly #{limit}"
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def matches?(given_proc)
|
70
|
-
return true unless trace = Trace.capture(@allocations.keys, &given_proc)
|
71
|
-
|
72
|
-
if @count or @size
|
73
|
-
# If the spec specifies a total limit, we have a limit which we can enforce which takes all allocations into account:
|
74
|
-
total = trace.total
|
75
|
-
|
76
|
-
check(total.count, @count) do |expected|
|
77
|
-
@errors << "allocated #{total.count} instances, #{total.size} bytes, #{expected} instances"
|
78
|
-
end if @count
|
79
|
-
|
80
|
-
check(total.size, @size) do |expected|
|
81
|
-
@errors << "allocated #{total.count} instances, #{total.size} bytes, #{expected} bytes"
|
82
|
-
end if @size
|
83
|
-
else
|
84
|
-
# Otherwise unspecified allocations are considered an error:
|
85
|
-
trace.ignored.each do |klass, allocation|
|
86
|
-
@errors << "allocated #{allocation.count} #{klass} instances, #{allocation.size} bytes, but it was not specified"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
trace.allocated.each do |klass, allocation|
|
91
|
-
next unless acceptable = @allocations[klass]
|
92
|
-
|
93
|
-
check(allocation.count, acceptable[:count]) do |expected|
|
94
|
-
@errors << "allocated #{allocation.count} #{klass} instances, #{allocation.size} bytes, #{expected} instances"
|
95
|
-
end
|
96
|
-
|
97
|
-
check(allocation.size, acceptable[:size]) do |expected|
|
98
|
-
@errors << "allocated #{allocation.count} #{klass} instances, #{allocation.size} bytes, #{expected} bytes"
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
return @errors.empty?
|
103
|
-
end
|
104
|
-
|
105
|
-
def failure_message
|
106
|
-
"exceeded allocation limit: #{@errors.join(', ')}"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def limit_allocations(*args)
|
111
|
-
LimitAllocations.new(*args)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
@@ -1,140 +0,0 @@
|
|
1
|
-
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'objspace'
|
22
|
-
|
23
|
-
module Async
|
24
|
-
module RSpec
|
25
|
-
module Memory
|
26
|
-
Allocation = Struct.new(:count, :size) do
|
27
|
-
SLOT_SIZE = 40
|
28
|
-
|
29
|
-
def << object
|
30
|
-
self.count += 1
|
31
|
-
|
32
|
-
# We don't want to force specs to take the slot size into account.
|
33
|
-
self.size += ObjectSpace.memsize_of(object) - SLOT_SIZE
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.default_hash
|
37
|
-
Hash.new{|h,k| h[k] = Allocation.new(0, 0)}
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class Trace
|
42
|
-
def self.supported?
|
43
|
-
# There are issues on truffleruby-1.0.0rc9
|
44
|
-
return false if RUBY_ENGINE == "truffleruby"
|
45
|
-
|
46
|
-
ObjectSpace.respond_to?(:trace_object_allocations)
|
47
|
-
end
|
48
|
-
|
49
|
-
if supported?
|
50
|
-
def self.capture(*args, &block)
|
51
|
-
self.new(*args).tap do |trace|
|
52
|
-
trace.capture(&block)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
else
|
56
|
-
def self.capture(*args, &block)
|
57
|
-
yield
|
58
|
-
|
59
|
-
return nil
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def initialize(klasses)
|
64
|
-
@klasses = klasses
|
65
|
-
|
66
|
-
@allocated = Allocation.default_hash
|
67
|
-
@retained = Allocation.default_hash
|
68
|
-
|
69
|
-
@ignored = Allocation.default_hash
|
70
|
-
|
71
|
-
@total = Allocation.new(0, 0)
|
72
|
-
end
|
73
|
-
|
74
|
-
attr :allocated
|
75
|
-
attr :retained
|
76
|
-
|
77
|
-
attr :ignored
|
78
|
-
|
79
|
-
attr :total
|
80
|
-
|
81
|
-
def current_objects(generation)
|
82
|
-
allocations = []
|
83
|
-
|
84
|
-
ObjectSpace.each_object do |object|
|
85
|
-
if ObjectSpace.allocation_generation(object) == generation
|
86
|
-
allocations << object
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
return allocations
|
91
|
-
end
|
92
|
-
|
93
|
-
def find_base(object)
|
94
|
-
@klasses.find{|klass| object.is_a? klass}
|
95
|
-
end
|
96
|
-
|
97
|
-
def capture(&block)
|
98
|
-
GC.start
|
99
|
-
|
100
|
-
begin
|
101
|
-
GC.disable
|
102
|
-
|
103
|
-
generation = GC.count
|
104
|
-
ObjectSpace.trace_object_allocations(&block)
|
105
|
-
|
106
|
-
allocated = current_objects(generation)
|
107
|
-
ensure
|
108
|
-
GC.enable
|
109
|
-
end
|
110
|
-
|
111
|
-
GC.start
|
112
|
-
retained = current_objects(generation)
|
113
|
-
|
114
|
-
# All allocated objects, including those freed in the last GC:
|
115
|
-
allocated.each do |object|
|
116
|
-
if klass = find_base(object)
|
117
|
-
@allocated[klass] << object
|
118
|
-
else
|
119
|
-
# If the user specified classes, but we can't pin this allocation to a specific class, we issue a warning.
|
120
|
-
if @klasses.any?
|
121
|
-
warn "Ignoring allocation of #{object.class} at #{ObjectSpace.allocation_sourcefile(object)}:#{ObjectSpace.allocation_sourceline(object)}"
|
122
|
-
end
|
123
|
-
|
124
|
-
@ignored[object.class] << object
|
125
|
-
end
|
126
|
-
|
127
|
-
@total << object
|
128
|
-
end
|
129
|
-
|
130
|
-
# Retained objects are still alive after a final GC:
|
131
|
-
retained.each do |object|
|
132
|
-
if klass = find_base(object)
|
133
|
-
@retained[klass] << object
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|