scout-gear 5.2.0 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,87 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/tsv'
5
+ class TestTSVParser < Test::Unit::TestCase
6
+
7
+ def test_parse_line
8
+ line = (0..10).to_a * "\t"
9
+ key, values = TSV.parse_line(line)
10
+
11
+ assert_equal "0", key
12
+ assert_equal (1..10).collect{|v| v.to_s }, values
13
+ end
14
+
15
+ def test_parse_double
16
+ line = (0..10).collect{|v| v == 0 ? v : [v,v] * "|" } * "\t"
17
+ key, values = TSV.parse_line(line, type: :double, cast: :to_i)
18
+
19
+ assert_equal "0", key
20
+ assert_equal (1..10).collect{|v| [v,v] }, values
21
+ end
22
+
23
+ def __test_benchmark
24
+ num = 10_000
25
+ txt = num.times.inject(nil) do |acc,i|
26
+ (acc.nil? ? "" : acc << "\n") << (0..10).collect{|v| v == 0 ? i : [v,v] * "|" } * "\t"
27
+ end
28
+
29
+ txt = StringIO.new(([txt] * (10))*"\n")
30
+ Misc.benchmark 1 do
31
+ #Misc.profile do
32
+ data = TSV.parse_stream(txt, fix: true, type: :double, bar: true, merge: :concat)
33
+ assert_equal num, data.size
34
+ assert_equal 20, data['1'][0].length
35
+ end
36
+ end
37
+
38
+ def test_parse_stream
39
+ lines =<<-EOF
40
+ 1 2 3 4 5
41
+ 11 12 13 14 15
42
+ EOF
43
+
44
+ lines = StringIO.new lines
45
+
46
+ data = TSV.parse_stream lines, sep: " "
47
+ assert_equal data["1"], %w(2 3 4 5)
48
+ end
49
+
50
+ def test_parse_stream_block
51
+ lines =<<-EOF
52
+ 1 2 3 4 5
53
+ 11 12 13 14 15
54
+ EOF
55
+
56
+ lines = StringIO.new lines
57
+
58
+ sum = 0
59
+ res = TSV.parse_stream(lines, sep: " ") do |k,values|
60
+ sum += values.inject(0){|acc,i| acc += i.to_i }
61
+ end
62
+ assert_equal 68, sum
63
+ end
64
+
65
+ def test_parse_header
66
+ header =<<-EOF
67
+ #: :sep=" "
68
+ #Key ValueA ValueB
69
+ k A B
70
+ EOF
71
+ header = StringIO.new header
72
+
73
+ assert_equal "Key", TSV.parse_header(header)[1]
74
+ end
75
+
76
+ def test_parse
77
+ header =<<-EOF
78
+ #: :sep=" "#:type=:double
79
+ #Key ValueA ValueB
80
+ k a|A b|B
81
+ EOF
82
+ header = StringIO.new header
83
+
84
+ tsv = TSV.parse(header)
85
+ assert_equal 'a', tsv['k'][0][0]
86
+ end
87
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestSocket < Test::Unit::TestCase
5
+ def test_simple
6
+ socket = WorkQueue::Socket.new
7
+
8
+ socket.write 1
9
+ socket.write 2
10
+ socket.write "STRING"
11
+ socket.write :string
12
+
13
+ assert_equal 1, socket.read
14
+ assert_equal 2, socket.read
15
+ assert_equal "STRING", socket.read
16
+ assert_equal :string, socket.read
17
+
18
+ socket.close_write
19
+ assert_raise ClosedStream do
20
+ socket.read
21
+ end
22
+ end
23
+
24
+ def __test_speed
25
+ sss 0
26
+ socket = WorkQueue::Socket.new
27
+
28
+ num = 10_000
29
+
30
+ Thread.new do
31
+ num.times do |i|
32
+ socket.write nil
33
+ end
34
+ socket.write DoneProcessing.new
35
+ end
36
+
37
+ bar = Log::ProgressBar.new num
38
+ while true
39
+ i = socket.read
40
+ bar.tick
41
+ break if DoneProcessing === i
42
+ end
43
+ bar.done
44
+ end
45
+ end
46
+
@@ -0,0 +1,147 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ require 'scout/semaphore'
5
+ require 'scout/work_queue/socket'
6
+ class TestQueueWorker < Test::Unit::TestCase
7
+ def test_simple
8
+ worker = WorkQueue::Worker.new
9
+ TmpFile.with_file do |file|
10
+ worker.run do
11
+ Open.write file, "TEST"
12
+ end
13
+ worker.join
14
+
15
+ assert_equal "TEST", Open.read(file)
16
+ end
17
+ end
18
+
19
+ def test_semaphore
20
+ ScoutSemaphore.with_semaphore 1 do |sem|
21
+
22
+ TmpFile.with_file do |outfile|
23
+ 2.times do
24
+ sout = Open.open_pipe do |sin|
25
+ workers = 100.times.collect{ WorkQueue::Worker.new }
26
+ workers.each do |w|
27
+ w.run do
28
+ ScoutSemaphore.synchronize(sem) do
29
+ 10.times do
30
+ sin.puts Process.pid
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ WorkQueue::Worker.join(workers)
37
+ end
38
+ Open.consume_stream(sout, false, outfile)
39
+ pid_list = Open.read(outfile).split("\n")
40
+
41
+ assert_nothing_raised do
42
+ seen = []
43
+ current = nil
44
+ pid_list.each do |pid|
45
+ if pid != current
46
+ raise "Out of order" if seen.include? pid
47
+ end
48
+ current = pid
49
+ seen << pid
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def test_process
58
+ input = WorkQueue::Socket.new
59
+ output = WorkQueue::Socket.new
60
+
61
+ workers = 10.times.collect{ WorkQueue::Worker.new }
62
+ workers.each do |w|
63
+ w.process(input, output) do |obj|
64
+ [Process.pid, obj.inspect] * " "
65
+ end
66
+ end
67
+
68
+ read = Thread.new do
69
+ begin
70
+ while obj = output.read
71
+ if DoneProcessing === obj
72
+ pid = obj.pid
73
+ workers.delete_if{|w| w.pid = pid }
74
+ break if workers.empty?
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ write = Thread.new do
81
+ 100.times do |i|
82
+ input.write i
83
+ end
84
+ 10.times do
85
+ input.write DoneProcessing.new
86
+ end
87
+ input.close_write
88
+ end
89
+
90
+ write.join
91
+ read.join
92
+
93
+ WorkQueue::Worker.join workers
94
+ input.clean
95
+ output.clean
96
+ end
97
+
98
+ def test_process_exception
99
+ input = WorkQueue::Socket.new
100
+ output = WorkQueue::Socket.new
101
+
102
+ workers = 10.times.collect{ WorkQueue::Worker.new }
103
+ workers.each do |w|
104
+ w.process(input, output) do |obj|
105
+ raise ScoutException
106
+ [Process.pid, obj.inspect] * " "
107
+ end
108
+ end
109
+
110
+ read = Thread.new do
111
+ Thread.current.report_on_exception = false
112
+ begin
113
+ while obj = output.read
114
+ if DoneProcessing === obj
115
+ pid = obj.pid
116
+ workers.delete_if{|w| w.pid = pid }
117
+ break if workers.empty?
118
+ end
119
+ raise obj if Exception === obj
120
+ end
121
+ end
122
+ end
123
+
124
+ write = Thread.new do
125
+ Thread.report_on_exception = false
126
+ 100.times do |i|
127
+ input.write i
128
+ end
129
+ 10.times do
130
+ input.write DoneProcessing.new
131
+ end
132
+ input.close_write
133
+ end
134
+
135
+ write.join
136
+
137
+ assert_raise ScoutException do
138
+ read.join
139
+ end
140
+
141
+ WorkQueue::Worker.join workers
142
+ input.clean
143
+ output.clean
144
+ end
145
+
146
+ end
147
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout-gear
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-28 00:00:00.000000000 Z
11
+ date: 2023-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: term-ansicolor
@@ -138,6 +138,7 @@ files:
138
138
  - lib/scout/resource/produce/rake.rb
139
139
  - lib/scout/resource/scout.rb
140
140
  - lib/scout/resource/util.rb
141
+ - lib/scout/semaphore.rb
141
142
  - lib/scout/simple_opt.rb
142
143
  - lib/scout/simple_opt/accessor.rb
143
144
  - lib/scout/simple_opt/doc.rb
@@ -145,6 +146,11 @@ files:
145
146
  - lib/scout/simple_opt/parse.rb
146
147
  - lib/scout/simple_opt/setup.rb
147
148
  - lib/scout/tmpfile.rb
149
+ - lib/scout/tsv.rb
150
+ - lib/scout/tsv/parser.rb
151
+ - lib/scout/work_queue.rb
152
+ - lib/scout/work_queue/socket.rb
153
+ - lib/scout/work_queue/worker.rb
148
154
  - lib/scout/workflow.rb
149
155
  - lib/scout/workflow/definition.rb
150
156
  - lib/scout/workflow/documentation.rb
@@ -165,8 +171,11 @@ files:
165
171
  - scout_commands/workflow/list
166
172
  - scout_commands/workflow/task
167
173
  - scout_commands/workflow/task_old
174
+ - share/color/color_names
175
+ - share/color/diverging_colors.hex
168
176
  - test/scout/indiferent_hash/test_case_insensitive.rb
169
177
  - test/scout/indiferent_hash/test_options.rb
178
+ - test/scout/log/test_color.rb
170
179
  - test/scout/log/test_progress.rb
171
180
  - test/scout/misc/test_digest.rb
172
181
  - test/scout/misc/test_filesystem.rb
@@ -197,8 +206,14 @@ files:
197
206
  - test/scout/test_path.rb
198
207
  - test/scout/test_persist.rb
199
208
  - test/scout/test_resource.rb
209
+ - test/scout/test_semaphore.rb
200
210
  - test/scout/test_tmpfile.rb
211
+ - test/scout/test_tsv.rb
212
+ - test/scout/test_work_queue.rb
201
213
  - test/scout/test_workflow.rb
214
+ - test/scout/tsv/test_parser.rb
215
+ - test/scout/work_queue/test_socket.rb
216
+ - test/scout/work_queue/test_worker.rb
202
217
  - test/scout/workflow/step/test_info.rb
203
218
  - test/scout/workflow/step/test_load.rb
204
219
  - test/scout/workflow/task/test_inputs.rb