101 lines
3.6 KiB
Ruby
101 lines
3.6 KiB
Ruby
class Condure < Formula
|
|
desc "HTTP/WebSocket connection manager"
|
|
homepage "https://github.com/fanout/condure"
|
|
url "https://github.com/fanout/condure/archive/1.4.1.tar.gz"
|
|
sha256 "6a30cf8f5aa51d958099c15433f23dacc1a75780b1aace9a94dce40a5e755d90"
|
|
license "Apache-2.0"
|
|
|
|
bottle do
|
|
rebuild 1
|
|
sha256 cellar: :any, arm64_monterey: "e538eaabfae94e53c2805cdcf483f3b2679bfd73282a3b68edd60dc76e26065f"
|
|
sha256 cellar: :any, arm64_big_sur: "3e1756bea865579f5803300783b22f0e50bb50e9000462ff21f561c2a7e15e25"
|
|
sha256 cellar: :any, monterey: "7aa533fc9b521bd81b3c69e0a8fb709a5fe154167ffa8fb69572fd9a17efbd7e"
|
|
sha256 cellar: :any, big_sur: "919ed30c8281ab14d8c66952ec5b29e7485541c655c43464d5a488013d2d842f"
|
|
sha256 cellar: :any, catalina: "96d852229873b07d090f608d7ad087082c1b0653bf4d52be106edb4d7230561d"
|
|
sha256 cellar: :any_skip_relocation, x86_64_linux: "9e3c29f8c40503b76813a7e0cd89c9a9404d4c82ecb4d441f7a359f9b94eab34"
|
|
end
|
|
|
|
depends_on "pkg-config" => :build
|
|
depends_on "rust" => :build
|
|
depends_on "python@3.10" => :test
|
|
depends_on "openssl@1.1"
|
|
depends_on "zeromq"
|
|
|
|
resource "pyzmq" do
|
|
url "https://files.pythonhosted.org/packages/6c/95/d37e7db364d7f569e71068882b1848800f221c58026670e93a4c6d50efe7/pyzmq-22.3.0.tar.gz"
|
|
sha256 "8eddc033e716f8c91c6a2112f0a8ebc5e00532b4a6ae1eb0ccc48e027f9c671c"
|
|
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.10"].opt_bin/"python3",
|
|
*Language::Python.setup_install_args(testpath/"vendor")
|
|
end
|
|
|
|
resource("tnetstring3").stage do
|
|
system Formula["python@3.10"].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.10"].opt_bin/"python3"
|
|
ENV["PYTHONPATH"] = testpath/"vendor/lib/python#{xy}/site-packages"
|
|
system Formula["python@3.10"].opt_bin/"python3", runfile
|
|
ensure
|
|
Process.kill("TERM", pid)
|
|
Process.wait(pid)
|
|
end
|
|
end
|
|
end
|