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'
---
...
log = require 'log'
---
...
test_run = require('test_run').new()
---
...
net = require('net.box')
---
...
test_run:cmd('create server connecter with script = "box/proxy.lua"')
---
- true
...
--
-- gh-3164: netbox connection is not closed and garbage collected
-- ever, if reconnect_after is set.
--
test_run:cmd('start server connecter')
---
- true
...
test_run:cmd("set variable connect_to to 'connecter.listen'")
---
- true
...
weak = setmetatable({}, {__mode = 'v'})
---
...
-- Create strong and weak reference. Weak is valid until strong
-- is valid too.
strong = net.connect(connect_to, {reconnect_after = 0.1})
---
...
weak.c = strong
---
...
weak.c:ping()
---
- true
...
test_run:cmd('stop server connecter')
---
- true
...
test_run:cmd('cleanup server connecter')
---
- true
...
-- Check the connection tries to reconnect at least two times.
-- 'Cannot assign requested address' is the crutch for running the
-- tests in a docker. This error emits instead of
-- 'Connection refused' inside a docker.
old_log_level = box.cfg.log_level
---
...
box.cfg{log_level = 6}
---
...
log.info(string.rep('a', 1000))
---
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
while test_run:grep_log('default', 'Network is unreachable', 1000) == nil and
test_run:grep_log('default', 'Connection refused', 1000) == nil and
test_run:grep_log('default', 'Cannot assign requested address', 1000) == nil do
fiber.sleep(0.1)
end;
---
...
log.info(string.rep('a', 1000));
---
...
while test_run:grep_log('default', 'Network is unreachable', 1000) == nil and
test_run:grep_log('default', 'Connection refused', 1000) == nil and
test_run:grep_log('default', 'Cannot assign requested address', 1000) == nil do
fiber.sleep(0.1)
end;
---
...
test_run:cmd("setopt delimiter ''");
---
- true
...
box.cfg{log_level = old_log_level}
---
...
collectgarbage('collect')
---
- 0
...
strong.state
---
- error_reconnect
...
strong == weak.c
---
- true
...
-- Remove single strong reference. Now connection must be garbage
-- collected.
strong = nil
---
...
collectgarbage('collect')
---
- 0
...
-- Now weak.c is null, because it was weak reference, and the
-- connection is deleted by 'collect'.
weak.c
---
- null
...
|