volt 0.9.4.pre5 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 336fa7176c4a60f3ea2757f0e78917d40f0faee7
4
- data.tar.gz: 2911281e8bea55eca1fdc94568452f75012ee0aa
3
+ metadata.gz: b818f9b2d02006b327aab20af6df7bb258b94ce6
4
+ data.tar.gz: 186ea61b4516a781fb3bac6b800e7e10a3bf1bef
5
5
  SHA512:
6
- metadata.gz: cb4724687642e194094184b6cd515da2fc1f78ff273ce2049d727dc1c3ea7f3fa07756827bb6b167545aea7f0cad83e40941cf0588a173c847901bd6359b7507
7
- data.tar.gz: cb51999eb63a80ad0606e457457325a22fadcba5ec7453b1068d227885e65fec1de5fc4f063b6633fab8d310d92b6ae8976013526f2ec23afb6c0d276a2aeb73
6
+ metadata.gz: 0a3898e2d3cab1dfe549cd34538f74df0ba5e9dc0587f94a426480badc4d606a67a51349d9c2f07a2a36881213699ed58d8fe5c04eab9d51a8e95cfecf901e45
7
+ data.tar.gz: 235f5228b227b80a07179c6f8ac309474e7dbeb209b48318c324c970a5d93810c67c76aa827871138eca29767f96d4bea30413e75081a62f0bb82bd06d53b2e5
data/CHANGELOG.md CHANGED
@@ -24,6 +24,8 @@ the base collections will now be called "Repositories" or "Repo's" for short. T
24
24
  - fixed issue with user password change
25
25
  - fix issue storing Time in a hash
26
26
  - fixed issue with local_store not persisting in some cases
27
+ - runners now block until messages have propigated to the message bus and updates have been pushed.
28
+ - upgraded some dependency gems to fix a conflict
27
29
 
28
30
  ## 0.9.3
29
31
  [0.9.3 Update Blog Post](http://blog.voltframework.com/post/121128931859/0-9-3-stuff-you-asked-for)
@@ -17,6 +17,8 @@ validate login_field, unique: true, length: 8
17
17
  validate :email, email: true
18
18
  ```
19
19
 
20
+ If you are using $page, it has been removed and you can now access any collection (which we're now calling repo's) via ```Volt.current_app.store``` or ```.page```, ```.params```, etc...
21
+
20
22
  # 0.9.2 to 0.9.3
21
23
 
22
24
  Upgrading from 0.9.2 should be fairly simple, just implement the following:
data/lib/volt/cli.rb CHANGED
@@ -32,6 +32,7 @@ module Volt
32
32
  say "Your app is now ready in the #{name} directory.", :green
33
33
  say ""
34
34
  say "To run your app: "
35
+ say ""
35
36
  say " cd #{name}"
36
37
  say " bundle exec volt server"
37
38
  end
@@ -5,10 +5,13 @@ module Volt
5
5
  class Runner
6
6
  # Runs the ruby file at the path
7
7
  def self.run_file(path)
8
- Volt.boot(Dir.pwd)
8
+ app = Volt.boot(Dir.pwd)
9
9
 
10
10
  # Require in the file at path
11
11
  require './' + path
12
+
13
+ # disconnect from the message bus and flush all messages
14
+ app.message_bus.disconnect!
12
15
  end
13
16
  end
14
17
  end
@@ -322,9 +322,8 @@ module Volt
322
322
  promise
323
323
  end
324
324
 
325
-
326
325
  # We need to setup the proxy methods below where they are defined.
327
- proxy_with_load :[], :size, :last, :reverse, :all, :to_a
326
+ proxy_with_load :[], :size, :last, :reverse, :all, :to_a, :empty?
328
327
 
329
328
  end
330
329
  end
@@ -47,6 +47,11 @@ module Volt
47
47
  def publish(channel_name, message)
48
48
  raise "Not implemented"
49
49
  end
50
+
51
+ # waits for all messages to be flushed and closes connections
52
+ def disconnect!
53
+ raise "Not implemented"
54
+ end
50
55
  end
51
56
  end
52
57
  end
@@ -71,9 +71,9 @@ module Volt
71
71
  setup_peer_server
72
72
  start_tracker
73
73
 
74
- Thread.new do
75
- sleep 1
74
+ @peer_connection_threads = []
76
75
 
76
+ @connect_thread = Thread.new do
77
77
  connect_to_peers
78
78
  end
79
79
  else
@@ -121,22 +121,20 @@ module Volt
121
121
  peers.each do |peer|
122
122
  # Start connecting to all at the same time. Since most will connect or
123
123
  # timeout, this is the desired behaviour.
124
- Thread.new do
125
- # sometimes we get nil peers for some reason
126
- if peer
127
- peer_connection = PeerConnection.connect_to(self, peer._ips, peer._port)
128
-
129
- if peer_connection
130
- add_peer_connection(peer_connection)
131
- else
132
- # remove if not alive anymore.
133
- still_alive?(peer._server_id)
134
- end
135
- end
124
+ # sometimes we get nil peers for some reason
125
+ if peer
126
+ peer_connection = PeerConnection.new(nil, peer._ips, peer._port, self, false, peer._server_id)
127
+ add_peer_connection(peer_connection)
136
128
  end
137
129
  end
138
130
  end
139
131
 
132
+ # Blocks until all peers have connected or timed out.
133
+ def disconnect!
134
+ # Wait for disconnect on each
135
+ @peer_connections.keys.each(&:disconnect!)
136
+ end
137
+
140
138
  def add_peer_connection(peer_connection)
141
139
  @peer_connections[peer_connection] = true
142
140
  @peer_server_ids[peer_connection.peer_server_id] = true
@@ -167,7 +165,7 @@ module Volt
167
165
 
168
166
  if peer_server_ids[peer_id]
169
167
  # Peer is already connected somewhere else, remove connection
170
- peer.disconnect
168
+ peer.disconnect!
171
169
 
172
170
  # remove the connection
173
171
  @peer_connections.delete(peer)
@@ -14,23 +14,47 @@ module Volt
14
14
  # The server id for the connected server
15
15
  attr_reader :peer_server_id, :socket
16
16
 
17
- def initialize(socket, ip, port, message_bus, server=false)
17
+ def initialize(socket, ips, port, message_bus, server=false, peer_server_id=nil)
18
18
  @message_bus = message_bus
19
- @ip = ip
19
+ @ips = ips
20
20
  @port = port
21
21
  @server = server
22
22
  @socket = socket
23
23
  @server_id = message_bus.server_id
24
+ @peer_server_id = peer_server_id
24
25
  @message_queue = SizedQueue.new(500)
25
26
  @reconnect_mutex = Mutex.new
26
27
 
27
28
  # The encoder handles things like formatting and encryption
28
29
  @message_encoder = MessageEncoder.new
29
30
 
31
+ @worker_thread = Thread.new do
32
+ # Connect to the remote if this PeerConnection was created from the
33
+ # active_volt_instances collection.
34
+ #
35
+ # reconnect! will setup the @socket
36
+ if @socket || reconnect!
37
+ # Announce checks to make sure we didn't connect to ourselves
38
+ if announce
39
+ # Setp the listen thread.
40
+ @listen_thread = Thread.new do
41
+ # Listen for messages in a new thread
42
+ listen
43
+ end
44
+
45
+ run_worker
46
+ end
30
47
 
48
+ end
49
+ end
50
+ end
51
+
52
+ # Tells the other connect its server_id. In the event we connected to
53
+ # ourself, close.
54
+ def announce
31
55
  failed = false
32
56
  begin
33
- if server
57
+ if @server
34
58
  # Wait for announcement
35
59
  @peer_server_id = @message_encoder.receive_message(@socket)
36
60
  @message_encoder.send_message(@socket, @server_id)
@@ -47,25 +71,19 @@ module Volt
47
71
  @message_bus.remove_duplicate_connections
48
72
 
49
73
  # Don't connect to self
50
- if @failed || @peer_server_id == @server_id
74
+ if failed || @peer_server_id == @server_id
51
75
  # Close the connection
52
- close
53
- return
54
- end
55
-
56
- @listen_thread = Thread.new do
57
- # Listen for messages in a new thread
58
- listen
76
+ disconnect!
77
+ return false
59
78
  end
60
79
 
61
- @worker_thread = Thread.new do
62
- run_worker
63
- end
80
+ # Success
81
+ return true
64
82
  end
65
83
 
66
- # Close the socket, kill worker threads, and remove from
67
- # message_bus's peer_connections
68
- def disconnect
84
+ # Close the socket, kill listener thread, wait for worker thread to send
85
+ # all messages, and remove from message_bus's peer_connections.
86
+ def disconnect!
69
87
  @disconnected = true
70
88
  @message_queue.push(:QUIT)
71
89
  begin
@@ -74,8 +92,11 @@ module Volt
74
92
  # Ignore close error, since we may not be connected
75
93
  end
76
94
 
77
- @listen_thread.kill
78
- @worker_thread.kill
95
+ @listen_thread.kill if @listen_thread
96
+ # @worker_thread.kill
97
+
98
+ # Wait for the worker to publish all messages
99
+ @worker_thread.join if Thread.current != @worker_thread
79
100
 
80
101
  @message_bus.remove_peer_connection(self)
81
102
  end
@@ -102,12 +123,10 @@ module Volt
102
123
  end
103
124
  end
104
125
 
105
-
106
126
  def listen
107
127
  loop do
108
128
  begin
109
129
  while (message = @message_encoder.receive_message(@socket))
110
- # puts "Message: #{message.inspect}"
111
130
  break if @disconnected
112
131
  @message_bus.handle_message(message)
113
132
  end
@@ -129,45 +148,50 @@ module Volt
129
148
  end
130
149
  end
131
150
 
151
+ private
152
+
153
+ def still_alive?
154
+ @message_bus.still_alive?(@peer_server_id)
155
+ end
132
156
 
133
157
  # Because servers can have many ips, we try the various ip's until we are
134
158
  # able to connect to one.
135
- # @param [Array] an array of ip strings
136
- def self.connect_to(message_bus, ips, port)
137
- ips.split(',').each do |ip|
159
+ def connect!
160
+ @ips.split(',').each do |ip|
138
161
  begin
139
- socket = SocketWithTimeout.new(ip, port, CONNECT_TIMEOUT)
140
- return PeerConnection.new(socket, ip, port, message_bus)
141
- rescue Errno::ECONNREFUSED, Errno::ENETUNREACH, Errno::ETIMEDOUT => e
162
+ socket = SocketWithTimeout.new(ip, @port, CONNECT_TIMEOUT)
163
+
164
+ @socket = socket
165
+
166
+ return
167
+ rescue Errno::ECONNREFUSED, Errno::ENETUNREACH, Errno::ETIMEDOUT, SocketError => e
142
168
  # Unable to connect, next
143
169
  next
144
170
  end
145
171
  end
146
172
 
147
- return false
148
- end
149
-
150
- private
151
-
152
- def still_alive?
153
- @message_bus.still_alive?(@peer_server_id)
173
+ raise Errno::ECONNREFUSED
154
174
  end
155
175
 
156
176
  def reconnect!
177
+ # Stop trying to reconnect if we are disconnected
178
+ return false if @disconnected
179
+
157
180
  # Don't reconnect on the server instances
158
181
  return false if @server
182
+
159
183
  @reconnect_mutex.synchronize do
160
184
  loop do
161
185
  # Server is no longer reporting as alive, give up on reconnecting
162
186
  unless still_alive?
163
187
  # Unable to connect, let peer connection die
164
- disconnect
188
+ disconnect!
165
189
  return false
166
190
  end
167
191
 
168
192
  failed = false
169
193
  begin
170
- socket = SocketWithTimeout.new(@ip, @port, CONNECT_TIMEOUT)
194
+ connect!
171
195
  rescue Errno::ECONNREFUSED, SocketError => e
172
196
  # Unable to cnnect, wait 10, try again
173
197
  sleep 10
data/lib/volt/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Volt
2
2
  module Version
3
- STRING = '0.9.4.pre5'
3
+ STRING = '0.9.4'
4
4
  end
5
5
  end
@@ -94,6 +94,7 @@ module Volt
94
94
  def load_stored_page
95
95
  if Volt.client?
96
96
  if `sessionStorage`
97
+ page = Volt.current_app.page
97
98
  page_obj_str = nil
98
99
 
99
100
  `page_obj_str = sessionStorage.getItem('___page');`
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ # TODO: ArrayModel and Model specs are mixed in model_spec atm. Need to move
4
+ # ArrayModel specs here.
5
+ describe Volt::ArrayModel do
6
+ unless RUBY_PLATFORM == 'opal'
7
+ it 'should return a Promise for empty? on store' do
8
+ expect(store._posts.empty?.class).to eq(Promise)
9
+ end
10
+ end
11
+
12
+ it 'should reactively update .empty? when an item is added to a collection' do
13
+ Volt::Computation.flush!
14
+ count = 0
15
+ comp = -> { the_page._names.empty? ; count += 1 }.watch!
16
+
17
+ expect(count).to eq(1)
18
+
19
+ the_page._names.create({name: 'Bob'})
20
+
21
+ Volt::Computation.flush!
22
+ expect(count).to eq(2)
23
+ end
24
+ end
@@ -24,11 +24,11 @@ unless RUBY_PLATFORM == 'opal'
24
24
  end
25
25
 
26
26
  it 'should on server' do
27
- Volt::MessageBus::PeerConnection.new(@socket, nil, nil, @bus, true)
27
+ Volt::MessageBus::PeerConnection.new(@socket, nil, nil, @bus, true).announce
28
28
  end
29
29
 
30
30
  it 'should pass the server_id back and forth to client' do
31
- Volt::MessageBus::PeerConnection.new(@socket, nil, nil, @bus)
31
+ Volt::MessageBus::PeerConnection.new(@socket, nil, nil, @bus).announce
32
32
  end
33
33
  end
34
34
 
@@ -89,7 +89,7 @@ unless RUBY_PLATFORM == 'opal'
89
89
 
90
90
  conn2 = nil
91
91
  threads << Thread.new do
92
- conn2 = Volt::MessageBus::PeerConnection.new(@client, nil, nil, bus2)
92
+ conn2 = Volt::MessageBus::PeerConnection.new(@client, nil, nil, bus2, false, bus2.server_id)
93
93
  end
94
94
 
95
95
  threads.each(&:join)
@@ -103,8 +103,8 @@ unless RUBY_PLATFORM == 'opal'
103
103
 
104
104
  expect(responses2).to eq(['test message'])
105
105
 
106
- conn1.disconnect
107
- conn2.disconnect
106
+ conn1.disconnect!
107
+ conn2.disconnect!
108
108
 
109
109
  end
110
110
  end
@@ -6,12 +6,6 @@ unless RUBY_PLATFORM == 'opal'
6
6
  @stack = Volt::MiddlewareStack.new
7
7
  end
8
8
 
9
- it 'should set_app' do
10
- app = double('rack app')
11
- @stack.set_app(app)
12
- expect(@stack.instance_variable_get('@app')).to eq(app)
13
- end
14
-
15
9
  it 'should insert a middleware at the end of the stack when calling use' do
16
10
  middleware1 = double('middleware1')
17
11
  @stack.use(middleware1, 'arg1')
data/volt.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'rack', '~> 1.5.0'
25
25
  spec.add_dependency 'sprockets-sass', '~> 1.0.0'
26
26
  spec.add_dependency 'sass', '~> 3.2.5'
27
- spec.add_dependency 'listen', '~> 2.8.0'
27
+ spec.add_dependency 'listen', '~> 3.0.1'
28
28
  spec.add_dependency 'configurations', '~> 2.0.0.pre'
29
29
  spec.add_dependency 'opal', '~> 0.7.2'
30
30
  spec.add_dependency 'bundler', '>= 1.5'
@@ -50,7 +50,7 @@ Gem::Specification.new do |spec|
50
50
  spec.add_development_dependency 'thin', '~> 1.6.3'
51
51
  spec.add_development_dependency 'coveralls', '~> 0.8.1'
52
52
 
53
- spec.add_development_dependency 'guard', '2.6.0' # bug in current guard
53
+ spec.add_development_dependency 'guard', '2.12.7' # bug in current guard
54
54
  spec.add_development_dependency 'guard-rspec', '~> 4.3.0'
55
55
  spec.add_development_dependency 'rake', '~> 10.0.4'
56
56
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: volt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4.pre5
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Stout
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-02 00:00:00.000000000 Z
11
+ date: 2015-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 2.8.0
89
+ version: 3.0.1
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 2.8.0
96
+ version: 3.0.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: configurations
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -296,14 +296,14 @@ dependencies:
296
296
  requirements:
297
297
  - - '='
298
298
  - !ruby/object:Gem::Version
299
- version: 2.6.0
299
+ version: 2.12.7
300
300
  type: :development
301
301
  prerelease: false
302
302
  version_requirements: !ruby/object:Gem::Requirement
303
303
  requirements:
304
304
  - - '='
305
305
  - !ruby/object:Gem::Version
306
- version: 2.6.0
306
+ version: 2.12.7
307
307
  - !ruby/object:Gem::Dependency
308
308
  name: guard-rspec
309
309
  requirement: !ruby/object:Gem::Requirement
@@ -673,6 +673,7 @@ files:
673
673
  - spec/integration/url_spec.rb
674
674
  - spec/integration/user_spec.rb
675
675
  - spec/integration/yield_spec.rb
676
+ - spec/models/array_model_spec.rb
676
677
  - spec/models/associations_spec.rb
677
678
  - spec/models/buffer_spec.rb
678
679
  - spec/models/dirty_spec.rb
@@ -721,7 +722,7 @@ files:
721
722
  - spec/server/message_bus/peer_to_peer/peer_server_spec.rb
722
723
  - spec/server/message_bus/peer_to_peer/socket_with_timeout_spec.rb
723
724
  - spec/server/message_bus/peer_to_peer_spec.rb
724
- - spec/server/middleware/middleware_handler.rb
725
+ - spec/server/middleware/middleware_stack_spec.rb
725
726
  - spec/server/rack/asset_files_spec.rb
726
727
  - spec/server/rack/component_paths_spec.rb
727
728
  - spec/server/rack/http_request_spec.rb
@@ -848,9 +849,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
848
849
  version: '2.1'
849
850
  required_rubygems_version: !ruby/object:Gem::Requirement
850
851
  requirements:
851
- - - ">"
852
+ - - ">="
852
853
  - !ruby/object:Gem::Version
853
- version: 1.3.1
854
+ version: '0'
854
855
  requirements: []
855
856
  rubyforge_project:
856
857
  rubygems_version: 2.4.5
@@ -929,6 +930,7 @@ test_files:
929
930
  - spec/integration/url_spec.rb
930
931
  - spec/integration/user_spec.rb
931
932
  - spec/integration/yield_spec.rb
933
+ - spec/models/array_model_spec.rb
932
934
  - spec/models/associations_spec.rb
933
935
  - spec/models/buffer_spec.rb
934
936
  - spec/models/dirty_spec.rb
@@ -977,7 +979,7 @@ test_files:
977
979
  - spec/server/message_bus/peer_to_peer/peer_server_spec.rb
978
980
  - spec/server/message_bus/peer_to_peer/socket_with_timeout_spec.rb
979
981
  - spec/server/message_bus/peer_to_peer_spec.rb
980
- - spec/server/middleware/middleware_handler.rb
982
+ - spec/server/middleware/middleware_stack_spec.rb
981
983
  - spec/server/rack/asset_files_spec.rb
982
984
  - spec/server/rack/component_paths_spec.rb
983
985
  - spec/server/rack/http_request_spec.rb