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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
fiber = require 'fiber'
---
...
test_run = require('test_run').new()
---
...
net = require('net.box')
---
...
test_run:cmd('create server connecter with script = "box/proxy.lua"')
---
- true
...
--
-- gh-946: long polling CALL blocks input
--
box.schema.func.create('fast_call')
---
...
box.schema.func.create('long_call')
---
...
box.schema.func.create('wait_signal')
---
...
box.schema.user.grant('guest', 'execute', 'function', 'fast_call')
---
...
box.schema.user.grant('guest', 'execute', 'function', 'long_call')
---
...
box.schema.user.grant('guest', 'execute', 'function', 'wait_signal')
---
...
c = net.connect(box.cfg.listen)
---
...
N = 100
---
...
pad = string.rep('x', 1024)
---
...
long_call_cond = fiber.cond()
---
...
long_call_channel = fiber.channel()
---
...
fast_call_channel = fiber.channel()
---
...
function fast_call(x) return x end
---
...
function long_call(x) long_call_cond:wait() return x * 2 end
---
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
for i = 1, N do
fiber.create(function()
fast_call_channel:put(c:call('fast_call', {i, pad}))
end)
fiber.create(function()
long_call_channel:put(c:call('long_call', {i, pad}))
end)
end
test_run:cmd("setopt delimiter ''");
---
...
x = 0
---
...
for i = 1, N do x = x + fast_call_channel:get() end
---
...
x
---
- 5050
...
long_call_cond:broadcast()
---
...
x = 0
---
...
for i = 1, N do x = x + long_call_channel:get() end
---
...
x
---
- 10100
...
--
-- Check that a connection does not leak if there is
-- a long CALL in progress when it is closed.
--
disconnected = false
---
...
function on_disconnect() disconnected = true end
---
...
-- Make sure all dangling connections are collected so
-- that on_disconnect trigger isn't called spuriously.
collectgarbage('collect')
---
- 0
...
fiber.sleep(0)
---
...
box.session.on_disconnect(on_disconnect) == on_disconnect
---
- true
...
|