build_watcher 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.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.1.4 / 2010-04-22 / 4530cc52ffee5af001bb2c167714cc8c6724ac15
2
+
3
+ * Adding retries for failed serial IO attempts
4
+
1
5
  === 0.1.3 / 2010-04-22
2
6
 
3
7
  * Updated hoe spec so dependencies work correctly
data/lib/build_watcher.rb CHANGED
@@ -6,7 +6,7 @@ require 'build_watcher/message'
6
6
  require 'serialport'
7
7
 
8
8
  module BuildWatcher
9
- VERSION = '0.1.3'
9
+ VERSION = '0.1.4'
10
10
 
11
11
  class AppropriateMessageTypeNotFound < StandardError; end
12
12
  end
@@ -1,5 +1,6 @@
1
1
  module BuildWatcher
2
2
  class ZigbeeDevice
3
+ MAX_SERIAL_DEVICE_ATTEMPTS = 5
3
4
  def initialize(device)
4
5
  @device = device
5
6
  @connection = "USE #serial_device INSTEAD OF CONNECTION DIRECTLY"
@@ -56,7 +57,6 @@ module BuildWatcher
56
57
  raise AppropriateMessageTypeNotFound, "No 'project info' message type found on serial buffer."
57
58
  end
58
59
 
59
- #Struct.new("ProjectInfo", :public_key, :private_key)
60
60
  Struct::ProjectInfo.new(*project_info.split(/#{Message::MSG_SEP}/).slice(1,3))
61
61
  end
62
62
 
@@ -71,7 +71,15 @@ module BuildWatcher
71
71
  def serial_device(&block)
72
72
  @connection = SerialPort.new(@device, 9600)
73
73
  @connection.read_timeout = -1
74
- yield @connection
74
+
75
+ i = 1
76
+ begin
77
+ yield @connection
78
+ rescue AppropriateMessageTypeNotFound => e
79
+ i += 1
80
+ retry unless i > MAX_SERIAL_DEVICE_ATTEMPTS
81
+ raise e
82
+ end
75
83
  ensure
76
84
  @connection.close
77
85
  end
@@ -2,14 +2,17 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require 'update_listeners/cli'
3
3
 
4
4
  describe UpdateListeners::CLI, "execute" do
5
+ def execute_script
6
+ UpdateListeners::CLI.execute(STDOUT, ['-d', '/dev/some_device'])
7
+ end
8
+
5
9
  before(:each) do
6
- @serial_port = FakeSerialPort.new
7
- @zgb_device = BuildWatcher::ZigbeeDevice.new('/dev/something')
10
+ @zigbee_device = BuildWatcher::ZigbeeDevice.new('/dev/something')
8
11
  @project = CodeFumes::Project.new(:public_key => 'pub', :private_key => 'priv')
9
12
  @project.stub!(:build_status).and_return("running")
10
13
 
11
- SerialPort.stub!(:new).and_return(@serial_port)
12
- BuildWatcher::ZigbeeDevice.stub!(:new).and_return(@zgb_device)
14
+ SerialPort.stub!(:new).and_return(FakeSerialPort.new)
15
+ BuildWatcher::ZigbeeDevice.stub!(:new).and_return(@zigbee_device)
13
16
  CodeFumes::Project.stub!(:find).and_return(@project)
14
17
  end
15
18
 
@@ -21,25 +24,25 @@ describe UpdateListeners::CLI, "execute" do
21
24
  end
22
25
 
23
26
  it "requests the quantity of projects from the serial device" do
24
- @zgb_device.should_receive(:project_quantity).and_return(@project_quantity)
25
- UpdateListeners::CLI.execute(STDOUT, ["-d", "/dev/something"])
27
+ @zigbee_device.should_receive(:project_quantity).and_return(@project_quantity)
28
+ execute_script
26
29
  end
27
30
 
28
31
  it "requests the project information from the serial device for each project" do
29
32
  project_info = OpenStruct.new({:private_key => 'priv', :public_key => 'pub'})
30
- @zgb_device.should_receive(:project_info).exactly(3).times.and_return(project_info)
31
- UpdateListeners::CLI.execute(STDOUT, [])
33
+ @zigbee_device.should_receive(:project_info).exactly(3).times.and_return(project_info)
34
+ execute_script
32
35
  end
33
36
 
34
37
  it "it requests the project build status from CodeFumes for each project" do
35
38
  CodeFumes::Project.should_receive(:find).exactly(@project_quantity).times.and_return(@project)
36
39
  @project.should_receive(:build_status).exactly(@project_quantity).times.and_return('running')
37
- UpdateListeners::CLI.execute(STDOUT, [])
40
+ execute_script
38
41
  end
39
42
 
40
43
  it "it broadcasts the status of each project via the serial device" do
41
- @zgb_device.should_receive(:broadcast_status).exactly(@project_quantity).times
42
- UpdateListeners::CLI.execute(STDOUT, [])
44
+ @zigbee_device.should_receive(:broadcast_status).exactly(@project_quantity).times
45
+ execute_script
43
46
  end
44
47
  end
45
48
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 3
9
- version: 0.1.3
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tom Kersten