File: on_shutdown.result

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 (169 lines) | stat: -rw-r--r-- 3,042 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
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
env = require('test_run')
---
...
log = require('log')
---
...
test_run = env.new()
---
...
--
-- gh-1607: on_shutdown triggers.
--
f = function() log.warn('on_shutdown 1') end
---
...
g = function() log.warn('on_shutdown 2') end
---
...
h = function() log.warn('on_shutdown 3') end
---
...
-- Check that on_shutdown triggers may yield
-- and perform some complicated actions.
fiber = require('fiber')
---
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
trig = function()
    fiber.sleep(0.01)
    fiber.yield()
    box.schema.space.create("shutdown")
    box.space.shutdown:create_index("pk")
    box.space.shutdown:insert{1,2,3}
    log.warn('on_shutdown 4')
end;
---
...
test_run:cmd("setopt delimiter ''");
---
- true
...
_ = box.ctl.on_shutdown(f)
---
...
_ = box.ctl.on_shutdown(g)
---
...
-- Check that replacing triggers works
_ = box.ctl.on_shutdown(h, g)
---
...
_ = box.ctl.on_shutdown(trig)
---
...
test_run:cmd('restart server default with wait=False')
test_run:wait_log('default', 'on_shutdown 1', nil, 30, {noreset=true})
---
- on_shutdown 1
...
test_run:grep_log('default', 'on_shutdown 2', nil, {noreset=true})
---
- null
...
test_run:grep_log('default', 'on_shutdown 3', nil, {noreset=true})
---
- on_shutdown 3
...
test_run:grep_log('default', 'on_shutdown 4', nil, {noreset=true})
---
- on_shutdown 4
...
box.space.shutdown:select{}
---
- - [1, 2, 3]
...
box.space.shutdown:drop()
---
...
-- Check that os.exit invokes on_shutdown triggers
fiber = require("fiber")
---
...
test_run:cmd("create server test with script='box/proxy.lua'")
---
- true
...
test_run:cmd("start server test")
---
- true
...
logfile = test_run:eval("test", "box.cfg.log")[1]
---
...
test_run:cmd("stop server test")
---
- true
...
-- clean up any leftover logs
require("fio").unlink(logfile)
---
- true
...
test_run:cmd("start server test")
---
- true
...
test_run:cmd("switch test")
---
- true
...
log = require('log')
---
...
_ = box.ctl.on_shutdown(function() log.warn("on_shutdown 5") end)
---
...
-- Check that we don't hang infinitely after os.exit()
-- even if the following code doesn't yield.
fiber = require("fiber")
---
...
test_run:cmd("switch default")
---
- true
...
-- eval the command on the 'test' instance while we're on default
-- instance to make sure test_run doesn't lose connection to the
-- shutting down instance.
test_run:eval("test", "_ = fiber.new(function() os.exit() while true do end end)")
---
- []
...
fiber.sleep(0.1)
---
...
-- The server should be already stopped by os.exit(),
-- but start doesn't work without a prior call to stop.
test_run:cmd("stop server test")
---
- true
...
test_run:cmd("start server test")
---
- true
...
test_run:wait_log('test', 'on_shutdown 5', nil, 30, {noreset=true})
---
- on_shutdown 5
...
-- make sure we exited because of os.exit(), not a signal.
test_run:grep_log('test', 'signal', nil, {noreset=true})
---
- null
...
test_run:cmd("stop server test")
---
- true
...
test_run:cmd("cleanup server test")
---
- true
...
test_run:cmd("delete server test")
---
- true
...