services_test_server 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 78dd7bdc684b60554afddb89652f4b8d6c9035e8
4
+ data.tar.gz: 00dfb3609b25931e7e986b5b9535249e43a83a94
5
+ SHA512:
6
+ metadata.gz: 13de9d6b9bb9c2db77aaf2ed1db2ee674cef8a83a5616d92bb7ce6282110ab7b934cf5088f37eb7f24a4131fd18267fb6a1466a42616fe8c5ceebc8cbb883c2a
7
+ data.tar.gz: 58ccd8607dce442738072b1a81fe30d2b0f68e0d9ada4cf73e1a47d5dfb70f62b4252ef8412d6eb9da4903dfc168a409900b61669623192d2fe350cd693d8b3a
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in services_test_server.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Donald Plummer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # ServicesTestServer
2
+
3
+ Allows a client to do integration tests against a service with a transaction.
4
+ This server starts a DRb that can start/rollback transactions with
5
+ ActiveRecord.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'services_test_server'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install services_test_server
20
+
21
+ ## Usage
22
+
23
+ Configure what port DRb will listen on:
24
+
25
+ ```
26
+ ServicesTestServer.control_port = 8001
27
+ ```
28
+
29
+ In your `config/environments/test.rb` (or in a test initializer):
30
+
31
+ ```
32
+ config.after_initialize do
33
+ ServicesTestServer.start
34
+ end
35
+ ```
36
+
37
+ If you would like some logging, you can also configure the logger:
38
+
39
+ ```
40
+ ServicesTestServer.logger = Rails.logger
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/[my-github-username]/services_test_server/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib'
7
+ t.libs << 'test'
8
+ t.pattern = 'test/**/*_test.rb'
9
+ t.verbose = false
10
+ end
11
+
12
+ task :default => :test
13
+
14
+
@@ -0,0 +1,41 @@
1
+ require 'drb'
2
+ require 'thread'
3
+
4
+ module ServicesTestServer
5
+ class DbController
6
+ def self.only_one_connection
7
+ ActiveRecord::ConnectionAdapters::ConnectionPool.class_eval do
8
+ alias_method :old_checkout, :checkout
9
+
10
+ def checkout
11
+ @cached_connection ||= old_checkout
12
+ end
13
+ end
14
+ end
15
+
16
+ def self.start
17
+ only_one_connection
18
+
19
+ port = ServicesTestServer.control_port
20
+
21
+ DRb.start_service("druby://localhost:#{port}", new)
22
+ ServicesTestServer.logger.info "DbController service started on druby://localhost:#{port}"
23
+ end
24
+
25
+ def initialize
26
+ @mutex = Mutex.new
27
+ end
28
+
29
+ def begin_transaction
30
+ @mutex.lock
31
+ ServicesTestServer.logger.debug "Beginning remote transaction"
32
+ ActiveRecord::Base.connection.begin_transaction(joinable: false)
33
+ end
34
+
35
+ def rollback_transaction
36
+ ServicesTestServer.logger.debug "Rolling back remote transaction"
37
+ ActiveRecord::Base.connection.rollback_transaction
38
+ @mutex.unlock
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module ServicesTestServer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ require 'logger'
2
+
3
+ module ServicesTestServer
4
+ MissingConfiguration = Class.new(StandardError)
5
+
6
+ def self.control_port=(port)
7
+ @control_port = port
8
+ end
9
+
10
+ def self.control_port
11
+ @control_port || raise(MissingConfiguration.new(<<-MSG))
12
+ You must configure the port ServicesTestServer will start on, ie:
13
+ ServicesTestServer.control_port = 8000
14
+ MSG
15
+ end
16
+
17
+ def self.logger
18
+ @logger ||= Logger.new(File.open(File::NULL, 'w'))
19
+ end
20
+
21
+ def self.logger=(logger)
22
+ @logger = logger
23
+ end
24
+ end
25
+
26
+ require 'services_test_server/version'
27
+ require 'services_test_server/db_controller'
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'services_test_server/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "services_test_server"
8
+ spec.version = ServicesTestServer::VERSION
9
+ spec.authors = ["Donald Plummer"]
10
+ spec.email = ["donald.plummer@gmail.com"]
11
+ spec.summary = %q{Server for controlling a remote service during a client integration test run.}
12
+ spec.homepage = "https://github.com/dplummer/services_test_server"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "minitest", "~> 5.0"
23
+ spec.add_development_dependency "minitest-rg"
24
+ spec.add_development_dependency "activerecord", "~> 4.0"
25
+ spec.add_development_dependency "sqlite3"
26
+ end
@@ -0,0 +1,16 @@
1
+ require 'active_record'
2
+
3
+ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
4
+
5
+ ActiveRecord::Schema.define do
6
+ self.verbose = false
7
+
8
+ create_table :users, :force => true do |t|
9
+ t.string :name
10
+ end
11
+
12
+ end
13
+
14
+ class User < ActiveRecord::Base
15
+ end
16
+
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+
3
+ class ConfigurationTest < Minitest::Test
4
+ def test_drb_port_config
5
+ ServicesTestServer.control_port = 8008
6
+ assert_equal 8008, ServicesTestServer.control_port
7
+ end
8
+
9
+ def test_logger
10
+ sio = StringIO.new
11
+ ServicesTestServer.logger = Logger.new(sio)
12
+ ServicesTestServer.logger.info 'cats'
13
+ sio.rewind
14
+ assert (sio.read =~ / INFO -- : cats$/), 'Expected logger to log'
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ require 'test_helper'
2
+ require 'active_record_helper'
3
+
4
+ class DbControllerTest < Minitest::Test
5
+ def setup
6
+ ServicesTestServer::DbController.only_one_connection
7
+ end
8
+
9
+ def test_transaction
10
+ controller = ServicesTestServer::DbController.new
11
+ user = User.create!(name: 'Bob')
12
+
13
+ controller.begin_transaction
14
+
15
+ user.update_attributes!(name: 'Alice')
16
+ assert_equal 'Alice', user.name
17
+
18
+ controller.rollback_transaction
19
+
20
+ assert_equal 'Bob', user.reload.name
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ Bundler.require(:default, :test)
2
+ require 'minitest/autorun'
3
+ require 'minitest/rg'
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: services_test_server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Donald Plummer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-rg
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - donald.plummer@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/services_test_server.rb
110
+ - lib/services_test_server/db_controller.rb
111
+ - lib/services_test_server/version.rb
112
+ - services_test_server.gemspec
113
+ - test/active_record_helper.rb
114
+ - test/configuration_test.rb
115
+ - test/db_controller_test.rb
116
+ - test/test_helper.rb
117
+ homepage: https://github.com/dplummer/services_test_server
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.2.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Server for controlling a remote service during a client integration test
141
+ run.
142
+ test_files:
143
+ - test/active_record_helper.rb
144
+ - test/configuration_test.rb
145
+ - test/db_controller_test.rb
146
+ - test/test_helper.rb