File: net.box_disconnect_gh-3859.test.lua

package info (click to toggle)
tarantool 2.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 85,412 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,178; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (50 lines) | stat: -rw-r--r-- 1,457 bytes parent folder | download | duplicates (3)
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
fiber = require 'fiber'
test_run = require('test_run').new()
net = require('net.box')

test_run:cmd('create server connecter with script = "box/proxy.lua"')

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)

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')
fiber.sleep(0)

box.session.on_disconnect(on_disconnect) == on_disconnect

--
-- gh-3859: on_disconnect is called only after all requests are
-- processed, but should be called right after disconnect and
-- only once.
--
ch1 = fiber.channel(1)
ch2 = fiber.channel(1)
function wait_signal() ch1:put(true) ch2:get() end
_ = fiber.create(function() c:call('wait_signal') end)
ch1:get()

c:close()
fiber.sleep(0)
while disconnected == false do fiber.sleep(0.01) end
disconnected -- true
disconnected = nil

ch2:put(true)
fiber.sleep(0)
disconnected -- nil, on_disconnect is not called second time.

box.session.on_disconnect(nil, on_disconnect)

box.schema.func.drop('long_call')
box.schema.func.drop('fast_call')
box.schema.func.drop('wait_signal')