Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Neff <benjamin@coding4coffee.ch>2022-07-23 18:58:09 +0300
committerBenjamin Neff <benjamin@coding4coffee.ch>2022-07-24 18:17:51 +0300
commitb29675fead857cf6370d5ad70cac97f0d975ec3a (patch)
tree6f329710f1ada4f385ba594171995d77f9ba0a4a
parenteb1c57151183cfceb87c06fc67f3293d83d2cb47 (diff)
Remove error if there was no error anymore
also add pod uri when logging offline pods ... just having a bunch of "OFFLINE" log messages doesn't help at all.
-rw-r--r--app/models/pod.rb4
-rw-r--r--spec/models/pod_spec.rb30
2 files changed, 18 insertions, 16 deletions
diff --git a/app/models/pod.rb b/app/models/pod.rb
index c64bf4ce2..08692f280 100644
--- a/app/models/pod.rb
+++ b/app/models/pod.rb
@@ -114,7 +114,7 @@ class Pod < ApplicationRecord
def update_from_result(result)
self.status = status_from_result(result)
update_offline_since
- logger.warn "OFFLINE #{result.failure_message}" if offline?
+ logger.warn "#{uri} OFFLINE: #{result.failure_message}" if offline?
attributes_from_result(result)
touch(:checked_at)
@@ -125,7 +125,7 @@ class Pod < ApplicationRecord
def attributes_from_result(result)
self.ssl ||= result.ssl
- self.error = result.failure_message[0..254] if result.error?
+ self.error = result.error? ? result.failure_message[0..254] : nil
self.software = result.software_version[0..254] if result.software_version.present?
self.response_time = result.rt
end
diff --git a/spec/models/pod_spec.rb b/spec/models/pod_spec.rb
index a8001d3a8..6ad265b2f 100644
--- a/spec/models/pod_spec.rb
+++ b/spec/models/pod_spec.rb
@@ -143,31 +143,28 @@ describe Pod, type: :model do
describe "#test_connection!" do
before do
@pod = FactoryGirl.create(:pod)
- @result = double("result")
@now = Time.zone.now
- allow(@result).to receive(:rt) { 123 }
- allow(@result).to receive(:software_version) { "diaspora a.b.c.d" }
- allow(@result).to receive(:failure_message) { "hello error!" }
+ @result = ConnectionTester::Result.new
+ @result.rt = 123
+ @result.software_version = "diaspora a.b.c.d"
+ @result.error = ConnectionTester::NetFailure.new("hello error!")
expect(ConnectionTester).to receive(:check).at_least(:once).and_return(@result)
end
it "updates the connectivity values" do
- allow(@result).to receive(:error)
- allow(@result).to receive(:error?)
+ @result.error = nil
@pod.test_connection!
expect(@pod.status).to eq("no_errors")
- expect(@pod.offline?).to be_falsy
+ expect(@pod.offline?).to be_falsey
expect(@pod.response_time).to eq(123)
expect(@pod.checked_at).to be_within(1.second).of @now
end
it "resets the scheduled_check flag" do
- allow(@result).to receive(:error)
- allow(@result).to receive(:error?)
- @pod.update_column(:scheduled_check, true)
+ @pod.update(scheduled_check: true)
@pod.test_connection!
@@ -175,17 +172,22 @@ describe Pod, type: :model do
end
it "handles a failed check" do
- expect(@result).to receive(:error?).at_least(:once) { true }
- expect(@result).to receive(:error).at_least(:once) { ConnectionTester::NetFailure.new }
@pod.test_connection!
expect(@pod.offline?).to be_truthy
expect(@pod.offline_since).to be_within(1.second).of @now
end
+ it "removes the error message when there was no error" do
+ @pod.update(error: "old error message")
+
+ @result.error = nil
+ @pod.test_connection!
+
+ expect(@pod.error).to be_nil
+ end
+
it "preserves the original offline timestamp" do
- expect(@result).to receive(:error?).at_least(:once) { true }
- expect(@result).to receive(:error).at_least(:once) { ConnectionTester::NetFailure.new }
@pod.test_connection!
expect(@pod.offline_since).to be_within(1.second).of @now