100 lines
3.4 KiB
Ruby
100 lines
3.4 KiB
Ruby
class Condure < Formula
|
|
desc "HTTP/WebSocket connection manager"
|
|
homepage "https://github.com/fanout/condure"
|
|
url "https://github.com/fanout/condure/archive/1.1.0.tar.gz"
|
|
sha256 "28d19110765e78701b512cf81aba23e4a823e3f502c6e87c7e247554da748cfe"
|
|
license "Apache-2.0"
|
|
|
|
bottle do
|
|
rebuild 2
|
|
sha256 cellar: :any, arm64_big_sur: "49a9a397891392a99536028f60a15d951c942764e96f37ea7bab668710217ec6"
|
|
sha256 cellar: :any, big_sur: "4e037359206bf4563fc7c7d64809d7e22905d1624ddda1047d0b92aa81a51b88"
|
|
sha256 cellar: :any, catalina: "26957f142c585546573cadf4f89475803d55f308d3d63c51ee1248a70af3dd40"
|
|
sha256 cellar: :any, mojave: "09bed07fabc6999a7eaf9f44ab25085b64ca9400fd2988328226f2fbba37d428"
|
|
sha256 cellar: :any, high_sierra: "080bfe369f308022f3f766f7d9034e15114e17db0911dae9a37e482eb07954bf"
|
|
end
|
|
|
|
depends_on "pkg-config" => :build
|
|
depends_on "rust" => :build
|
|
depends_on "python@3.9" => :test
|
|
depends_on "openssl@1.1"
|
|
depends_on "zeromq"
|
|
|
|
resource "pyzmq" do
|
|
url "https://files.pythonhosted.org/packages/86/08/e5fc492317cc9d65b32d161c6014d733e8ab20b5e78e73eca63f53b17004/pyzmq-19.0.1.tar.gz"
|
|
sha256 "13a5638ab24d628a6ade8f794195e1a1acd573496c3b85af2f1183603b7bf5e0"
|
|
end
|
|
|
|
resource "tnetstring3" do
|
|
url "https://files.pythonhosted.org/packages/d9/fd/737a371f539842f6fcece47bb6b941700c9f924e8543cd35c4f3a2e7cc6c/tnetstring3-0.3.1.tar.gz"
|
|
sha256 "5acab57cce3693d119265a8ac019a9bcdc52a9cacb3ba37b5b3a1746a1c14d56"
|
|
end
|
|
|
|
def install
|
|
system "cargo", "install", *std_cargo_args
|
|
end
|
|
|
|
test do
|
|
ipcfile = testpath/"client"
|
|
runfile = testpath/"test.py"
|
|
|
|
resource("pyzmq").stage do
|
|
system Formula["python@3.9"].opt_bin/"python3",
|
|
*Language::Python.setup_install_args(testpath/"vendor")
|
|
end
|
|
|
|
resource("tnetstring3").stage do
|
|
system Formula["python@3.9"].opt_bin/"python3",
|
|
*Language::Python.setup_install_args(testpath/"vendor")
|
|
end
|
|
|
|
runfile.write(<<~EOS,
|
|
import threading
|
|
from urllib.request import urlopen
|
|
import tnetstring
|
|
import zmq
|
|
def server_worker(c):
|
|
ctx = zmq.Context()
|
|
sock = ctx.socket(zmq.REP)
|
|
sock.connect('ipc://#{ipcfile}')
|
|
c.acquire()
|
|
c.notify()
|
|
c.release()
|
|
while True:
|
|
m_raw = sock.recv()
|
|
req = tnetstring.loads(m_raw[1:])
|
|
resp = {}
|
|
resp[b'id'] = req[b'id']
|
|
resp[b'code'] = 200
|
|
resp[b'reason'] = b'OK'
|
|
resp[b'headers'] = [[b'Content-Type', b'text/plain']]
|
|
resp[b'body'] = b'test response\\n'
|
|
sock.send(b'T' + tnetstring.dumps(resp))
|
|
c = threading.Condition()
|
|
c.acquire()
|
|
server_thread = threading.Thread(target=server_worker, args=(c,))
|
|
server_thread.daemon = True
|
|
server_thread.start()
|
|
c.wait()
|
|
c.release()
|
|
with urlopen('http://localhost:10000/test') as f:
|
|
body = f.read()
|
|
assert(body == b'test response\\n')
|
|
EOS
|
|
)
|
|
|
|
pid = fork do
|
|
exec "#{bin}/condure", "--listen", "10000,req", "--zclient-req", "ipc://#{ipcfile}"
|
|
end
|
|
|
|
begin
|
|
xy = Language::Python.major_minor_version Formula["python@3.9"].opt_bin/"python3"
|
|
ENV["PYTHONPATH"] = testpath/"vendor/lib/python#{xy}/site-packages"
|
|
system Formula["python@3.9"].opt_bin/"python3", runfile
|
|
ensure
|
|
Process.kill("TERM", pid)
|
|
Process.wait(pid)
|
|
end
|
|
end
|
|
end
|