Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trojan-go: use TCPServer instead of WEBrick for test #162360

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions Formula/t/trojan-go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ def caveats
end

test do
require "webrick"

(testpath/"test.crt").write <<~EOS
-----BEGIN CERTIFICATE-----
MIIBuzCCASQCCQDC8CtpZ04+pTANBgkqhkiG9w0BAQsFADAhMQswCQYDVQQGEwJV
Expand Down Expand Up @@ -114,8 +112,17 @@ def caveats
EOS

http_server_port = free_port
http_server = WEBrick::HTTPServer.new Port: http_server_port
Thread.new { http_server.start }
fork do
server = TCPServer.new(http_server_port)
loop do
socket = server.accept
socket.write "HTTP/1.1 200 OK\r\n" \
"Content-Type: text/plain; charset=utf-8\r\n" \
"Content-Length: 0\r\n" \
"\r\n"
socket.close
end
end

trojan_go_server_port = free_port
(testpath/"server.yaml").write <<~EOS
Expand Down Expand Up @@ -149,13 +156,13 @@ def caveats

sleep 3
begin
system "curl", "--socks5", "127.0.0.1:#{trojan_go_client_port}", "github.com"
output = shell_output("curl --socks5 127.0.0.1:#{trojan_go_client_port} example.com")
assert_match "<title>Example Domain</title>", output
ensure
Process.kill 9, server
Process.wait server
Process.kill 9, client
Process.wait client
http_server.shutdown
end
end
end
Loading