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
path: root/spec
diff options
context:
space:
mode:
authorBenjamin Neff <benjamin@coding4coffee.ch>2022-07-24 18:22:41 +0300
committerBenjamin Neff <benjamin@coding4coffee.ch>2022-07-24 18:22:41 +0300
commita661b0b608ce901f053421578dad815fd7c34002 (patch)
treecc2ecd378caa36227bcbab82fba8ebc8bae2a1ae /spec
parent429a47d64d7753f14be454a519d198ca53ee7c7a (diff)
parent646685b42cd4cf14f6431633ef1b9f5c2d80ccfc (diff)
Merge branch 'next-minor' into develop
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/connection_tester_spec.rb13
-rw-r--r--spec/models/pod_spec.rb30
2 files changed, 29 insertions, 14 deletions
diff --git a/spec/lib/connection_tester_spec.rb b/spec/lib/connection_tester_spec.rb
index 671fec860..d665dd717 100644
--- a/spec/lib/connection_tester_spec.rb
+++ b/spec/lib/connection_tester_spec.rb
@@ -94,6 +94,11 @@ describe ConnectionTester do
expect { tester.request }.to raise_error(ConnectionTester::HTTPFailure)
end
+ it "receives a 502 bad gateway" do
+ stub_request(:get, url).to_return(status: 502, body: "Bad Gateway!")
+ expect { tester.request }.to raise_error(ConnectionTester::HTTPFailure)
+ end
+
it "cannot connect" do
stub_request(:get, url).to_raise(Faraday::ConnectionFailed.new("Error!"))
expect { tester.request }.to raise_error(ConnectionTester::NetFailure)
@@ -172,6 +177,14 @@ describe ConnectionTester do
expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
end
+ it "handles timeout gracefully" do
+ ni_wellknown = {links: [{rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"}]}
+ stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
+ .to_return(status: 200, body: JSON.generate(ni_wellknown))
+ stub_request(:get, "#{url}/nodeinfo/1.0").to_raise(Faraday::TimeoutError.new)
+ expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
+ end
+
it "handles a invalid jrd document gracefully" do
invalid_wellknown = {links: {rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"}}
stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
diff --git a/spec/models/pod_spec.rb b/spec/models/pod_spec.rb
index b7386f7a6..ac5520c73 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 = FactoryBot.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