scout-gear 6.0.0 → 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
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 TestTSV < Test::Unit::TestCase
5
+ def test_open_with_data
6
+ content =<<-'EOF'
7
+ #: :sep=/\s+/#:type=:double#:merge=:concat
8
+ #Id ValueA ValueB OtherID
9
+ row1 a|aa|aaa b Id1|Id2
10
+ row2 A B Id3
11
+ row2 a a id3
12
+ EOF
13
+
14
+ content2 =<<-'EOF'
15
+ #: :sep=/\s+/#:type=:double#:merge=:concat
16
+ #Id ValueA ValueB OtherID
17
+ row3 a|aa|aaa b Id1|Id2
18
+ row4 A B Id3
19
+ row4 a a id3
20
+ EOF
21
+
22
+ tsv = TmpFile.with_file(content) do |filename|
23
+ TSV.open(filename)
24
+ end
25
+
26
+ TmpFile.with_file(content2) do |filename|
27
+ TSV.open(filename, :data => tsv)
28
+ end
29
+
30
+ assert_include tsv.keys, 'row4'
31
+ assert_include tsv.keys, 'row1'
32
+ end
33
+ end
34
+
@@ -89,5 +89,33 @@ class TestWorkQueue < Test::Unit::TestCase
89
89
 
90
90
  assert_equal 0, res.length
91
91
  end
92
+
93
+ def test_queue_error
94
+ num = 10
95
+ reps = 10_000
96
+
97
+ q = WorkQueue.new num do |obj|
98
+ raise ScoutException if rand < 1
99
+ [Process.pid.to_s, obj.to_s] * " "
100
+ end
101
+
102
+ res = []
103
+ q.process do |out|
104
+ res << out
105
+ end
106
+
107
+ pid = Process.fork do
108
+ reps.times do |i|
109
+ q.write i
110
+ end
111
+ end
112
+
113
+ Process.wait pid
114
+
115
+ assert_raise ScoutException do
116
+ q.close
117
+ q.join
118
+ end
119
+ end
92
120
  end
93
121
 
@@ -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
@@ -95,5 +95,53 @@ class TestQueueWorker < Test::Unit::TestCase
95
95
  output.clean
96
96
  end
97
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
+
98
146
  end
99
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: 6.0.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-29 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
@@ -146,6 +146,8 @@ files:
146
146
  - lib/scout/simple_opt/parse.rb
147
147
  - lib/scout/simple_opt/setup.rb
148
148
  - lib/scout/tmpfile.rb
149
+ - lib/scout/tsv.rb
150
+ - lib/scout/tsv/parser.rb
149
151
  - lib/scout/work_queue.rb
150
152
  - lib/scout/work_queue/socket.rb
151
153
  - lib/scout/work_queue/worker.rb
@@ -206,8 +208,10 @@ files:
206
208
  - test/scout/test_resource.rb
207
209
  - test/scout/test_semaphore.rb
208
210
  - test/scout/test_tmpfile.rb
211
+ - test/scout/test_tsv.rb
209
212
  - test/scout/test_work_queue.rb
210
213
  - test/scout/test_workflow.rb
214
+ - test/scout/tsv/test_parser.rb
211
215
  - test/scout/work_queue/test_socket.rb
212
216
  - test/scout/work_queue/test_worker.rb
213
217
  - test/scout/workflow/step/test_info.rb