offshore 0.0.6 → 0.0.7
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.
- data/README.md +4 -3
- data/lib/offshore/server/database.rb +2 -41
- data/lib/offshore/tasks.rb +2 -2
- data/lib/offshore/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -51,8 +51,8 @@ The :preload and :setup steps will be invoked in that order before your :seed ca
|
|
51
51
|
* For other Rack apps, you should be able to use Offshore::Middleware directly.
|
52
52
|
* This middleware is included automatically in Rails via Railties.
|
53
53
|
* The server is meant to be a singular resource accessed by many test threads (parallelization of tests). It accomplishes this through a mutex and polling its availability.
|
54
|
-
|
55
|
-
|
54
|
+
* You'll want to run `rake offshore:startup` on the server beforehand to call your rake code and set up the databases
|
55
|
+
* Running the server will look something like `RAILS_ENV=test OFFSHORE=true rails s -p 6001` depending on the server configuration (app decided to only enable with the env for example)
|
56
56
|
|
57
57
|
## Client
|
58
58
|
|
@@ -94,16 +94,17 @@ You can send :snapshot => false to Offshore.suite.start to prevent rolling back
|
|
94
94
|
Note, this will leave your suite in a somewhat unpredictable state especially when you consider there are other suites that might be rolling that database back.
|
95
95
|
However, this may be preferable if your database is very large. On small (50 tables / 1000 rows) databases, the difference in time seems to be noise. Some efforts are taken (checksum) to not rollback if the test did not change the database.
|
96
96
|
|
97
|
-
|
98
97
|
#### Notes
|
99
98
|
|
100
99
|
* You can also make API requests.
|
101
100
|
* You get a fresh database each time by default.
|
101
|
+
* You'll want to run `rake offshore:startup` on the server beforehand to set up the databases
|
102
102
|
|
103
103
|
## TODO
|
104
104
|
|
105
105
|
* Use binlogs if enabled for even faster MySQL rollback
|
106
106
|
* Configure custom lookups for the hash returned with the created data
|
107
|
+
* Register with keys that maps to databases to support parallel tests
|
107
108
|
* Configure custom paths (defaults to /offshore_tests now)
|
108
109
|
* Anything else need to be cleared out each test? i.e. redis, memcache, etc
|
109
110
|
* Other DB support
|
@@ -2,7 +2,6 @@ module Offshore
|
|
2
2
|
module Database
|
3
3
|
extend self
|
4
4
|
|
5
|
-
GENERATE_KEY = "database:generate"
|
6
5
|
LOCK_KEY = "database:lock"
|
7
6
|
SHUTDOWN_KEY = "database:shutdown"
|
8
7
|
SUITES_LIST_KEY = "suites:list"
|
@@ -29,15 +28,13 @@ module Offshore
|
|
29
28
|
def reset
|
30
29
|
Logger.info(" Database.reset")
|
31
30
|
redis.del(LOCK_KEY)
|
32
|
-
redis.del(GENERATE_KEY)
|
33
31
|
redis.del(SHUTDOWN_KEY)
|
34
32
|
redis.del(SUITES_LIST_KEY)
|
35
33
|
end
|
36
34
|
|
37
|
-
def startup
|
35
|
+
def startup
|
38
36
|
Logger.info(" Database.startup")
|
39
37
|
reset
|
40
|
-
create_schema(background)
|
41
38
|
end
|
42
39
|
|
43
40
|
def shutdown
|
@@ -54,10 +51,8 @@ module Offshore
|
|
54
51
|
Offshore::Database.unlock unless ENV['MULTI_OFFSHORE'] # no reason to keep everyone waiting if I'm the only one
|
55
52
|
|
56
53
|
if redis.get(SHUTDOWN_KEY)
|
57
|
-
Logger.info(" ....
|
54
|
+
Logger.info(" .... database shutting down. Exiting.")
|
58
55
|
raise "Database shutting down. No new connections, please."
|
59
|
-
else
|
60
|
-
create_schema(true)
|
61
56
|
end
|
62
57
|
end
|
63
58
|
|
@@ -73,40 +68,6 @@ module Offshore
|
|
73
68
|
|
74
69
|
private
|
75
70
|
|
76
|
-
def create_schema(background)
|
77
|
-
times = redis.incr(GENERATE_KEY) # get the incremented counter value
|
78
|
-
unless times == 1
|
79
|
-
Logger.info(" Database.create_schema: already created")
|
80
|
-
return
|
81
|
-
end
|
82
|
-
|
83
|
-
Logger.info(" Database.create_schema: creating....")
|
84
|
-
lock
|
85
|
-
if background
|
86
|
-
build_in_fork
|
87
|
-
else
|
88
|
-
build_in_process
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
|
93
|
-
def build_in_fork
|
94
|
-
Logger.info(" ..... building in fork")
|
95
|
-
otherProcess = fork { `bundle exec rake offshore:seed_schema --trace`; `bundle exec rake offshore:unlock --trace`; }
|
96
|
-
Process.detach(otherProcess)
|
97
|
-
end
|
98
|
-
|
99
|
-
def build_in_process
|
100
|
-
Logger.info(" ..... building in process")
|
101
|
-
#TODO: configurable, what rake job if not exist
|
102
|
-
%x(bundle exec rake offshore:seed_schema --trace)
|
103
|
-
unless $? == 0
|
104
|
-
reset
|
105
|
-
raise "rake offshore:seed_schema failed!"
|
106
|
-
end
|
107
|
-
unlock
|
108
|
-
end
|
109
|
-
|
110
71
|
def snapshot
|
111
72
|
Offshore::Snapshot::Template
|
112
73
|
end
|
data/lib/offshore/tasks.rb
CHANGED
@@ -23,8 +23,8 @@ namespace :offshore do
|
|
23
23
|
Offshore::Database.shutdown
|
24
24
|
end
|
25
25
|
|
26
|
-
task :startup => [:preload, :setup] do
|
27
|
-
Offshore::Database.startup
|
26
|
+
task :startup => [:preload, :setup, :seed_schema] do
|
27
|
+
Offshore::Database.startup
|
28
28
|
end
|
29
29
|
|
30
30
|
desc "Reset the db"
|
data/lib/offshore/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: offshore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|