cosmos 4.2.3-java → 4.2.4-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Manifest.txt +14 -1
  4. data/bin/dart_util +4 -0
  5. data/cosmos.gemspec +3 -2
  6. data/data/config/interface_modifiers.yaml +2 -1
  7. data/data/config/item_modifiers.yaml +1 -1
  8. data/data/config/parameter_modifiers.yaml +1 -1
  9. data/data/crc.txt +52 -45
  10. data/demo/config/data/crc.txt +6 -1
  11. data/demo/config/system/system.txt +1 -0
  12. data/demo/config/targets/DART/cmd_tlm/dart_cmds.txt +2 -0
  13. data/demo/config/targets/DART/cmd_tlm/dart_tlm.txt +40 -0
  14. data/demo/config/targets/DART/cmd_tlm_server.txt +6 -0
  15. data/demo/config/targets/DART/screens/status.txt +54 -0
  16. data/demo/config/targets/DART/target.txt +7 -0
  17. data/ext/cosmos/ext/structure/structure.c +16 -4
  18. data/lib/cosmos/dart/app/models/status.rb +2 -0
  19. data/lib/cosmos/dart/db/migrate/20180423205644_create_statuses.rb +22 -0
  20. data/lib/cosmos/dart/db/migrate/20180425211340_add_decom_state_index.rb +5 -0
  21. data/lib/cosmos/dart/db/migrate/20180509204705_remove_indexes.rb +29 -0
  22. data/lib/cosmos/dart/db/migrate/20180510160002_remove_timestamps_from_ples.rb +6 -0
  23. data/lib/cosmos/dart/db/migrate/20180511194944_add_packet_log_id_to_tables.rb +18 -0
  24. data/lib/cosmos/dart/db/schema.rb +15 -9
  25. data/lib/cosmos/dart/db/seeds.rb +8 -0
  26. data/lib/cosmos/dart/lib/dart_common.rb +5 -6
  27. data/lib/cosmos/dart/lib/dart_database_cleaner.rb +56 -5
  28. data/lib/cosmos/dart/lib/dart_decom_query.rb +108 -6
  29. data/lib/cosmos/dart/lib/dart_decommutator.rb +81 -22
  30. data/lib/cosmos/dart/lib/dart_importer.rb +44 -14
  31. data/lib/cosmos/dart/lib/dart_packet_log_writer.rb +73 -55
  32. data/lib/cosmos/dart/lib/dart_reducer_manager.rb +34 -3
  33. data/lib/cosmos/dart/lib/dart_reducer_worker_thread.rb +18 -7
  34. data/lib/cosmos/dart/processes/dart.rb +2 -1
  35. data/lib/cosmos/dart/processes/dart_decom_server.rb +2 -1
  36. data/lib/cosmos/dart/processes/dart_import.rb +1 -0
  37. data/lib/cosmos/dart/processes/dart_ingester.rb +1 -0
  38. data/lib/cosmos/dart/processes/dart_reducer.rb +1 -0
  39. data/lib/cosmos/dart/processes/dart_stream_server.rb +1 -0
  40. data/lib/cosmos/dart/processes/dart_util.rb +147 -0
  41. data/lib/cosmos/dart/processes/dart_worker.rb +1 -0
  42. data/lib/cosmos/dart/spec/dart/dart_database_cleaner_spec.rb +1 -1
  43. data/lib/cosmos/dart/spec/dart/dart_decom_query_spec.rb +1 -0
  44. data/lib/cosmos/dart/spec/dart/dart_decommutator_spec.rb +1 -0
  45. data/lib/cosmos/dart/spec/dart/dart_importer_spec.rb +1 -0
  46. data/lib/cosmos/dart/spec/dart/dart_packet_log_writer_spec.rb +39 -36
  47. data/lib/cosmos/dart/spec/dart/dart_reducer_manager_spec.rb +2 -1
  48. data/lib/cosmos/dart/spec/dart/dart_tcpip_server_interface_spec.rb +1 -2
  49. data/lib/cosmos/gui/widgets/dart_meta_frame.rb +13 -6
  50. data/lib/cosmos/interfaces.rb +1 -0
  51. data/lib/cosmos/interfaces/dart_status_interface.rb +91 -0
  52. data/lib/cosmos/interfaces/serial_interface.rb +5 -1
  53. data/lib/cosmos/io/json_drb.rb +7 -2
  54. data/lib/cosmos/io/json_drb_object.rb +11 -6
  55. data/lib/cosmos/io/json_rpc.rb +1 -0
  56. data/lib/cosmos/io/posix_serial_driver.rb +4 -2
  57. data/lib/cosmos/io/serial_driver.rb +8 -4
  58. data/lib/cosmos/io/win32_serial_driver.rb +4 -3
  59. data/lib/cosmos/packets/packet_config.rb +12 -2
  60. data/lib/cosmos/packets/structure_item.rb +1 -0
  61. data/lib/cosmos/script/extract.rb +4 -2
  62. data/lib/cosmos/streams/serial_stream.rb +10 -5
  63. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_config.rb +15 -15
  64. data/lib/cosmos/tools/cmd_tlm_server/gui/status_tab.rb +1 -1
  65. data/lib/cosmos/tools/table_manager/table_manager.rb +6 -4
  66. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_dart_thread.rb +5 -4
  67. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_logfile_thread.rb +1 -1
  68. data/lib/cosmos/top_level.rb +1 -1
  69. data/lib/cosmos/version.rb +4 -4
  70. data/spec/interfaces/serial_interface_spec.rb +13 -0
  71. data/spec/io/json_rpc_spec.rb +7 -0
  72. data/spec/io/win32_serial_driver_spec.rb +8 -0
  73. data/spec/packets/structure_item_spec.rb +6 -0
  74. data/spec/script/extract_spec.rb +5 -0
  75. data/spec/tools/cmd_tlm_server/cmd_tlm_server_config_spec.rb +10 -0
  76. metadata +17 -3
  77. data/lib/cosmos/dart/app/helpers/application_helper.rb +0 -2
@@ -10,6 +10,20 @@
10
10
 
11
11
  require 'dart_reducer_worker_thread'
12
12
 
13
+ class DartReducerStatus
14
+ attr_accessor :count
15
+ attr_accessor :error_count
16
+ attr_accessor :message
17
+ attr_accessor :message_time
18
+
19
+ def initialize
20
+ @count = 0
21
+ @error_count = 0
22
+ @message = ''
23
+ @message_time = Time.now
24
+ end
25
+ end
26
+
13
27
  # Reduce the decommutated data into the database. It creates a number of
14
28
  # threads to perform the actual data reduction. Then it queries the database
15
29
  # for all the decommutation tables and determines which need to be reduced
@@ -21,13 +35,15 @@ class DartReducerManager
21
35
  #
22
36
  # @param num_threads [Integer] The number of worker threads to create
23
37
  def initialize(num_threads = 5)
24
- Cosmos::Logger.info("Dart Reducer Starting with #{num_threads} threads...")
38
+ message = "Dart Reducer Starting with #{num_threads} threads..."
39
+ Cosmos::Logger.info(message)
25
40
  @master_queue = Queue.new
26
41
  @locked_tables = []
27
42
  @mutex = Mutex.new
28
43
  @threads = []
44
+ @status = DartReducerStatus.new
29
45
  num_threads.times do |index|
30
- @threads << DartReducerWorkerThread.new(@master_queue, @locked_tables, @mutex, index + 1)
46
+ @threads << DartReducerWorkerThread.new(@master_queue, @locked_tables, @mutex, index + 1, @status)
31
47
  end
32
48
  end
33
49
 
@@ -51,6 +67,20 @@ class DartReducerManager
51
67
  queue_worker(:HOUR, packet_config_id, table_index, minute_model, hour_model)
52
68
  queue_worker(:DAY, packet_config_id, table_index, hour_model, day_model)
53
69
  end
70
+
71
+ # Update status
72
+ status = Status.first
73
+ if (Time.now - @status.message_time) <= 60.0
74
+ status.reduction_message = @status.message
75
+ status.reduction_message_time = @status.message_time
76
+ status.save!
77
+ end
78
+ if @status.count > 0 or @status.error_count > 0
79
+ Status.update_counters(status.id, :reduction_count => @status.count, :reduction_error_count => @status.error_count)
80
+ @status.count = 0
81
+ @status.error_count = 0
82
+ end
83
+
54
84
  # Throttle to no faster than once every 60 seconds
55
85
  delta = Time.now - time_start
56
86
  if delta < 60 and delta > 0
@@ -58,7 +88,8 @@ class DartReducerManager
58
88
  end
59
89
  end
60
90
  rescue Interrupt
61
- Cosmos::Logger.info("Dart Reducer Shutting Down...")
91
+ message = "Dart Reducer Shutting Down..."
92
+ Cosmos::Logger.info(message)
62
93
  shutdown()
63
94
  exit(0)
64
95
  end
@@ -23,13 +23,15 @@ class DartReducerWorkerThread
23
23
  # third values are the PacketConfig ID and table index.
24
24
  # @param mutex [Mutex] Mutex used to synchronize access to the locked_tables
25
25
  # @param instance_num [Integer] Simple counter to trace the thread instance
26
- def initialize(master_queue, locked_tables, mutex, instance_num)
26
+ # @param status [DartReducerStatus] Status structure
27
+ def initialize(master_queue, locked_tables, mutex, instance_num, status)
27
28
  @instance_num = instance_num
28
29
  @running = true
29
30
  @master_queue = master_queue
30
31
  @locked_tables = locked_tables
31
32
  @mutex = mutex
32
33
  @thread_queue = Queue.new
34
+ @status = status
33
35
  # Start the thread which will wait on @thread_queue.pop
34
36
  @thread = Thread.new { work() }
35
37
  # Add the local @thread_queue to the @master_queue so jobs can be added
@@ -77,6 +79,7 @@ class DartReducerWorkerThread
77
79
  new_row.start_time = first_row_time
78
80
  new_row.num_samples = sample_rows.length
79
81
  new_row.meta_id = sample_rows[0].meta_id
82
+ new_row.packet_log_id = sample_rows[0].packet_log_id
80
83
  # Process each of the ItemToDecomTableMapping to get the item to be reduced
81
84
  mappings.each do |mapping|
82
85
  item_name = "i#{mapping.item_index}"
@@ -105,7 +108,7 @@ class DartReducerWorkerThread
105
108
  max_sample = value
106
109
  avg_sample = value
107
110
  if value.nil?
108
- Cosmos::Logger.error("#{item_name} is nil in #{row_to_reduce.class}:#{row_to_reduce.id}")
111
+ handle_error("#{item_name} is nil in #{row_to_reduce.class}:#{row_to_reduce.id}")
109
112
  next
110
113
  end
111
114
  else # :HOUR or :DAY
@@ -116,19 +119,19 @@ class DartReducerWorkerThread
116
119
  avg_sample = row_to_reduce.read_attribute(avg_item_name)
117
120
  stddev_sample = row_to_reduce.read_attribute(stddev_item_name)
118
121
  if min_sample.nil?
119
- Cosmos::Logger.error("#{min_item_name} is nil in #{row_to_reduce.class}:#{row_to_reduce.id}")
122
+ handle_error("#{min_item_name} is nil in #{row_to_reduce.class}:#{row_to_reduce.id}")
120
123
  next
121
124
  end
122
125
  if max_sample.nil?
123
- Cosmos::Logger.error("#{max_item_name} is nil in #{row_to_reduce.class}:#{row_to_reduce.id}")
126
+ handle_error("#{max_item_name} is nil in #{row_to_reduce.class}:#{row_to_reduce.id}")
124
127
  next
125
128
  end
126
129
  if avg_sample.nil?
127
- Cosmos::Logger.error("#{avg_item_name} is nil in #{row_to_reduce.class}:#{row_to_reduce.id}")
130
+ handle_error("#{avg_item_name} is nil in #{row_to_reduce.class}:#{row_to_reduce.id}")
128
131
  next
129
132
  end
130
133
  if stddev_sample.nil?
131
- Cosmos::Logger.error("#{stddev_item_name} is nil in #{row_to_reduce.class}:#{row_to_reduce.id}")
134
+ handle_error("#{stddev_item_name} is nil in #{row_to_reduce.class}:#{row_to_reduce.id}")
132
135
  next
133
136
  end
134
137
  end
@@ -193,6 +196,7 @@ class DartReducerWorkerThread
193
196
  base_model.where(id: sample_rows.map(&:id)).update_all(:reduced_id => new_row.id)
194
197
  new_row.reduced_state = DartCommon::READY_TO_REDUCE
195
198
  new_row.save!
199
+ @status.count += 1
196
200
 
197
201
  rows = rows[-1..-1] # Start a new sample with the last item in the previous sample
198
202
  Cosmos::Logger.debug("Created #{new_row.class}:#{new_row.id} with #{mappings.length} items from #{new_row.num_samples} samples")
@@ -201,7 +205,7 @@ class DartReducerWorkerThread
201
205
  end # while @running
202
206
  Cosmos::Logger.info("Reducer Thread #{@instance_num} Shutdown")
203
207
  rescue Exception => error
204
- Cosmos::Logger.error("Reducer Thread Unexpectedly Died: #{error.formatted}")
208
+ handle_error("Reducer Thread Unexpectedly Died: #{error.formatted}")
205
209
  end
206
210
 
207
211
  # Shutdown the worker thread
@@ -260,4 +264,11 @@ class DartReducerWorkerThread
260
264
  raise "Reducer Thread Unexpected Job Type: #{job_type}"
261
265
  end
262
266
  end
267
+
268
+ def handle_error(message)
269
+ Cosmos::Logger.error(message)
270
+ @status.error_count += 1
271
+ @status.message = message
272
+ @status.message_time = Time.now
273
+ end
263
274
  end
@@ -8,6 +8,7 @@
8
8
  # as published by the Free Software Foundation; version 3 with
9
9
  # attribution addendums as found in the LICENSE.txt
10
10
 
11
+ ENV['RAILS_ENV'] = 'production'
11
12
  require File.expand_path('../../config/environment', __FILE__)
12
13
  require 'dart_common'
13
14
  require 'dart_logging'
@@ -45,7 +46,7 @@ class Dart
45
46
  end
46
47
 
47
48
  num_workers = ENV['DART_NUM_WORKERS']
48
- num_workers ||= 1
49
+ num_workers ||= 2
49
50
  num_workers = num_workers.to_i
50
51
 
51
52
  process_definitions = [
@@ -8,6 +8,7 @@
8
8
  # as published by the Free Software Foundation; version 3 with
9
9
  # attribution addendums as found in the LICENSE.txt
10
10
 
11
+ ENV['RAILS_ENV'] = 'production'
11
12
  require File.expand_path('../../config/environment', __FILE__)
12
13
  require 'dart_common'
13
14
  require 'dart_decom_query'
@@ -21,7 +22,7 @@ Cosmos.catch_fatal_exception do
21
22
  json_drb = Cosmos::JsonDRb.new
22
23
  json_drb.acl = Cosmos::System.acl if Cosmos::System.acl
23
24
  begin
24
- json_drb.method_whitelist = ['query', 'item_names']
25
+ json_drb.method_whitelist = ['query', 'item_names', 'dart_status', 'clear_errors']
25
26
  begin
26
27
  json_drb.start_service(Cosmos::System.listen_hosts['DART_DECOM'],
27
28
  Cosmos::System.ports['DART_DECOM'], DartDecomQuery.new)
@@ -54,6 +54,7 @@ unless ARGV[0]
54
54
  exit(1)
55
55
  end
56
56
 
57
+ ENV['RAILS_ENV'] = 'production'
57
58
  require File.expand_path('../../config/environment', __FILE__)
58
59
  require 'dart_importer'
59
60
 
@@ -8,6 +8,7 @@
8
8
  # as published by the Free Software Foundation; version 3 with
9
9
  # attribution addendums as found in the LICENSE.txt
10
10
 
11
+ ENV['RAILS_ENV'] = 'production'
11
12
  require File.expand_path('../../config/environment', __FILE__)
12
13
  require 'dart_packet_log_writer'
13
14
  require 'dart_logging'
@@ -8,6 +8,7 @@
8
8
  # as published by the Free Software Foundation; version 3 with
9
9
  # attribution addendums as found in the LICENSE.txt
10
10
 
11
+ ENV['RAILS_ENV'] = 'production'
11
12
  require File.expand_path('../../config/environment', __FILE__)
12
13
  require 'dart_reducer_manager'
13
14
  require 'dart_logging'
@@ -8,6 +8,7 @@
8
8
  # as published by the Free Software Foundation; version 3 with
9
9
  # attribution addendums as found in the LICENSE.txt
10
10
 
11
+ ENV['RAILS_ENV'] = 'production'
11
12
  require File.expand_path('../../config/environment', __FILE__)
12
13
  require 'dart_tcpip_server_interface'
13
14
  require 'dart_logging'
@@ -0,0 +1,147 @@
1
+ # encoding: ascii-8bit
2
+
3
+ # Copyright 2018 Ball Aerospace & Technologies Corp.
4
+ # All Rights Reserved.
5
+ #
6
+ # This program is free software; you can modify and/or redistribute it
7
+ # under the terms of the GNU General Public License
8
+ # as published by the Free Software Foundation; version 3 with
9
+ # attribution addendums as found in the LICENSE.txt
10
+
11
+ # This code must be run on the database server
12
+
13
+ require 'ostruct'
14
+ require 'optparse'
15
+ require 'cosmos/version'
16
+
17
+ options = OpenStruct.new
18
+ options.force = false
19
+
20
+ parser = OptionParser.new do |option_parser|
21
+ option_parser.banner = "Usage: dart_util <action> [options]"
22
+ option_parser.separator("")
23
+
24
+ # Create the help option
25
+ option_parser.on("-h", "--help", "Show this message") do
26
+ puts option_parser
27
+ exit(0)
28
+ end
29
+
30
+ # Create the version option
31
+ option_parser.on("-v", "--version", "Show version") do
32
+ puts "COSMOS Version: #{COSMOS_VERSION}"
33
+ puts "User Version: #{USER_VERSION}" if defined? USER_VERSION
34
+ exit(0)
35
+ end
36
+
37
+ # Create the system option
38
+ option_parser.on("--system FILE", "Use an alternative system.txt file") do |arg|
39
+ System.instance(File.join(USERPATH, 'config', 'system', arg))
40
+ end
41
+
42
+ # Create the force option
43
+ option_parser.on("-f", "--force", "Force parsing entire file") do
44
+ options.force = true
45
+ end
46
+ end
47
+
48
+ parser.parse!(ARGV)
49
+ action = ARGV[0]
50
+ unless action
51
+ puts parser
52
+ exit(1)
53
+ end
54
+
55
+ ENV['RAILS_ENV'] = 'production'
56
+ require File.expand_path('../../config/environment', __FILE__)
57
+ require 'dart_database_cleaner'
58
+
59
+ Cosmos.catch_fatal_exception do
60
+ case action.downcase
61
+ when 'showpleerrors'
62
+ ples = PacketLogEntry.where("decom_state >= 3").find_each do |ple|
63
+ puts "#{ple.id}: #{ple.decom_state_string}(#{ple.decom_state})"
64
+ end
65
+
66
+ when 'resetpleerrors'
67
+ PacketLogEntry.where("decom_state >= 3").update_all(:decom_state => 0)
68
+ puts "All errored PLEs set to decom_state 0"
69
+
70
+ when 'fullcleanup'
71
+ Cosmos::Logger.level = Cosmos::Logger::INFO
72
+ DartDatabaseCleaner.clean(false, true)
73
+
74
+ when 'removepacketlog'
75
+ puts "Removing database entries for packet log #{ARGV[1]}"
76
+ puts "Note!!! This does not delete the file"
77
+ Cosmos::Logger.level = Cosmos::Logger::INFO
78
+ DartDatabaseCleaner.new.remove_packet_log(ARGV[1])
79
+
80
+ when 'showpacketlogs'
81
+ total_size = 0
82
+ packet_logs = PacketLog.all
83
+ filenames = []
84
+ reader = Cosmos::PacketLogReader.new
85
+ packet_logs.each do |pl|
86
+ filenames << pl.filename
87
+ if File.exist?(pl.filename)
88
+ exists = "FOUND "
89
+ size = File.size(pl.filename)
90
+ reader.open(pl.filename)
91
+ begin
92
+ first_packet = reader.first
93
+ last_packet = reader.last
94
+ start_time = first_packet.received_time.formatted
95
+ end_time = last_packet.received_time.formatted
96
+ rescue
97
+ if size == 128 or size == 0
98
+ start_time = "EMPTY "
99
+ end_time = "EMPTY "
100
+ else
101
+ start_time = "ERROR "
102
+ end_time = "ERROR "
103
+ end
104
+ ensure
105
+ reader.close
106
+ end
107
+ else
108
+ size = 0
109
+ start_time = "MISSING "
110
+ end_time = "MISSING "
111
+ exists = "MISSING"
112
+ end
113
+ puts "#{"%-32.32s" % File.basename(pl.filename)} #{exists} #{start_time} #{end_time} #{size}"
114
+ total_size += size
115
+ end
116
+ other_size = 0
117
+ Cosmos.set_working_dir do
118
+ Dir[Cosmos::System.paths['DART_DATA'] + '/*.bin'].each do |filename|
119
+ next if filename[0] == '.'
120
+ next if filenames.include?(filename)
121
+ exists = "NOTINDB"
122
+ size = File.size(filename)
123
+ reader.open(filename)
124
+ begin
125
+ first_packet = reader.first
126
+ last_packet = reader.last
127
+ start_time = first_packet.received_time.formatted
128
+ end_time = last_packet.received_time.formatted
129
+ rescue
130
+ if size == 128 or size == 0
131
+ start_time = "EMPTY "
132
+ end_time = "EMPTY "
133
+ else
134
+ start_time = "ERROR "
135
+ end_time = "ERROR "
136
+ end
137
+ ensure
138
+ reader.close
139
+ end
140
+ puts "#{"%-32.32s" % File.basename(filename)} #{exists} #{start_time} #{end_time} #{size}"
141
+ other_size += size
142
+ end
143
+ end
144
+ puts "Total size in database: #{"%0.2f GB" % (total_size.to_f / (1024 * 1024 * 1024))}"
145
+ puts "Total size not in database: #{"%0.2f GB" % (other_size.to_f / (1024 * 1024 * 1024))}"
146
+ end
147
+ end
@@ -8,6 +8,7 @@
8
8
  # as published by the Free Software Foundation; version 3 with
9
9
  # attribution addendums as found in the LICENSE.txt
10
10
 
11
+ ENV['RAILS_ENV'] = 'production'
11
12
  require File.expand_path('../../config/environment', __FILE__)
12
13
  require 'dart_common'
13
14
  require 'dart_logging'
@@ -17,6 +17,7 @@ describe DartDatabaseCleaner do
17
17
  before(:each) do
18
18
  DatabaseCleaner.strategy = :truncation
19
19
  DatabaseCleaner.clean
20
+ Rails.application.load_seed
20
21
  @cleaner = DartDatabaseCleaner.new
21
22
  end
22
23
 
@@ -29,7 +30,6 @@ describe DartDatabaseCleaner do
29
30
  expect(messages.select{|m| m =~ /Cleaning up PacketLog\./}.length).to eq 1
30
31
  expect(messages.select{|m| m =~ /Cleaning up PacketConfig/}.length).to eq 1
31
32
  expect(messages.select{|m| m =~ /Cleaning up PacketLogEntry/}.length).to eq 1
32
- expect(messages.select{|m| m =~ /Cleaning up Decommutation/}.length).to eq 1
33
33
  expect(messages.select{|m| m =~ /Database cleanup complete/}.length).to eq 1
34
34
  end
35
35
  end
@@ -18,6 +18,7 @@ describe DartDecomQuery do
18
18
  before(:each) do
19
19
  DatabaseCleaner.strategy = :truncation
20
20
  DatabaseCleaner.clean
21
+ Rails.application.load_seed
21
22
  @query = DartDecomQuery.new
22
23
  # Put all the known targets and packets into the DB
23
24
  @query.sync_targets_and_packets
@@ -17,6 +17,7 @@ describe DartDecommutator do
17
17
  before(:each) do
18
18
  DatabaseCleaner.strategy = :truncation
19
19
  DatabaseCleaner.clean
20
+ Rails.application.load_seed
20
21
  end
21
22
 
22
23
  describe "run" do
@@ -25,6 +25,7 @@ describe DartImporter do
25
25
  before(:each) do
26
26
  DatabaseCleaner.strategy = :truncation
27
27
  DatabaseCleaner.clean
28
+ Rails.application.load_seed
28
29
  # Clean the dart logs
29
30
  Dir["#{Cosmos::System.paths['DART_LOGS']}/*"].each do |filename|
30
31
  FileUtils.rm_f filename
@@ -15,10 +15,14 @@ describe DartPacketLogWriter do
15
15
  before(:each) do
16
16
  DatabaseCleaner.strategy = :truncation
17
17
  DatabaseCleaner.clean
18
+ Rails.application.load_seed
18
19
  end
19
20
 
20
21
  describe "write" do
21
22
  it "creates PacketLogEntries and flushes the file" do
23
+ DatabaseCleaner.clean
24
+ Rails.application.load_seed
25
+
22
26
  writer = DartPacketLogWriter.new(
23
27
  :TLM, # Log telemetry
24
28
  'test_dart_tlm_', # Put dart_ in the log file name
@@ -28,7 +32,7 @@ describe DartPacketLogWriter do
28
32
  Cosmos::System.paths['DART_DATA']) # Log into the DART_DATA dir
29
33
 
30
34
  hs_packet = Cosmos::System.telemetry.packet("INST", "HEALTH_STATUS")
31
- (DartPacketLogWriter::DEFAULT_SYNC_COUNT_LIMIT - 1).times do
35
+ (DartPacketLogWriter::DEFAULT_SYNC_COUNT_LIMIT).times do
32
36
  hs_packet.received_time = Time.now
33
37
  writer.write(hs_packet)
34
38
  sleep 0.01
@@ -39,7 +43,7 @@ describe DartPacketLogWriter do
39
43
  ple = PacketLogEntry.find(1)
40
44
  expect(ple.target.name).to eq "SYSTEM"
41
45
  expect(ple.packet.name).to eq "META"
42
- expect(ple.ready).to eq false # Hasn't been flushed yet
46
+ expect(ple.ready).to eq true
43
47
 
44
48
  packet = writer.read_packet_from_ple(ple)
45
49
  expect(packet.class).to eq Cosmos::Packet
@@ -49,35 +53,38 @@ describe DartPacketLogWriter do
49
53
  target = Target.find_by_name("INST")
50
54
  packet = Packet.find_by_name("HEALTH_STATUS")
51
55
  count = 0
52
- previous_time = Time.now
53
- PacketLogEntry.where("target_id = ? and packet_id = ?", target.id, packet.id).each do |ple|
54
- expect(ple.target.name).to eq "INST"
55
- expect(ple.packet.name).to eq "HEALTH_STATUS"
56
- expect(ple.ready).to eq false # Hasn't been flushed yet
57
-
58
- packet = writer.read_packet_from_ple(ple)
59
- expect(packet.target_name).to eq "INST"
60
- expect(packet.packet_name).to eq "HEALTH_STATUS"
61
- expect(packet.received_time).to_not eq previous_time
62
- previous_time = packet.received_time
63
- count += 1
64
- end
65
- expect(count).to eq (DartPacketLogWriter::DEFAULT_SYNC_COUNT_LIMIT - 1)
56
+ count = PacketLogEntry.where("target_id = ? and packet_id = ?", target.id, packet.id).count
57
+ expect(count).to eq (0)
66
58
 
67
59
  hs_packet.received_time = Time.now
68
60
  writer.write(hs_packet) # Write the packet that causes the flush
69
61
  sleep 0.1
70
62
  count = 0
63
+ previous_time = Time.now
71
64
  PacketLogEntry.all.each do |ple|
72
- if count < DartPacketLogWriter::DEFAULT_SYNC_COUNT_LIMIT
73
- expect(ple.ready).to eq true # Flushed!
65
+ if count == 0
66
+ expect(ple.target.name).to eq "SYSTEM"
67
+ expect(ple.packet.name).to eq "META"
68
+ expect(ple.ready).to eq true
69
+
70
+ packet = writer.read_packet_from_ple(ple)
71
+ expect(packet.target_name).to eq "SYSTEM"
72
+ expect(packet.packet_name).to eq "META"
73
+ expect(packet.received_time).to_not eq previous_time
74
74
  else
75
- # The last write isn't flushed
76
- expect(ple.ready).to eq false
75
+ expect(ple.target.name).to eq "INST"
76
+ expect(ple.packet.name).to eq "HEALTH_STATUS"
77
+ expect(ple.ready).to eq true
78
+
79
+ packet = writer.read_packet_from_ple(ple)
80
+ expect(packet.target_name).to eq "INST"
81
+ expect(packet.packet_name).to eq "HEALTH_STATUS"
82
+ expect(packet.received_time).to_not eq previous_time
77
83
  end
84
+ previous_time = packet.received_time
78
85
  count += 1
79
86
  end
80
- # We wrote one SYSTEM META plus (DartPacketLogWriter::DEFAULT_SYNC_COUNT_LIMIT - 1)
87
+ # We wrote one SYSTEM META plus (DartPacketLogWriter::DEFAULT_SYNC_COUNT_LIMIT)
81
88
  # plus one more to cause the flush
82
89
  expect(count).to eq DartPacketLogWriter::DEFAULT_SYNC_COUNT_LIMIT + 1
83
90
  writer.shutdown
@@ -89,6 +96,8 @@ describe DartPacketLogWriter do
89
96
 
90
97
  it "creates command logs" do
91
98
  DatabaseCleaner.clean
99
+ Rails.application.load_seed
100
+
92
101
  meta = Cosmos::System.commands.packet("SYSTEM", "META")
93
102
  clr_cmd = Cosmos::System.commands.packet("INST", "CLEAR")
94
103
  # 128 byte file header, SYSTEM META has 24 byte header,
@@ -111,36 +120,30 @@ describe DartPacketLogWriter do
111
120
  ple = PacketLogEntry.find(1)
112
121
  expect(ple.target.name).to eq "SYSTEM"
113
122
  expect(ple.packet.name).to eq "META"
114
- expect(ple.ready).to eq false # Hasn't been flushed yet
123
+ expect(ple.ready).to eq true
124
+
125
+ clr_cmd.received_time = Time.now
126
+ writer.write(clr_cmd) # The second command should create a new log
127
+ sleep 0.1
115
128
 
116
129
  # The second Log Entry is the command
117
130
  ple = PacketLogEntry.find(2)
118
131
  expect(ple.target.name).to eq "INST"
119
132
  expect(ple.packet.name).to eq "CLEAR"
120
- expect(ple.ready).to eq false # Hasn't been flushed yet
133
+ expect(ple.ready).to eq true
121
134
 
122
- clr_cmd.received_time = Time.now
123
- writer.write(clr_cmd) # The second command should create a new log
135
+ writer.shutdown
124
136
  sleep 0.1
125
137
 
126
- # Check the the first two have been flushed
127
- ple = PacketLogEntry.find(1)
128
- expect(ple.ready).to eq true # Flushed
129
- ple = PacketLogEntry.find(2)
130
- expect(ple.ready).to eq true # Flushed
131
-
132
138
  # The third and fourth are SYSTEM META and the command
133
139
  ple = PacketLogEntry.find(3)
134
140
  expect(ple.target.name).to eq "SYSTEM"
135
141
  expect(ple.packet.name).to eq "META"
136
- expect(ple.ready).to eq false # Hasn't been flushed yet
142
+ expect(ple.ready).to eq true
137
143
  ple = PacketLogEntry.find(4)
138
144
  expect(ple.target.name).to eq "INST"
139
145
  expect(ple.packet.name).to eq "CLEAR"
140
- expect(ple.ready).to eq false # Hasn't been flushed yet
141
-
142
- writer.shutdown
143
- sleep 0.1
146
+ expect(ple.ready).to eq true
144
147
 
145
148
  files = Dir["#{Cosmos::System.paths['DART_DATA']}/*_test_dart_cmd_*"]
146
149
  expect(files.length).to eq 2