@@ -53,28 +53,33 @@ module FileWatch
53
53
end
54
54
55
55
context "create + rename rotation: when a new logfile is renamed to a path we have seen before and the open file is fully read, renamed outside glob" do
56
+ let ( :stat_interval ) { 0.04 }
57
+ let ( :discover_interval ) { 15 }
58
+
56
59
let ( :watch_dir ) { directory . join ( "*A.log" ) }
57
60
let ( :file_path ) { directory . join ( "1A.log" ) }
58
61
subject { described_class . new ( conf ) }
59
62
let ( :listener1 ) { observer . listener_for ( file1_path ) }
60
63
let ( :listener2 ) { observer . listener_for ( second_file . to_path ) }
61
64
let ( :actions ) do
62
65
RSpec ::Sequencing
63
- . run_after ( 0.25 , "create file" ) do
64
- file_path . open ( "wb" ) { |file | file . write ( "#{ line1 } \n " ) }
65
- end
66
- . then_after ( 0.25 , "write a 'unfinished' line" ) do
67
- file_path . open ( "ab" ) { |file | file . write ( line2 ) }
68
- end
69
- . then_after ( 0.25 , "rotate once" ) do
70
- tmpfile = directory . join ( "1.logtmp" )
71
- tmpfile . open ( "wb" ) { |file | file . write ( "\n #{ line3 } \n " ) }
66
+ . run_after ( 1.25 , "create file" ) do
67
+ file_path . open ( "wb" ) { |file | file . write ( "#{ line1 } \n " ) }
68
+ end
69
+ . then_after ( 1.25 , "write a 'unfinished' line" ) do
70
+ file_path . open ( "ab" ) { |file | file . write ( "#{ line2 } " ) }
71
+ end
72
+ . then_after ( 1.25 , "rotate once" ) do
73
+ tmpfile = directory . join ( "1.logtmp" )
74
+ tmpfile . open ( "wb" ) { |file |
75
+ file . write ( "\n #{ line3 } \n " )
76
+ }
72
77
file_path . rename ( directory . join ( "1.log.1" ) )
73
78
FileUtils . mv ( directory . join ( "1.logtmp" ) . to_path , file1_path )
74
- end
79
+ end
75
80
. then ( "wait for expectation" ) do
76
- sleep ( 0 .25) # if ENV['CI']
77
- wait ( 2 ) . for { listener1 . calls } . to eq ( [ :open , :accept , :accept , :accept ] )
81
+ sleep ( 1 .25) # if ENV['CI']
82
+ wait ( 2 ) . for { listener1 . calls } . to include ( :open , :accept , :accept , :accept )
78
83
end
79
84
. then ( "quit" ) do
80
85
tailing . quit
@@ -104,14 +109,14 @@ module FileWatch
104
109
let ( :listener3 ) { observer . listener_for ( third_file . to_path ) }
105
110
let ( :actions ) do
106
111
RSpec ::Sequencing
107
- . run_after ( 0.25 , "create file" ) do
112
+ . run_after ( 0.75 , "create file" ) do
108
113
file_path . open ( "wb" ) { |file | file . write ( "#{ line1 } \n " ) }
109
114
end
110
- . then_after ( 0.25 , "rotate 1 - line1(66) is in 2B.log, line2(61) is in 1B.log" ) do
115
+ . then_after ( 0.75 , "rotate 1 - line1(66) is in 2B.log, line2(61) is in 1B.log" ) do
111
116
file_path . rename ( second_file )
112
117
file_path . open ( "wb" ) { |file | file . write ( "#{ line2 } \n " ) }
113
118
end
114
- . then_after ( 0.25 , "rotate 2 - line1(66) is in 3B.log, line2(61) is in 2B.log, line3(47) is in 1B.log" ) do
119
+ . then_after ( 0.75 , "rotate 2 - line1(66) is in 3B.log, line2(61) is in 2B.log, line3(47) is in 1B.log" ) do
115
120
second_file . rename ( third_file )
116
121
file_path . rename ( second_file )
117
122
file_path . open ( "wb" ) { |file | file . write ( "#{ line3 } \n " ) }
@@ -145,19 +150,19 @@ module FileWatch
145
150
let ( :listener2 ) { observer . listener_for ( second_file . to_path ) }
146
151
let ( :actions ) do
147
152
RSpec ::Sequencing
148
- . run_after ( 0.25 , "create original - write line 1, 66 bytes" ) do
153
+ . run_after ( 0.75 , "create original - write line 1, 66 bytes" ) do
149
154
file_path . open ( "wb" ) { |file | file . write ( "#{ line1 } \n " ) }
150
155
end
151
- . then_after ( 0.25 , "rename to 2.log" ) do
156
+ . then_after ( 0.75 , "rename to 2.log" ) do
152
157
file_path . rename ( second_file )
153
158
end
154
- . then_after ( 0.25 , "write line 2 to original, 61 bytes" ) do
159
+ . then_after ( 0.75 , "write line 2 to original, 61 bytes" ) do
155
160
file_path . open ( "wb" ) { |file | file . write ( "#{ line2 } \n " ) }
156
161
end
157
- . then_after ( 0.25 , "rename to 2.log again" ) do
162
+ . then_after ( 0.75 , "rename to 2.log again" ) do
158
163
file_path . rename ( second_file )
159
164
end
160
- . then_after ( 0.25 , "write line 3 to original, 47 bytes" ) do
165
+ . then_after ( 0.75 , "write line 3 to original, 47 bytes" ) do
161
166
file_path . open ( "wb" ) { |file | file . write ( "#{ line3 } \n " ) }
162
167
end
163
168
. then ( "wait for expectations to be met" ) do
@@ -267,14 +272,14 @@ module FileWatch
267
272
let ( :listener1 ) { observer . listener_for ( file1_path ) }
268
273
let ( :actions ) do
269
274
RSpec ::Sequencing
270
- . run_after ( 0.25 , "create file" ) do
275
+ . run_after ( 0.75 , "create file" ) do
271
276
file_path . open ( "wb" ) { |file | file . puts ( line1 ) ; file . puts ( line2 ) }
272
277
end
273
- . then_after ( 0.25 , "rotate" ) do
278
+ . then_after ( 0.75 , "rotate" ) do
274
279
FileUtils . cp ( file1_path , directory . join ( "1F.log.1" ) . to_path )
275
280
file_path . truncate ( 0 )
276
281
end
277
- . then_after ( 0.25 , "write to truncated file" ) do
282
+ . then_after ( 0.75 , "write to truncated file" ) do
278
283
file_path . open ( "wb" ) { |file | file . puts ( line3 ) }
279
284
end
280
285
. then ( "wait for expectations to be met" ) do
@@ -342,13 +347,13 @@ module FileWatch
342
347
let ( :listener2 ) { observer . listener_for ( file2 . to_path ) }
343
348
let ( :actions ) do
344
349
RSpec ::Sequencing
345
- . run_after ( 0.25 , "create file" ) do
350
+ . run_after ( 0.75 , "create file" ) do
346
351
file_path . open ( "wb" ) { |file | file . puts ( line1 ) ; file . puts ( line2 ) }
347
352
end
348
- . then_after ( 0.25 , "rename" ) do
353
+ . then_after ( 0.75 , "rename" ) do
349
354
FileUtils . mv ( file1_path , file2 . to_path )
350
355
end
351
- . then_after ( 0.25 , "write to renamed file" ) do
356
+ . then_after ( 0.75 , "write to renamed file" ) do
352
357
file2 . open ( "ab" ) { |file | file . puts ( line3 ) }
353
358
end
354
359
. then ( "wait for expectations to be met" ) do
@@ -464,14 +469,14 @@ module FileWatch
464
469
. run_after ( 0.75 , "create file" ) do
465
470
file_path . open ( "wb" ) { |file | file . puts ( line1 ) ; file . puts ( line2 ) }
466
471
end
467
- . then_after ( 0.5 , "rename" ) do
472
+ . then_after ( 0.75 , "rename" ) do
468
473
file_path . rename ( second_file )
469
474
file_path . open ( "wb" ) { |file | file . puts ( "#{ line3 } " ) }
470
475
end
471
476
. then ( "wait for expectations to be met" ) do
472
477
wait ( 2.0 ) . for { listener1 . lines . size + listener2 . lines . size } . to eq ( 3 )
473
- end
474
- . then_after ( 0.5 , "rename again" ) do
478
+ end
479
+ . then_after ( 0.75 , "rename again" ) do
475
480
file_path . rename ( second_file )
476
481
file_path . open ( "wb" ) { |file | file . puts ( "#{ line4 } " ) }
477
482
end
0 commit comments