Skip to content

Commit

Permalink
Another strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
yoannchaudet committed Sep 13, 2024
1 parent 87d52c0 commit e97b31d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
11 changes: 6 additions & 5 deletions script/test-redirections
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
require 'socket'

# Start a webserver on a given port, serving a 301 redirection to a specific location
def start_server(port, location)
def start_server(port, location, log_mode)
server = TCPServer.new(port)
puts "Server started on port #{port}"

loop do
# Block until a client connects
client = server.accept

# Append a hit in the file
File.open("/tmp/bad-redirection#{ENV["RUBY_VERSION"]}.log", 'a') do |file|
File.open("/tmp/bad-redirection#{ENV["RUBY_VERSION"]}.log", log_mode) do |file|
file.sync = true # no bufferring
file.print("HIT #{port} ")
end
Expand All @@ -38,7 +39,7 @@ end

# Go!
threads = []
threads << Thread.new { start_server(9988, 'http://127.0.0.1:9987') } # HTTP 301
threads << Thread.new { start_server(9987, 'ftp://127.0.0.1:9986') } # HTTP 301
threads << Thread.new { start_server(9986, 'STOP') } # TCP close
threads << Thread.new { start_server(9988, 'http://127.0.0.1:9987', "w") } # HTTP 301
threads << Thread.new { start_server(9987, 'ftp://127.0.0.1:9986', "a") } # HTTP 301
threads << Thread.new { start_server(9986, 'STOP', "a") } # TCP close
threads.each(&:join)
9 changes: 2 additions & 7 deletions spec/github_pages_health_check/domain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,6 @@

context "Protocol redirections" do
let(:log_file) { "/tmp/bad-redirection#{ENV["RUBY_VERSION"]}.log" }
before do
File.open(log_file, "w") do |file|
# Just truncate the file (without buffering to avoid flakiness)
file.sync = true
end
sleep(0.5) # slow down just a little to limit flakiness too
end

it "it follows ftp if requested" do
# Make a real request to a local server started with /script/test-redirections
Expand All @@ -689,6 +682,7 @@
)

# Confirm port 9986 was hit (it is the FTP one)
sleep(0.1) until File.exist?(log_file)
expect(File.read(log_file).strip).to eq("HIT 9988 HIT 9987 HIT 9986")
end

Expand All @@ -700,6 +694,7 @@
)

# Confirm port 9986 was NOT hit (it is the FTP one)
sleep(0.1) until File.exist?(log_file)
expect(File.read(log_file).strip).to eq("HIT 9988 HIT 9987")
end
end
Expand Down

0 comments on commit e97b31d

Please sign in to comment.