ar_multi_threaded_transactional_tests 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/lib/ar_multi_threaded_transactional_tests.rb +71 -0
- data/lib/ar_multi_threaded_transactional_tests/version.rb +3 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6cab2d048b066da11ee3b70253592f95c352068b
|
4
|
+
data.tar.gz: 88621efbfd78f721fd503c96db135b571015e99c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cdff6be45803753291d0c0c56ff061402deafa890e471b1ace9bc856cb250aa4b66877688185a35cf1560f29084a0df0821f2177fb744fafcabc10825b882fba
|
7
|
+
data.tar.gz: 0a2e62e254fae583b5e581a28dc9da5eafc18b8a348425fd1b874aaaf903b37373342ad4780687c72ddd53fb16f1344f33c1186cb83e1f90b94bec83c26d8b09
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) 2013 Michael Grosser <michael@grosser.it>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
# Multithreaded code uses the same connection or we would escape our surrounding transactional fixtures.
|
4
|
+
# To make multiple threads not step on each other, we wrap each transaction and
|
5
|
+
# and each execution outside of a transaction in a lock, being careful not to lock multiple times when nesting.
|
6
|
+
module ArMultiThreadedTransactionalTests
|
7
|
+
MUTEX = Mutex.new
|
8
|
+
|
9
|
+
class << self
|
10
|
+
attr_reader :active, :connection
|
11
|
+
|
12
|
+
def activate
|
13
|
+
if block_given?
|
14
|
+
begin
|
15
|
+
activate
|
16
|
+
yield
|
17
|
+
ensure
|
18
|
+
deactivate
|
19
|
+
end
|
20
|
+
else
|
21
|
+
@active = true
|
22
|
+
@connection = ActiveRecord::Base.connection
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def deactivate
|
27
|
+
@active = false
|
28
|
+
@connection = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def synchronize
|
32
|
+
if !active || Thread.current[:MultiThreadDbSyncerLocked]
|
33
|
+
yield
|
34
|
+
else
|
35
|
+
MUTEX.synchronize do
|
36
|
+
begin
|
37
|
+
Thread.current[:MultiThreadDbSyncerLocked] = true
|
38
|
+
yield
|
39
|
+
ensure
|
40
|
+
Thread.current[:MultiThreadDbSyncerLocked] = false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module TransactionSyncer
|
48
|
+
def transaction(*)
|
49
|
+
ArMultiThreadedTransactionalTests.synchronize { super }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module ExecutionSyncer
|
54
|
+
def log(*)
|
55
|
+
ArMultiThreadedTransactionalTests.synchronize { super }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
module ConnectionSyncer
|
60
|
+
def connection
|
61
|
+
ArMultiThreadedTransactionalTests.connection || super
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class << ActiveRecord::Base
|
67
|
+
prepend ArMultiThreadedTransactionalTests::TransactionSyncer
|
68
|
+
prepend ArMultiThreadedTransactionalTests::ConnectionSyncer
|
69
|
+
end
|
70
|
+
|
71
|
+
ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend ArMultiThreadedTransactionalTests::ExecutionSyncer
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ar_multi_threaded_transactional_tests
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Grosser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.1.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.2.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.1.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bump
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: maxitest
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: single_cov
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: sqlite3
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: wwtd
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
description:
|
118
|
+
email: michael@grosser.it
|
119
|
+
executables: []
|
120
|
+
extensions: []
|
121
|
+
extra_rdoc_files: []
|
122
|
+
files:
|
123
|
+
- MIT-LICENSE
|
124
|
+
- lib/ar_multi_threaded_transactional_tests.rb
|
125
|
+
- lib/ar_multi_threaded_transactional_tests/version.rb
|
126
|
+
homepage: https://github.com/grosser/ar_multi_threaded_transactional_tests
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.1.0
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.5.1
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Execute multithreaded code while still using transactional fixtures by synchronizing
|
150
|
+
db access to a single connection
|
151
|
+
test_files: []
|