io-tail 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ $: << File.dirname(__FILE__)
5
+ $: << File.join(File.dirname(__FILE__),'..', 'lib')
6
+
7
+
8
+ require 'test_helper'
9
+ require 'io-tail'
10
+ require 'timeout'
11
+ require 'thread'
12
+ Thread.abort_on_exception = true
13
+
14
+ class ProcessTailTest < Test::Unit::TestCase
15
+
16
+ def setup
17
+ @out = File.new("test.#$$", "wb")
18
+ @in = IO::Tail::Process.new("tail -n 0 -F test.#$$")
19
+ @in.interval = 0.1
20
+ @in.max_interval = 0.2
21
+ @in.reopen_deleted = true # is default
22
+ @in.reopen_suspicious = true # is default
23
+ @in.suspicious_interval = 60
24
+ end
25
+ TAIL_CONTENT = ['foo', 'bar', 'qux', 'dog', 'hop', 'mooh']
26
+ # We should be able to do a tail as with a regular file...
27
+ def test_tail_with_block
28
+ teardown
29
+ setup
30
+ Thread.new do
31
+ sleep(2)
32
+ TAIL_CONTENT.each do |fragment|
33
+ @out.puts fragment
34
+ $stdout.flush
35
+ @out.flush
36
+ end
37
+ end
38
+ timeout(5) do
39
+ tail_position = 0
40
+ @in.tail { |l|
41
+ $stdout.flush
42
+
43
+ assert_equal(TAIL_CONTENT[tail_position], l.chomp)
44
+ tail_position += 1
45
+ # Exit when all content has been seen
46
+ break if tail_position == TAIL_CONTENT.length
47
+ }
48
+ end
49
+ end
50
+
51
+ # However, seeking is not possible for a process
52
+ def test_cannot_seek
53
+ assert_raise(NoMethodError) { @in.backward(1) }
54
+ assert_raise(NoMethodError) { @in.forward(1) }
55
+ end
56
+
57
+ # A killed process will be restarted if reopen_* is true
58
+ def test_killed_child_will_reopen
59
+ # Force test resetup
60
+ teardown
61
+ setup
62
+
63
+ Thread.new do
64
+ # Wait a bit for the tailer to be ready
65
+ sleep(1)
66
+ TAIL_CONTENT.each_with_index do |fragment, position|
67
+ @out.puts fragment
68
+ @out.flush
69
+ if position == 2
70
+ @in.kill_inner
71
+ # The tailer will see something's wrong and hopefully reopen the process
72
+ # We have to wait a bit for the tailer to notice the process is down and restart it
73
+ sleep(4)
74
+ end
75
+ end
76
+ end
77
+ timeout(6) do
78
+ tail_position = 0
79
+ @in.tail { |l|
80
+ assert_equal(TAIL_CONTENT[tail_position], l.chomp)
81
+ tail_position += 1
82
+ # Exit when all content has been seen
83
+ break if tail_position == TAIL_CONTENT.length
84
+ }
85
+ end
86
+
87
+ end
88
+
89
+ def teardown
90
+ @in.close
91
+ @out.close
92
+ File.unlink(@out.path)
93
+ end
94
+
95
+ private
96
+
97
+ def count(file)
98
+ n = 0
99
+ until file.eof?
100
+ file.readline
101
+ n += 1
102
+ end
103
+ return n
104
+ end
105
+
106
+ end
@@ -0,0 +1,7 @@
1
+ if ENV['START_SIMPLECOV'].to_i == 1
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter "#{File.basename(File.dirname(__FILE__))}/"
5
+ end
6
+ end
7
+ require 'test/unit'
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: io-tail
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pierre Baillet
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: gem_hadar
16
+ requirement: &70303751110000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.4
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70303751110000
25
+ - !ruby/object:Gem::Dependency
26
+ name: test-unit
27
+ requirement: &70303751109580 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.4.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70303751109580
36
+ - !ruby/object:Gem::Dependency
37
+ name: tins
38
+ requirement: &70303751109160 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.3'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70303751109160
47
+ description: Library to tail files and process in Ruby
48
+ email: pierre@baillet.name
49
+ executables:
50
+ - rtail
51
+ extensions: []
52
+ extra_rdoc_files:
53
+ - README.rdoc
54
+ - lib/io/tail/group.rb
55
+ - lib/io/tail/line_extension.rb
56
+ - lib/io/tail/logfile.rb
57
+ - lib/io/tail/process.rb
58
+ - lib/io/tail/tailer.rb
59
+ - lib/io/tail/version.rb
60
+ - lib/io/tail.rb
61
+ - lib/io-tail.rb
62
+ files:
63
+ - .gitignore
64
+ - .travis.yml
65
+ - CHANGES
66
+ - COPYING
67
+ - Gemfile
68
+ - README.rdoc
69
+ - Rakefile
70
+ - bin/rtail
71
+ - examples/pager.rb
72
+ - examples/tail.rb
73
+ - lib/io-tail.rb
74
+ - lib/io/tail.rb
75
+ - lib/io/tail/group.rb
76
+ - lib/io/tail/line_extension.rb
77
+ - lib/io/tail/logfile.rb
78
+ - lib/io/tail/process.rb
79
+ - lib/io/tail/tailer.rb
80
+ - lib/io/tail/version.rb
81
+ - tests/file_tail_group_test.rb
82
+ - tests/file_tail_test.rb
83
+ - tests/process_tail_test.rb
84
+ - tests/test_helper.rb
85
+ homepage: http://github.com/octplane/ruby-io-tail
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --title
90
+ - Io-tail - Io::Tail for Ruby
91
+ - --main
92
+ - README.rdoc
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.11
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Io::Tail for Ruby
113
+ test_files:
114
+ - tests/file_tail_group_test.rb
115
+ - tests/file_tail_test.rb
116
+ - tests/process_tail_test.rb
117
+ - tests/test_helper.rb