easymon 1.6.2 → 1.6.4
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/README.md +28 -12
- data/Rakefile +1 -1
- data/app/controllers/easymon/checks_controller.rb +6 -6
- data/config/routes.rb +2 -2
- data/lib/easymon/checklist.rb +7 -7
- data/lib/easymon/checks/active_record_check.rb +6 -5
- data/lib/easymon/checks/active_record_mysql_writeable_check.rb +1 -1
- data/lib/easymon/checks/http_check.rb +6 -6
- data/lib/easymon/checks/memcached_check.rb +6 -6
- data/lib/easymon/checks/multi_active_record_check.rb +52 -0
- data/lib/easymon/checks/redis_check.rb +3 -3
- data/lib/easymon/checks/redis_writeable_check.rb +1 -1
- data/lib/easymon/checks/semaphore_check.rb +6 -6
- data/lib/easymon/checks/split_active_record_check.rb +6 -16
- data/lib/easymon/checks/traffic_enabled_check.rb +2 -2
- data/lib/easymon/engine.rb +1 -1
- data/lib/easymon/repository.rb +5 -5
- data/lib/easymon/result.rb +2 -2
- data/lib/easymon/testing.rb +2 -2
- data/lib/easymon/version.rb +1 -1
- data/lib/easymon.rb +10 -9
- data/test/controllers/easymon/checks_controller_test.rb +10 -11
- data/test/dummy/Rakefile +2 -3
- data/test/dummy/app/assets/stylesheets/application.css +6 -4
- data/test/dummy/app/controllers/application_controller.rb +2 -1
- data/test/dummy/app/jobs/application_job.rb +7 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +22 -9
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/app/views/pwa/manifest.json.erb +22 -0
- data/test/dummy/app/views/pwa/service-worker.js +26 -0
- data/test/dummy/bin/dev +2 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +34 -0
- data/test/dummy/config/application.rb +22 -50
- data/test/dummy/config/boot.rb +4 -9
- data/test/dummy/config/database.yml +25 -6
- data/test/dummy/config/environment.rb +4 -4
- data/test/dummy/config/environments/development.rb +55 -25
- data/test/dummy/config/environments/production.rb +64 -42
- data/test/dummy/config/environments/test.rb +35 -25
- data/test/dummy/config/initializers/assets.rb +7 -0
- data/test/dummy/config/initializers/content_security_policy.rb +25 -0
- data/test/dummy/config/initializers/easymon.rb +2 -2
- data/test/dummy/config/initializers/filter_parameter_logging.rb +8 -0
- data/test/dummy/config/initializers/inflections.rb +10 -9
- data/test/dummy/config/locales/en.yml +28 -2
- data/test/dummy/config/puma.rb +38 -0
- data/test/dummy/config/redis.yml +5 -6
- data/test/dummy/config/routes.rb +13 -0
- data/test/dummy/config/storage.yml +34 -0
- data/test/dummy/config.ru +4 -2
- data/test/dummy/log/test.log +0 -8916
- data/test/dummy/public/400.html +114 -0
- data/test/dummy/public/404.html +113 -25
- data/test/dummy/public/406-unsupported-browser.html +114 -0
- data/test/dummy/public/422.html +113 -25
- data/test/dummy/public/500.html +113 -24
- data/test/dummy/public/icon.png +0 -0
- data/test/dummy/public/icon.svg +3 -0
- data/test/dummy/tmp/local_secret.txt +1 -0
- data/test/helpers/easymon/checks_helper_test.rb +1 -1
- data/test/integration/navigation_test.rb +1 -2
- data/test/test_helper.rb +3 -3
- data/test/unit/checklist_test.rb +5 -5
- data/test/unit/checks/active_record_check_on_postgresql_test.rb +1 -2
- data/test/unit/checks/active_record_check_test.rb +1 -2
- data/test/unit/checks/active_record_mysql_writeable_check_test.rb +2 -3
- data/test/unit/checks/http_check_test.rb +3 -3
- data/test/unit/checks/memcached_check_test.rb +6 -8
- data/test/unit/checks/multi_active_record_check_test.rb +73 -0
- data/test/unit/checks/redis_check_test.rb +8 -9
- data/test/unit/checks/redis_writeable_check_test.rb +2 -3
- data/test/unit/checks/semaphore_check_test.rb +2 -3
- data/test/unit/checks/split_active_record_check_test.rb +9 -24
- data/test/unit/checks/traffic_enabled_check_test.rb +2 -3
- data/test/unit/repository_test.rb +2 -3
- metadata +98 -80
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/app/assets/config/manifest.js +0 -0
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/javascripts/easymon.js +0 -2
- data/test/dummy/app/assets/stylesheets/easymon.css +0 -4
- data/test/dummy/app/controllers/easymon_controller.rb +0 -7
- data/test/dummy/app/helpers/easymon_helper.rb +0 -2
- data/test/dummy/app/views/easymon/index.html.erb +0 -2
- data/test/dummy/app/views/easymon/show.html.erb +0 -2
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/log/development.log +0 -24
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
- data/test/dummy/tmp/cache/4D4/7A0/health_check +0 -1
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
69d142a16a2f12228584cd763b3a304b81a860016191866149145dfd1a343cbc7240b4ab51e2eb4c3f08ffd3f71a8d6b11aff2dc711209df99b151ef88ef540c
|
data/test/test_helper.rb
CHANGED
|
@@ -19,7 +19,7 @@ class ActiveSupport::TestCase
|
|
|
19
19
|
# This is needed to prevent leakage between tests, the Easymon::Repository
|
|
20
20
|
# will remember all checks added to it, regardless of what test it was
|
|
21
21
|
# added in
|
|
22
|
-
Easymon::Repository.names.each {|name| Easymon::Repository.remove(name)}
|
|
22
|
+
Easymon::Repository.names.each { |name| Easymon::Repository.remove(name) }
|
|
23
23
|
end
|
|
24
24
|
end
|
|
25
25
|
|
|
@@ -28,10 +28,10 @@ class ActionController::TestCase
|
|
|
28
28
|
# This is needed to prevent leakage between tests, the Easymon::Repository
|
|
29
29
|
# will remember all checks added to it, regardless of what test it was
|
|
30
30
|
# added in
|
|
31
|
-
Easymon::Repository.names.each {|name| Easymon::Repository.remove(name)}
|
|
31
|
+
Easymon::Repository.names.each { |name| Easymon::Repository.remove(name) }
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
# setting up mocha *after* we load the test libraries as per
|
|
36
36
|
# http://gofreerange.com/mocha/docs/
|
|
37
|
-
require
|
|
37
|
+
require "mocha/minitest"
|
data/test/unit/checklist_test.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class ChecklistTest < ActiveSupport::TestCase
|
|
4
4
|
def setup
|
|
5
5
|
Easymon::Repository.add("database", Easymon::ActiveRecordCheck.new(ActiveRecord::Base))
|
|
6
|
-
Easymon::Repository.add("redis", Easymon::RedisCheck.new(YAML.load_file(Rails.root.join("config/redis.yml"))[Rails.env].symbolize_keys))
|
|
6
|
+
Easymon::Repository.add("redis", Easymon::RedisCheck.new(YAML.load_file(Rails.root.join("config/redis.yml"), aliases: true)[Rails.env].symbolize_keys))
|
|
7
7
|
Easymon::Repository.add("memcached", Easymon::MemcachedCheck.new(Rails.cache))
|
|
8
8
|
end
|
|
9
9
|
|
|
@@ -34,9 +34,9 @@ class ChecklistTest < ActiveSupport::TestCase
|
|
|
34
34
|
test "#timing is a sum of all check results" do
|
|
35
35
|
checklist = Easymon::Repository.all
|
|
36
36
|
# Fake some results
|
|
37
|
-
checklist.results = %w
|
|
37
|
+
checklist.results = %w[one two three].inject({}) do |hash, name|
|
|
38
38
|
timing = 1.2
|
|
39
|
-
hash[name] = Easymon::Result.new([name, "dummy message"], timing)
|
|
39
|
+
hash[name] = Easymon::Result.new([ name, "dummy message" ], timing)
|
|
40
40
|
hash
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -77,4 +77,4 @@ class ChecklistTest < ActiveSupport::TestCase
|
|
|
77
77
|
|
|
78
78
|
assert checklist.fetch("database")[:check].instance_of? Easymon::ActiveRecordCheck
|
|
79
79
|
end
|
|
80
|
-
end
|
|
80
|
+
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class ActiveRecordMysqlWriteableCheckTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
4
|
test "#check returns a successful result on a good run" do
|
|
6
5
|
check = create_check
|
|
7
6
|
results = check.check
|
|
@@ -12,7 +11,7 @@ class ActiveRecordMysqlWriteableCheckTest < ActiveSupport::TestCase
|
|
|
12
11
|
|
|
13
12
|
test "#check returns a failed result on a failed run" do
|
|
14
13
|
# Return a mock'd object that responds to .entries that returns [[0]]
|
|
15
|
-
ActiveRecord::Base.connection.stubs(:execute).returns(mock().stubs(:entries).returns([[1]]))
|
|
14
|
+
ActiveRecord::Base.connection.stubs(:execute).returns(mock().stubs(:entries).returns([ [ 1 ] ]))
|
|
16
15
|
check = create_check
|
|
17
16
|
results = check.check
|
|
18
17
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class HttpCheckTest < ActiveSupport::TestCase
|
|
4
4
|
test "#run sets success conditions on successful run" do
|
|
@@ -10,7 +10,7 @@ class HttpCheckTest < ActiveSupport::TestCase
|
|
|
10
10
|
assert_equal("Up", results[1])
|
|
11
11
|
assert_equal(true, results[0])
|
|
12
12
|
end
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
test "#run sets failure conditions on a failed run" do
|
|
15
15
|
Net::HTTP.any_instance.stubs(:request).returns(Net::HTTPNotFound.new(1.1, 404, "Not Found"))
|
|
16
16
|
|
|
@@ -30,7 +30,7 @@ class HttpCheckTest < ActiveSupport::TestCase
|
|
|
30
30
|
assert_equal("Down", results[1])
|
|
31
31
|
assert_equal(false, results[0])
|
|
32
32
|
end
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
test "given nil as a url" do
|
|
35
35
|
check = Easymon::HttpCheck.new(nil)
|
|
36
36
|
results = check.check
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class MemcachedCheckTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
4
|
test "#run sets success conditions on successful run" do
|
|
6
5
|
Rails.cache.stubs(:write).returns(true)
|
|
7
6
|
Rails.cache.stubs(:read).returns(1)
|
|
8
7
|
check = Easymon::MemcachedCheck.new(Rails.cache)
|
|
9
8
|
results = check.check
|
|
10
|
-
|
|
9
|
+
|
|
11
10
|
assert_equal("Up", results[1])
|
|
12
11
|
assert_equal(true, results[0])
|
|
13
12
|
end
|
|
14
|
-
|
|
13
|
+
|
|
15
14
|
test "#run sets failure conditions on a failed run" do
|
|
16
15
|
Rails.cache.stubs(:write).raises("boom")
|
|
17
16
|
check = Easymon::MemcachedCheck.new(Rails.cache)
|
|
18
17
|
results = check.check
|
|
19
|
-
|
|
18
|
+
|
|
20
19
|
assert_equal("Down", results[1])
|
|
21
20
|
assert_equal(false, results[0])
|
|
22
21
|
end
|
|
@@ -30,12 +29,11 @@ class MemcachedCheckTest < ActiveSupport::TestCase
|
|
|
30
29
|
end
|
|
31
30
|
|
|
32
31
|
test "fails when passed a cache with no servers" do
|
|
33
|
-
dalli = Dalli::Client.new(
|
|
32
|
+
dalli = Dalli::Client.new("", { namespace: "easymon" })
|
|
34
33
|
check = Easymon::MemcachedCheck.new(dalli)
|
|
35
34
|
results = check.check
|
|
36
35
|
|
|
37
36
|
assert_equal("Down", results[1])
|
|
38
|
-
assert_equal(false, results[0])
|
|
37
|
+
assert_equal(false, results[0])
|
|
39
38
|
end
|
|
40
|
-
|
|
41
39
|
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class MultiActiveRecordCheckTest < ActiveSupport::TestCase
|
|
4
|
+
test "#run sets success conditions on successful run" do
|
|
5
|
+
primary = ActiveRecord::Base.connection
|
|
6
|
+
primary_replica = Easymon::PrimaryReplica.connection
|
|
7
|
+
other_replica = Easymon::OtherReplica.connection
|
|
8
|
+
|
|
9
|
+
check = Easymon::MultiActiveRecordCheck.new do
|
|
10
|
+
{
|
|
11
|
+
"Primary": primary, "PrimaryReplica": primary_replica, "OtherReplica": other_replica
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
results = check.check
|
|
15
|
+
|
|
16
|
+
assert_equal("Primary: Up - PrimaryReplica: Up - OtherReplica: Up", results[1])
|
|
17
|
+
assert_equal(true, results[0])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test "#run sets failed conditions when replica is down" do
|
|
21
|
+
primary = ActiveRecord::Base.connection
|
|
22
|
+
primary_replica = Easymon::PrimaryReplica.connection
|
|
23
|
+
other_replica = Easymon::OtherReplica.connection
|
|
24
|
+
|
|
25
|
+
primary_replica.stubs(:active?).raises("boom")
|
|
26
|
+
|
|
27
|
+
check = Easymon::MultiActiveRecordCheck.new do
|
|
28
|
+
{
|
|
29
|
+
"Primary": primary, "PrimaryReplica": primary_replica, "OtherReplica": other_replica
|
|
30
|
+
}
|
|
31
|
+
end
|
|
32
|
+
results = check.check
|
|
33
|
+
|
|
34
|
+
assert_equal("Primary: Up - PrimaryReplica: Down - OtherReplica: Up", results[1])
|
|
35
|
+
assert_equal(false, results[0])
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test "#run sets failed conditions when primary is down" do
|
|
39
|
+
primary = ActiveRecord::Base.connection
|
|
40
|
+
primary_replica = Easymon::PrimaryReplica.connection
|
|
41
|
+
other_replica = Easymon::OtherReplica.connection
|
|
42
|
+
|
|
43
|
+
primary.stubs(:active?).raises("boom")
|
|
44
|
+
|
|
45
|
+
check = Easymon::MultiActiveRecordCheck.new do
|
|
46
|
+
{
|
|
47
|
+
"Primary": primary, "PrimaryReplica": primary_replica, "OtherReplica": other_replica
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
results = check.check
|
|
51
|
+
|
|
52
|
+
assert_equal("Primary: Down - PrimaryReplica: Up - OtherReplica: Up", results[1])
|
|
53
|
+
assert_equal(false, results[0])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
test "given nil as a config" do
|
|
57
|
+
check = Easymon::MultiActiveRecordCheck.new { }
|
|
58
|
+
results = check.check
|
|
59
|
+
assert_equal("", results[1])
|
|
60
|
+
assert_equal(false, results[0])
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# This would be done in the host app
|
|
65
|
+
module Easymon
|
|
66
|
+
class PrimaryReplica < ActiveRecord::Base
|
|
67
|
+
establish_connection :primary_replica
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class OtherReplica < ActiveRecord::Base
|
|
71
|
+
establish_connection :other_replica
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -1,36 +1,35 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class RedisCheckTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
4
|
test "#run sets success conditions on successful run" do
|
|
6
5
|
Redis.any_instance.stubs(:ping).returns("PONG")
|
|
7
6
|
check = create_check
|
|
8
7
|
results = check.check
|
|
9
|
-
|
|
8
|
+
|
|
10
9
|
assert_equal("Up", results[1])
|
|
11
10
|
assert_equal(true, results[0])
|
|
12
11
|
end
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
test "#run sets failure conditions on a failed run" do
|
|
15
14
|
Redis.any_instance.stubs(:ping).raises("boom")
|
|
16
15
|
check = create_check
|
|
17
16
|
results = check.check
|
|
18
|
-
|
|
17
|
+
|
|
19
18
|
assert_equal("Down", results[1])
|
|
20
19
|
assert_equal(false, results[0])
|
|
21
20
|
end
|
|
22
|
-
|
|
21
|
+
|
|
23
22
|
test "given nil as a config" do
|
|
24
23
|
check = Easymon::RedisCheck.new(nil)
|
|
25
24
|
results = check.check
|
|
26
25
|
assert_equal("Down", results[1])
|
|
27
26
|
assert_equal(false, results[0])
|
|
28
27
|
end
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
|
|
29
|
+
|
|
31
30
|
private
|
|
32
31
|
def create_check
|
|
33
32
|
# Get us a config hash from disk in this case
|
|
34
|
-
Easymon::RedisCheck.new(YAML.load_file(Rails.root.join("config/redis.yml"))[Rails.env].symbolize_keys)
|
|
33
|
+
Easymon::RedisCheck.new(YAML.load_file(Rails.root.join("config/redis.yml"), aliases: true)[Rails.env].symbolize_keys)
|
|
35
34
|
end
|
|
36
35
|
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class RedisWriteableCheckTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
4
|
test "#run sets success conditions on successful run" do
|
|
6
5
|
Redis.any_instance.stubs(:set).returns("OK")
|
|
7
6
|
check = create_check
|
|
@@ -23,6 +22,6 @@ class RedisWriteableCheckTest < ActiveSupport::TestCase
|
|
|
23
22
|
private
|
|
24
23
|
def create_check
|
|
25
24
|
# Get us a config hash from disk in this case
|
|
26
|
-
Easymon::RedisWriteableCheck.new(YAML.load_file(Rails.root.join("config/redis.yml"))[Rails.env].symbolize_keys)
|
|
25
|
+
Easymon::RedisWriteableCheck.new(YAML.load_file(Rails.root.join("config/redis.yml"), aliases: true)[Rails.env].symbolize_keys)
|
|
27
26
|
end
|
|
28
27
|
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class SemaphoreCheckTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
4
|
test "#run sets success conditions on successful run" do
|
|
6
5
|
check = Easymon::SemaphoreCheck.new("config/redis.yml")
|
|
7
6
|
results = check.check
|
|
@@ -9,7 +8,7 @@ class SemaphoreCheckTest < ActiveSupport::TestCase
|
|
|
9
8
|
assert_equal(true, results[0])
|
|
10
9
|
assert_equal("config/redis.yml is in place!", results[1])
|
|
11
10
|
end
|
|
12
|
-
|
|
11
|
+
|
|
13
12
|
test "#run sets failure conditions on a failed run" do
|
|
14
13
|
check = Easymon::SemaphoreCheck.new("config/file-does-not-exist")
|
|
15
14
|
results = check.check
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class SplitActiveRecordCheckTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
4
|
test "#run sets success conditions on successful run" do
|
|
6
5
|
primary = ActiveRecord::Base.connection
|
|
7
|
-
Easymon::
|
|
8
|
-
replica = Easymon::Base.connection
|
|
6
|
+
replica = Easymon::Replica.connection
|
|
9
7
|
|
|
10
|
-
check = Easymon::SplitActiveRecordCheck.new { [primary, replica] }
|
|
8
|
+
check = Easymon::SplitActiveRecordCheck.new { [ primary, replica ] }
|
|
11
9
|
|
|
12
10
|
results = check.check
|
|
13
11
|
|
|
@@ -17,12 +15,11 @@ class SplitActiveRecordCheckTest < ActiveSupport::TestCase
|
|
|
17
15
|
|
|
18
16
|
test "#run sets failed conditions when replica is down" do
|
|
19
17
|
primary = ActiveRecord::Base.connection
|
|
20
|
-
Easymon::
|
|
21
|
-
replica = Easymon::Base.connection
|
|
18
|
+
replica = Easymon::Replica.connection
|
|
22
19
|
|
|
23
20
|
replica.stubs(:active?).raises("boom")
|
|
24
21
|
|
|
25
|
-
check = Easymon::SplitActiveRecordCheck.new { [primary, replica] }
|
|
22
|
+
check = Easymon::SplitActiveRecordCheck.new { [ primary, replica ] }
|
|
26
23
|
results = check.check
|
|
27
24
|
|
|
28
25
|
assert_equal("Primary: Up - Replica: Down", results[1])
|
|
@@ -31,12 +28,11 @@ class SplitActiveRecordCheckTest < ActiveSupport::TestCase
|
|
|
31
28
|
|
|
32
29
|
test "#run sets failed conditions when primary is down" do
|
|
33
30
|
primary = ActiveRecord::Base.connection
|
|
34
|
-
Easymon::
|
|
35
|
-
replica = Easymon::Base.connection
|
|
31
|
+
replica = Easymon::Replica.connection
|
|
36
32
|
|
|
37
33
|
primary.stubs(:active?).raises("boom")
|
|
38
34
|
|
|
39
|
-
check = Easymon::SplitActiveRecordCheck.new { [primary, replica] }
|
|
35
|
+
check = Easymon::SplitActiveRecordCheck.new { [ primary, replica ] }
|
|
40
36
|
results = check.check
|
|
41
37
|
|
|
42
38
|
assert_equal("Primary: Down - Replica: Up", results[1])
|
|
@@ -53,18 +49,7 @@ end
|
|
|
53
49
|
|
|
54
50
|
# This would be done in the host app
|
|
55
51
|
module Easymon
|
|
56
|
-
class
|
|
57
|
-
|
|
58
|
-
if spec
|
|
59
|
-
super
|
|
60
|
-
elsif config = Easymon.database_configuration
|
|
61
|
-
super config
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def database_configuration
|
|
66
|
-
env = "#{Rails.env}_replica"
|
|
67
|
-
YAML.load_file(Rails.root.join('config/database.yml'))[env]
|
|
68
|
-
end
|
|
52
|
+
class Replica < ActiveRecord::Base
|
|
53
|
+
establish_connection :primary_replica
|
|
69
54
|
end
|
|
70
55
|
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class TrafficEnabledCheckTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
4
|
test "#check sets success conditions on successful run" do
|
|
6
5
|
# Using a file we know exists in the test
|
|
7
6
|
check = Easymon::TrafficEnabledCheck.new("config/redis.yml")
|
|
@@ -10,7 +9,7 @@ class TrafficEnabledCheckTest < ActiveSupport::TestCase
|
|
|
10
9
|
assert_equal(true, results[0])
|
|
11
10
|
assert_equal("ENABLED", results[1])
|
|
12
11
|
end
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
test "#check sets failure conditions on a failed run" do
|
|
15
14
|
check = Easymon::TrafficEnabledCheck.new("config/file-does-not-exist")
|
|
16
15
|
results = check.check
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
require
|
|
1
|
+
require "test_helper"
|
|
2
2
|
|
|
3
3
|
class RepositoryTest < ActiveSupport::TestCase
|
|
4
|
-
|
|
5
4
|
test "we can add a check to the repository" do
|
|
6
5
|
Easymon::Repository.add("database", Easymon::ActiveRecordCheck.new(ActiveRecord::Base))
|
|
7
6
|
check = Easymon::Repository.fetch("database")
|
|
@@ -49,4 +48,4 @@ class RepositoryTest < ActiveSupport::TestCase
|
|
|
49
48
|
|
|
50
49
|
assert check[:check].instance_of? Easymon::ActiveRecordCheck
|
|
51
50
|
end
|
|
52
|
-
end
|
|
51
|
+
end
|