Skip to content

Commit 60b4015

Browse files
committed
Add additional sleep delays for tests
1 parent 381a4ee commit 60b4015

File tree

4 files changed

+49
-43
lines changed

4 files changed

+49
-43
lines changed

spec/filewatch/rotate_spec.rb

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,33 @@ module FileWatch
5353
end
5454

5555
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+
5659
let(:watch_dir) { directory.join("*A.log") }
5760
let(:file_path) { directory.join("1A.log") }
5861
subject { described_class.new(conf) }
5962
let(:listener1) { observer.listener_for(file1_path) }
6063
let(:listener2) { observer.listener_for(second_file.to_path) }
6164
let(:actions) do
6265
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+
}
7277
file_path.rename(directory.join("1.log.1"))
7378
FileUtils.mv(directory.join("1.logtmp").to_path, file1_path)
74-
end
79+
end
7580
.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)
7883
end
7984
.then("quit") do
8085
tailing.quit
@@ -104,14 +109,14 @@ module FileWatch
104109
let(:listener3) { observer.listener_for(third_file.to_path) }
105110
let(:actions) do
106111
RSpec::Sequencing
107-
.run_after(0.25, "create file") do
112+
.run_after(0.75, "create file") do
108113
file_path.open("wb") { |file| file.write("#{line1}\n") }
109114
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
111116
file_path.rename(second_file)
112117
file_path.open("wb") { |file| file.write("#{line2}\n") }
113118
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
115120
second_file.rename(third_file)
116121
file_path.rename(second_file)
117122
file_path.open("wb") { |file| file.write("#{line3}\n") }
@@ -145,19 +150,19 @@ module FileWatch
145150
let(:listener2) { observer.listener_for(second_file.to_path) }
146151
let(:actions) do
147152
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
149154
file_path.open("wb") { |file| file.write("#{line1}\n") }
150155
end
151-
.then_after(0.25, "rename to 2.log") do
156+
.then_after(0.75, "rename to 2.log") do
152157
file_path.rename(second_file)
153158
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
155160
file_path.open("wb") { |file| file.write("#{line2}\n") }
156161
end
157-
.then_after(0.25, "rename to 2.log again") do
162+
.then_after(0.75, "rename to 2.log again") do
158163
file_path.rename(second_file)
159164
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
161166
file_path.open("wb") { |file| file.write("#{line3}\n") }
162167
end
163168
.then("wait for expectations to be met") do
@@ -267,14 +272,14 @@ module FileWatch
267272
let(:listener1) { observer.listener_for(file1_path) }
268273
let(:actions) do
269274
RSpec::Sequencing
270-
.run_after(0.25, "create file") do
275+
.run_after(0.75, "create file") do
271276
file_path.open("wb") { |file| file.puts(line1); file.puts(line2) }
272277
end
273-
.then_after(0.25, "rotate") do
278+
.then_after(0.75, "rotate") do
274279
FileUtils.cp(file1_path, directory.join("1F.log.1").to_path)
275280
file_path.truncate(0)
276281
end
277-
.then_after(0.25, "write to truncated file") do
282+
.then_after(0.75, "write to truncated file") do
278283
file_path.open("wb") { |file| file.puts(line3) }
279284
end
280285
.then("wait for expectations to be met") do
@@ -342,13 +347,13 @@ module FileWatch
342347
let(:listener2) { observer.listener_for(file2.to_path) }
343348
let(:actions) do
344349
RSpec::Sequencing
345-
.run_after(0.25, "create file") do
350+
.run_after(0.75, "create file") do
346351
file_path.open("wb") { |file| file.puts(line1); file.puts(line2) }
347352
end
348-
.then_after(0.25, "rename") do
353+
.then_after(0.75, "rename") do
349354
FileUtils.mv(file1_path, file2.to_path)
350355
end
351-
.then_after(0.25, "write to renamed file") do
356+
.then_after(0.75, "write to renamed file") do
352357
file2.open("ab") { |file| file.puts(line3) }
353358
end
354359
.then("wait for expectations to be met") do
@@ -464,14 +469,14 @@ module FileWatch
464469
.run_after(0.75, "create file") do
465470
file_path.open("wb") { |file| file.puts(line1); file.puts(line2) }
466471
end
467-
.then_after(0.5, "rename") do
472+
.then_after(0.75, "rename") do
468473
file_path.rename(second_file)
469474
file_path.open("wb") { |file| file.puts("#{line3}") }
470475
end
471476
.then("wait for expectations to be met") do
472477
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
475480
file_path.rename(second_file)
476481
file_path.open("wb") { |file| file.puts("#{line4}") }
477482
end

spec/filewatch/tailing_spec.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module FileWatch
5858
ENV["FILEWATCH_MAX_FILES_WARN_INTERVAL"] = "0"
5959
File.open(file_path, "wb") { |file| file.write("line1\nline2\n") }
6060
File.open(file_path2, "wb") { |file| file.write("line-A\nline-B\n") }
61+
sleep(0.25) # if ENV['CI']
6162
end
6263

6364
context "when max_active is 1" do
@@ -76,7 +77,7 @@ module FileWatch
7677
end
7778

7879
context "when close_older is set" do
79-
let(:wait_before_quit) { 0.8 }
80+
let(:wait_before_quit) { 1.5 }
8081
let(:opts) { super().merge(:close_older => 0.1, :max_open_files => 1, :stat_interval => 0.1) }
8182
let(:suffix) { "B" }
8283
it "opens both files" do
@@ -134,7 +135,7 @@ module FileWatch
134135
File.open(file_path, "wb") { |file| file.write("line1\nline2\n") }
135136
end
136137
.then("wait") do
137-
wait(0.75).for { listener1.lines }.to_not be_empty
138+
wait(1.5).for { listener1.lines }.to_not be_empty
138139
end
139140
.then("quit") do
140141
tailing.quit
@@ -155,7 +156,7 @@ module FileWatch
155156
# it simulates that the user deleted the file
156157
# so when a stat is taken on the file an error is raised
157158
let(:suffix) { "E" }
158-
let(:quit_after) { 0.2 }
159+
let(:quit_after) { 1 }
159160
let(:stat) { double("stat", :size => 100, :modified_at => Time.now.to_f, :inode => 234567, :inode_struct => InodeStruct.new("234567", 1, 5)) }
160161
let(:watched_file) { WatchedFile.new(file_path, stat, tailing.settings) }
161162
before do
@@ -253,10 +254,10 @@ module FileWatch
253254
# create file after first discovery, will be read from the beginning
254255
File.open(file_path, "wb") { |file| file.write("line1\nline2\n") }
255256
end
256-
.then_after(0.55, "rename file") do
257+
.then_after(0.75, "rename file") do
257258
FileUtils.mv(file_path, new_file_path)
258259
end
259-
.then_after(0.55, "then write to renamed file") do
260+
.then_after(0.75, "then write to renamed file") do
260261
File.open(new_file_path, "ab") { |file| file.write("line3\nline4\n") }
261262
wait(0.5).for{listener1.lines.size}.to eq(2), "listener1.lines.size not eq(2)"
262263
end
@@ -354,7 +355,7 @@ module FileWatch
354355
end
355356
.then("watch and wait") do
356357
tailing.watch_this(watch_dir)
357-
wait(1.25).for{listener1.calls}.to eq([:open, :timed_out])
358+
wait(2).for{listener1.calls}.to eq([:open, :timed_out])
358359
end
359360
.then("quit") do
360361
tailing.quit

spec/inputs/file_read_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
end
103103

104104
events = input(conf) do |pipeline, queue|
105-
wait(0.5).for{File.exist?(tmpfile_path)}.to be_falsey
105+
wait(1).for{File.exist?(tmpfile_path)}.to be_falsey
106106
3.times.collect { queue.pop }
107107
end
108108

@@ -363,7 +363,7 @@ def wait_for_start_processing(run_thread, timeout: 1.0)
363363
end
364364
end
365365

366-
def wait_for_file_removal(path, timeout: 5 * interval)
367-
wait(timeout).for { File.exist?(path) }.to be_falsey
366+
def wait_for_file_removal(path)
367+
wait(5).for { File.exist?(path) }.to be_falsey
368368
end
369369
end

spec/inputs/file_tail_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288
.run("create file") do
289289
File.open(tmpfile_path, "wb") { |file| file.puts(line) }
290290
end
291-
.then_after(0.1, "identity is mapped") do
291+
.then_after(0.25, "identity is mapped") do
292292
wait(0.75).for{subject.codec.identity_map[tmpfile_path]}.not_to be_nil, "identity is not mapped"
293293
end
294294
.then("wait for auto_flush") do
@@ -395,7 +395,7 @@
395395
let(:suffix) { "M" }
396396
it "an event is generated via auto_flush" do
397397
actions = RSpec::Sequencing
398-
.run_after(0.1, "create files") do
398+
.run_after(0.25, "create files") do
399399
File.open(tmpfile_path, "wb") do |fd|
400400
fd.puts("line1.1-of-a")
401401
fd.puts(" line1.2-of-a")
@@ -478,7 +478,7 @@
478478
"sincedb_path" => sincedb_path,
479479
"stat_interval" => 0.1,
480480
"max_open_files" => 1,
481-
"close_older" => 0.5,
481+
"close_older" => 1,
482482
"start_position" => "beginning",
483483
"file_sort_by" => "path",
484484
"delimiter" => TEST_FILE_DELIMITER)
@@ -491,9 +491,9 @@
491491
wait(0.4).for{subject.codec.identity_count == 1 && events.size == 2}.to eq(true), "both identities are not mapped and the first two events are not built"
492492
end
493493
.then("wait for close to flush last event of each identity") do
494-
wait(0.8).for{events.size}.to eq(4), "close does not flush last event of each identity"
494+
wait(1.6).for{events.size}.to eq(4), "close does not flush last event of each identity"
495495
end
496-
.then_after(0.1, "stop") do
496+
.then_after(0.2, "stop") do
497497
subject.stop
498498
end
499499
subject.run(events)

0 commit comments

Comments
 (0)