vision_mate 0.1.3 → 0.1.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/lib/vision_mate/telnet.rb +16 -3
- data/lib/vision_mate/version.rb +1 -1
- data/spec/vision_mate/telnet_spec.rb +20 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f81c4d5d557338d38d6884e03ac5a3d1b55d3e3
|
4
|
+
data.tar.gz: f23712ebbdf2179d3ec404a33710a0a534acf476
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32ae55647d4b839b112b7101c055642235e2ce7e2c3158b47402f205b248a66677cf1d0f1e7cd431b401696474491a2a321155b7928703764258d82be9cafa6e
|
7
|
+
data.tar.gz: 6cb1fb5ab28c3537035d3916469bd7fdf37d53b277b3f17c619a965e3b0d149057f1daf0a63515fb131335c3c23efa652407f713d30f48256a3c106e5085a181
|
data/lib/vision_mate/telnet.rb
CHANGED
@@ -9,11 +9,10 @@ module VisionMate
|
|
9
9
|
|
10
10
|
# For ruby 1.9 compatibility
|
11
11
|
class Net::OpenTimeout; end
|
12
|
+
class Net::ReadTimeout; end
|
12
13
|
|
13
14
|
def self.connect(host, port, telnet_class = Net::Telnet)
|
14
|
-
@telnet_connection ||= telnet_class
|
15
|
-
"Host" => host, "Port" => port, "Timeout" => Configuration.timeout
|
16
|
-
)
|
15
|
+
@telnet_connection ||= verified_connection host, port, telnet_class
|
17
16
|
new(@telnet_connection)
|
18
17
|
rescue Net::OpenTimeout, Timeout::Error
|
19
18
|
raise CouldNotConnect, "Failed to connect to #{host}:#{port}"
|
@@ -21,6 +20,20 @@ module VisionMate
|
|
21
20
|
raise BadHostNameOrPort, "Malformed host name or port"
|
22
21
|
end
|
23
22
|
|
23
|
+
def self.verified_connection(host, port, telnet_class)
|
24
|
+
telnet_connection = telnet_class.new(
|
25
|
+
"Host" => host, "Port" => port, "Timeout" => Configuration.timeout
|
26
|
+
)
|
27
|
+
telnet_connection.cmd("String" => "L", "Match" => /OK/)
|
28
|
+
|
29
|
+
telnet_connection
|
30
|
+
rescue Net::OpenTimeout, Timeout::Error => e
|
31
|
+
retries ||= 0
|
32
|
+
raise e if retries == 5
|
33
|
+
retries += 1
|
34
|
+
retry
|
35
|
+
end
|
36
|
+
|
24
37
|
def initialize(telnet_connection)
|
25
38
|
self.telnet_connection = telnet_connection
|
26
39
|
set_scanner_to_manual
|
data/lib/vision_mate/version.rb
CHANGED
@@ -9,6 +9,23 @@ describe VisionMate::Telnet do
|
|
9
9
|
let(:telnet_connection) { double "telnet_connection" }
|
10
10
|
before { VisionMate::Telnet.instance_variable_set(:@telnet_connection, nil) }
|
11
11
|
|
12
|
+
describe ".verified_connection" do
|
13
|
+
context "ruby 1.9.X conneciton will often fail to get scanner status" do
|
14
|
+
it "recreates the connection if the connection fails" do
|
15
|
+
telnet_connection.stub(:cmd).with(hash_including("String" => "L"))
|
16
|
+
.and_raise(Timeout::Error.new("Telnet connection failed on status"))
|
17
|
+
|
18
|
+
MockTelnet.should_receive(:new)
|
19
|
+
.with(hash_including("Host" => uri.host, "Port" => uri.port))
|
20
|
+
.at_least(:twice).and_return(telnet_connection)
|
21
|
+
|
22
|
+
expect {
|
23
|
+
VisionMate::Telnet.verified_connection(uri.host, uri.port, MockTelnet)
|
24
|
+
}.to raise_error(Timeout::Error)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
12
29
|
describe ".connect" do
|
13
30
|
it "connects to telnet using a host and port" do
|
14
31
|
MockTelnet.should_receive(:new)
|
@@ -34,6 +51,9 @@ describe VisionMate::Telnet do
|
|
34
51
|
|
35
52
|
it "sets the scanner to manual" do
|
36
53
|
MockTelnet.stub(new: telnet_connection)
|
54
|
+
telnet_connection.should_receive(:cmd).with(
|
55
|
+
"String" => "L", "Match" => /OK/
|
56
|
+
)
|
37
57
|
telnet_connection.should_receive(:cmd).with(
|
38
58
|
"String" => "M0", "Match" => /OK/
|
39
59
|
)
|