aboutsummaryrefslogtreecommitdiff
path: root/tests/units/net-query.lua
blob: 2e072620c0ce53278e4d1c9017d5fea46fe37d28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
local bserver = llby.thread.buffer(nil)

local a = 255
local b = 992

local net = llby.thread.async(function(tres)
  local c = 943
  llby.net.listen(function(server)
    bserver:set(server)

    server:GET("/", function(res, req)
      res:send(tostring(tonumber(req.query.t1) * a + tonumber(req.query.t2) * b + tonumber(req.query.t3) * c))
    end)
  end, PORT)
end)

local t1 = 293
local t2 = 928
local t3 = 777

--should wait for the server to start
os.execute("sleep 0.1")

local s = llby.net.request(string.format("localhost:%i/?t1=%i&t2=%i&t3=%i", PORT, t1, t2, t3))
local num = s.content:read()

bserver:get():close()

net:await()
return tonumber(num) == (t1 * a + t2 * b + t3 * 943)