cosmos 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,13 +35,13 @@ module Cosmos
35
35
  tf.close
36
36
  config = CmdTlmServerConfig.new(tf.path)
37
37
  bt = BackgroundTasks.new(config)
38
- num_threads = Thread.list.length
39
38
  bt.start
40
39
  sleep 0.1
41
- Thread.list.length.should eql (num_threads + 1)
40
+ # 2 because the RSpec main thread plus the background task
41
+ Thread.list.length.should eql(2)
42
42
  bt.stop
43
- sleep 0.1
44
- Thread.list.length.should eql num_threads
43
+ sleep 0.2
44
+ Thread.list.length.should eql(1)
45
45
 
46
46
  tf.unlink
47
47
  File.delete(File.join(Cosmos::USERPATH,'lib','my_bg_task1.rb'))
@@ -61,14 +61,14 @@ module Cosmos
61
61
  end
62
62
  config = CmdTlmServerConfig.new(tf.path)
63
63
  bt = BackgroundTasks.new(config)
64
- num_threads = Thread.list.length
65
64
  bt.start
66
- Thread.list.length.should eql (num_threads + 1)
65
+ # 2 because the RSpec main thread plus the background task
66
+ Thread.list.length.should eql(2)
67
67
  sleep 1.1 # Allow the thread to crash
68
- Thread.list.length.should eql num_threads
68
+ Thread.list.length.should eql(1)
69
69
  bt.stop
70
- sleep 0.1
71
- Thread.list.length.should eql num_threads
70
+ sleep 0.2
71
+ Thread.list.length.should eql(1)
72
72
 
73
73
  stdout.string.should match "Background Task thread unexpectedly died"
74
74
  end
@@ -79,4 +79,3 @@ module Cosmos
79
79
 
80
80
  end
81
81
  end
82
-
@@ -109,6 +109,11 @@ module Cosmos
109
109
  config.packet_log_writer_pairs["DEFAULT"].cmd_log_writer.logging_enabled.should be_truthy
110
110
  config.packet_log_writer_pairs["MY_WRITER"].cmd_log_writer.logging_enabled.should be_falsey
111
111
  tf.unlink
112
+ config.packet_log_writer_pairs.each do |name, plwp|
113
+ plwp.cmd_log_writer.shutdown
114
+ plwp.tlm_log_writer.shutdown
115
+ end
116
+ sleep(0.2)
112
117
  end
113
118
  end
114
119
 
@@ -21,13 +21,10 @@ module Cosmos
21
21
  File.open(cts,'w') do |file|
22
22
  file.puts 'INTERFACE INT interface.rb'
23
23
  end
24
-
25
- @start_threads = Thread.list.length
26
24
  end
27
25
 
28
26
  after(:all) do
29
27
  clean_config()
30
- Thread.list.length.should eql @start_threads
31
28
  end
32
29
 
33
30
  before(:each) do
@@ -52,7 +49,7 @@ module Cosmos
52
49
  # Verify we can't start another CTS
53
50
  expect { CmdTlmServer.new }.to raise_error(FatalError, /Error starting JsonDRb on port 7777/)
54
51
  cts.stop
55
- sleep 0.1
52
+ sleep 0.2
56
53
  end
57
54
 
58
55
  it "should create the CTS in production mode" do
@@ -65,7 +62,7 @@ module Cosmos
65
62
  CmdTlmServer.json_drb.method_whitelist.should_not include('stop_cmd_log')
66
63
  CmdTlmServer.json_drb.method_whitelist.should_not include('stop_tlm_log')
67
64
  cts.stop
68
- sleep 0.1
65
+ sleep 0.2
69
66
  end
70
67
  end
71
68
 
@@ -81,7 +78,7 @@ module Cosmos
81
78
  cts.start # Call start again ... it should do nothing
82
79
  Thread.list.length.should eql threads
83
80
  cts.stop
84
- sleep 0.1
81
+ sleep 0.2
85
82
 
86
83
  expect_any_instance_of(PacketLogging).to receive(:start)
87
84
  # Now start the server in production mode
@@ -92,7 +89,7 @@ module Cosmos
92
89
  CmdTlmServer.json_drb.method_whitelist.should_not include('stop_cmd_log')
93
90
  CmdTlmServer.json_drb.method_whitelist.should_not include('stop_tlm_log')
94
91
  cts.stop
95
- sleep 0.1
92
+ sleep 0.2
96
93
  end
97
94
 
98
95
  it "should monitor the staleness thread" do
@@ -104,7 +101,7 @@ module Cosmos
104
101
  cts = CmdTlmServer.new
105
102
  sleep 0.1
106
103
  cts.stop
107
- sleep 0.1
104
+ sleep 0.2
108
105
 
109
106
  stdout.string.should match "Staleness Monitor thread unexpectedly died"
110
107
  end
@@ -137,7 +134,7 @@ module Cosmos
137
134
  stdout.string.should match "<R>TGT PKT TEST = 100 is RED"
138
135
 
139
136
  cts.stop
140
- sleep 0.1
137
+ sleep 0.2
141
138
  end
142
139
  end
143
140
 
@@ -159,7 +156,7 @@ module Cosmos
159
156
  cts.limits_change_callback(pkt, pi, :YELLOW, 100, true)
160
157
  sleep 0.1
161
158
  cts.stop
162
- sleep 0.1
159
+ sleep 0.2
163
160
  end
164
161
 
165
162
  it "should log limits response errors" do
@@ -177,7 +174,7 @@ module Cosmos
177
174
 
178
175
  stdout.string.should match "TGT PKT TEST Limits Response Exception!"
179
176
  cts.stop
180
- sleep 0.1
177
+ sleep 0.2
181
178
  end
182
179
  end
183
180
  end
@@ -216,7 +213,7 @@ module Cosmos
216
213
  state.should eql :YELLOW
217
214
 
218
215
  cts.stop
219
- sleep 0.1
216
+ sleep 0.2
220
217
  end
221
218
 
222
219
  it "should delete queues after the max events is reached" do
@@ -242,7 +239,7 @@ module Cosmos
242
239
  expect { CmdTlmServer.get_limits_event(id) }.to raise_error("Limits event queue with id #{id} not found")
243
240
 
244
241
  cts.stop
245
- sleep 0.1
242
+ sleep 0.2
246
243
  end
247
244
  end
248
245
 
@@ -267,7 +264,7 @@ module Cosmos
267
264
  expect { CmdTlmServer.get_limits_event(id) }.to raise_error("Limits event queue with id #{id} not found")
268
265
 
269
266
  cts.stop
270
- sleep 0.1
267
+ sleep 0.2
271
268
  end
272
269
  end
273
270
 
@@ -313,7 +310,7 @@ module Cosmos
313
310
  end
314
311
 
315
312
  cts.stop
316
- sleep 0.1
313
+ sleep 0.2
317
314
  end
318
315
 
319
316
  it "should delete queues after the max packets is reached" do
@@ -348,7 +345,7 @@ module Cosmos
348
345
  expect { CmdTlmServer.get_packet_data(id) }.to raise_error("Packet data queue with id #{id} not found")
349
346
 
350
347
  cts.stop
351
- sleep 0.1
348
+ sleep 0.2
352
349
  end
353
350
  end
354
351
 
@@ -382,7 +379,7 @@ module Cosmos
382
379
  expect { CmdTlmServer.get_packet_data(id) }.to raise_error("Packet data queue with id #{id} not found")
383
380
 
384
381
  cts.stop
385
- sleep 0.1
382
+ sleep 0.2
386
383
  end
387
384
  end
388
385
 
@@ -393,7 +390,7 @@ module Cosmos
393
390
 
394
391
  expect { CmdTlmServer.get_packet_data(id, true) }.to raise_error(ThreadError)
395
392
  cts.stop
396
- sleep 0.1
393
+ sleep 0.2
397
394
  end
398
395
  end
399
396
 
@@ -409,7 +406,7 @@ module Cosmos
409
406
 
410
407
  CmdTlmServer.json_drb.request_count.should eql 0
411
408
  cts.stop
412
- sleep 0.1
409
+ sleep 0.2
413
410
  end
414
411
  end
415
412
 
@@ -57,13 +57,12 @@ module Cosmos
57
57
  allow(@interface).to receive(:connected?).and_return(false)
58
58
  allow(@interface).to receive(:connect) { raise "ConnectError" }
59
59
  thread = InterfaceThread.new(@interface)
60
- threads = Thread.list.length
61
60
  thread.start
62
61
  sleep 0.1
63
- Thread.list.length.should eql threads + 1
62
+ Thread.list.length.should eql(2)
64
63
  thread.stop
65
- sleep 0.1
66
- Thread.list.length.should eql threads
64
+ sleep 0.2
65
+ Thread.list.length.should eql(1)
67
66
 
68
67
  stdout.string.should match "Connection Failed: ConnectError"
69
68
  end
@@ -83,13 +82,12 @@ module Cosmos
83
82
  error.message.should eql "ConnectError"
84
83
  error_count += 1
85
84
  end
86
- threads = Thread.list.length
87
85
  thread.start
88
86
  sleep 0.1
89
- Thread.list.length.should eql threads + 1
87
+ Thread.list.length.should eql(2)
90
88
  thread.stop
91
- sleep 0.1
92
- Thread.list.length.should eql threads
89
+ sleep 0.2
90
+ Thread.list.length.should eql(1)
93
91
  error_count.should eql 2
94
92
 
95
93
  stdout.string.should_not match "Connection Failed: ConnectError"
@@ -99,13 +97,12 @@ module Cosmos
99
97
  it "should log the connection" do
100
98
  capture_io do |stdout|
101
99
  thread = InterfaceThread.new(@interface)
102
- threads = Thread.list.length
103
100
  thread.start
104
101
  sleep 0.1
105
- Thread.list.length.should eql threads + 1
102
+ Thread.list.length.should eql(2)
106
103
  thread.stop
107
- sleep 0.1
108
- Thread.list.length.should eql threads
104
+ sleep 0.2
105
+ Thread.list.length.should eql(1)
109
106
 
110
107
  stdout.string.should match "Connection Success"
111
108
  end
@@ -118,13 +115,12 @@ module Cosmos
118
115
  thread.connection_success_callback = Proc.new do
119
116
  callback_called = true
120
117
  end
121
- threads = Thread.list.length
122
118
  thread.start
123
119
  sleep 0.1
124
- Thread.list.length.should eql threads + 1
120
+ Thread.list.length.should eql(2)
125
121
  thread.stop
126
- sleep 0.1
127
- Thread.list.length.should eql threads
122
+ sleep 0.2
123
+ Thread.list.length.should eql(1)
128
124
  callback_called.should be_truthy
129
125
 
130
126
  stdout.string.should_not match "Connection Success"
@@ -139,13 +135,12 @@ module Cosmos
139
135
  # create see the error twice.
140
136
  @interface.reconnect_delay = 0.06
141
137
  thread = InterfaceThread.new(@interface)
142
- threads = Thread.list.length
143
138
  thread.start
144
139
  sleep 0.1
145
- Thread.list.length.should eql threads + 1
140
+ Thread.list.length.should eql(2)
146
141
  thread.stop
147
- sleep 0.1
148
- Thread.list.length.should eql threads
142
+ sleep 0.2
143
+ Thread.list.length.should eql(1)
149
144
 
150
145
  stdout.string.should match "Connection Lost"
151
146
  end
@@ -160,15 +155,14 @@ module Cosmos
160
155
  thread.connection_lost_callback = Proc.new do
161
156
  callback_called = true
162
157
  end
163
- threads = Thread.list.length
164
158
  thread.start
165
159
  sleep 0.1
166
160
  # Since we set auto_reconnect to false we shouldn't see the interface
167
161
  # thread because it will be killed
168
- Thread.list.length.should eql threads
162
+ Thread.list.length.should eql(1)
169
163
  thread.stop
170
- sleep 0.1
171
- Thread.list.length.should eql threads
164
+ sleep 0.2
165
+ Thread.list.length.should eql(1)
172
166
  callback_called.should be_truthy
173
167
 
174
168
  stdout.string.should_not match "Connection Lost"
@@ -179,13 +173,12 @@ module Cosmos
179
173
  capture_io do |stdout|
180
174
  allow(@interface).to receive(:read) { raise "ReadError" }
181
175
  thread = InterfaceThread.new(@interface)
182
- threads = Thread.list.length
183
176
  thread.start
184
177
  sleep 0.1
185
- Thread.list.length.should eql threads + 1
178
+ Thread.list.length.should eql(2)
186
179
  thread.stop
187
- sleep 0.1
188
- Thread.list.length.should eql threads
180
+ sleep 0.2
181
+ Thread.list.length.should eql(1)
189
182
 
190
183
  stdout.string.should match "ReadError"
191
184
  end
@@ -199,13 +192,12 @@ module Cosmos
199
192
  # create see the error twice.
200
193
  @interface.reconnect_delay = 0.06
201
194
  thread = InterfaceThread.new(@interface)
202
- threads = Thread.list.length
203
195
  thread.start
204
196
  sleep 0.1
205
- Thread.list.length.should eql threads + 1
197
+ Thread.list.length.should eql(2)
206
198
  thread.stop
207
- sleep 0.1
208
- Thread.list.length.should eql threads
199
+ sleep 0.2
200
+ Thread.list.length.should eql(1)
209
201
 
210
202
  stdout.string.should match "ECONNRESET"
211
203
  end
@@ -218,7 +210,7 @@ module Cosmos
218
210
  thread.start
219
211
  sleep 0.1
220
212
  thread.stop
221
- sleep 0.1
213
+ sleep 0.2
222
214
 
223
215
  stdout.string.should match "Packet reading thread unexpectedly died"
224
216
  end
@@ -236,7 +228,7 @@ module Cosmos
236
228
  thread.start
237
229
  sleep 0.1
238
230
  thread.stop
239
- sleep 0.1
231
+ sleep 0.2
240
232
  callback_called.should be_truthy
241
233
 
242
234
  stdout.string.should_not match "Packet reading thread unexpectedly died"
@@ -247,13 +239,12 @@ module Cosmos
247
239
  capture_io do |stdout|
248
240
  @packet = Packet.new(nil,nil)
249
241
  thread = InterfaceThread.new(@interface)
250
- threads = Thread.list.length
251
242
  thread.start
252
243
  sleep 0.1
253
- Thread.list.length.should eql threads + 1
244
+ Thread.list.length.should eql(2)
254
245
  thread.stop
255
- sleep 0.1
256
- Thread.list.length.should eql threads
246
+ sleep 0.2
247
+ Thread.list.length.should eql(1)
257
248
 
258
249
  stdout.string.should match "Unknown 2 byte packet"
259
250
  end
@@ -265,13 +256,12 @@ module Cosmos
265
256
  @packet.packet_name = 'SMITH'
266
257
  allow(System).to receive_message_chain(:telemetry,:update!).and_raise(RuntimeError)
267
258
  thread = InterfaceThread.new(@interface)
268
- threads = Thread.list.length
269
259
  thread.start
270
260
  sleep 0.1
271
- Thread.list.length.should eql threads + 1
261
+ Thread.list.length.should eql(2)
272
262
  thread.stop
273
- sleep 0.1
274
- Thread.list.length.should eql threads
263
+ sleep 0.2
264
+ Thread.list.length.should eql(1)
275
265
  stdout.string.should match "Received unknown identified telemetry: BOB SMITH"
276
266
  end
277
267
  end
@@ -285,13 +275,12 @@ module Cosmos
285
275
  allow(router).to receive(:write) { raise "RouterWriteError" }
286
276
  @interface.routers = [router]
287
277
  thread = InterfaceThread.new(@interface)
288
- threads = Thread.list.length
289
278
  thread.start
290
279
  sleep 0.1
291
- Thread.list.length.should eql threads + 1
280
+ Thread.list.length.should eql(2)
292
281
  thread.stop
293
- sleep 0.1
294
- Thread.list.length.should eql threads
282
+ sleep 0.2
283
+ Thread.list.length.should eql(1)
295
284
 
296
285
  stdout.string.should match "Problem writing to router"
297
286
  end
@@ -305,10 +294,10 @@ module Cosmos
305
294
  threads = Thread.list.length
306
295
  thread.start
307
296
  sleep 0.1
308
- Thread.list.length.should eql threads + 1
297
+ Thread.list.length.should eql(2)
309
298
  thread.stop
310
- sleep 0.1
311
- Thread.list.length.should eql threads
299
+ sleep 0.2
300
+ Thread.list.length.should eql(1)
312
301
  end
313
302
 
314
303
  end
@@ -160,10 +160,12 @@ module Cosmos
160
160
  tf.puts 'ROUTE DEST2'
161
161
  tf.close
162
162
  capture_io do |stdout|
163
- server = TCPServer.new(8888)
164
- Thread.new do
165
- client = server.accept
166
- client.close
163
+ server = TCPServer.new('127.0.0.1', 8888)
164
+ clients = []
165
+ server_thread = Thread.new do
166
+ loop do
167
+ clients << server.accept
168
+ end
167
169
  end
168
170
 
169
171
  config = CmdTlmServerConfig.new(tf.path)
@@ -171,18 +173,26 @@ module Cosmos
171
173
  config.interfaces['DEST1'].routers[0].name.should eql "MY_ROUTER"
172
174
  config.interfaces['DEST2'].routers[0].name.should eql "MY_ROUTER"
173
175
  interfaces.connect("DEST1")
174
- sleep 0.1
176
+ sleep 0.2
175
177
  stdout.string.should match "Connecting to DEST1"
176
178
  interfaces.disconnect("DEST1")
177
- interfaces.connect("DEST1",'localhost',9888,9888,6,6,'length')
178
- sleep 0.1
179
+ interfaces.connect("DEST1",'localhost',8888,8888,6,6,'length')
180
+ sleep 0.2
179
181
  config.interfaces['DEST1'].routers[0].name.should eql "MY_ROUTER"
180
182
  config.interfaces['DEST2'].routers[0].name.should eql "MY_ROUTER"
181
183
  stdout.string.should match "Disconnected from interface DEST1"
182
184
  stdout.string.should match "Connecting to DEST1"
183
185
  interfaces.disconnect("DEST1")
186
+ interfaces.stop
187
+
188
+ server_thread.kill
189
+ server.close
190
+ clients.each do |c|
191
+ c.close
192
+ end
184
193
  end
185
194
  tf.unlink
195
+ sleep(0.2)
186
196
  end
187
197
  end
188
198