summaryrefslogtreecommitdiff
path: root/ngx_stream_lua-0.0.16/t/062-count.t
blob: e3eb4ad2502f5e8b973690a7a343c430bd472cf8 (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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# vim:set ft= ts=4 sw=4 et fdm=marker:
use Test::Nginx::Socket::Lua::Stream;

#worker_connections(1014);
#master_on();
#workers(4);
#log_level('warn');
no_root_location();

#repeat_each(2);

plan tests => repeat_each() * (blocks() * 3);

our $HtmlDir = html_dir;

#$ENV{LUA_CPATH} = "/usr/local/openresty/lualib/?.so;" . $ENV{LUA_CPATH};

no_long_string();
run_tests();

__DATA__

=== TEST 1: entries under ngx. (content by lua)
--- stream_server_config
    content_by_lua_block {
        local n = 0
        for k, v in pairs(ngx) do
            n = n + 1
        end
        ngx.say("ngx: ", n)
    }
--- stream_response
ngx: 54
--- no_error_log
[error]



=== TEST 2: entries under ngx.req (content by lua)
--- stream_server_config
    content_by_lua_block {
        local n = 0
        for k, v in pairs(ngx.req) do
            n = n + 1
        end
        -- ngx.req.socket
        -- ngx.req.start_time
        ngx.say("n = ", n)
    }
--- stream_response
n = 2
--- no_error_log
[error]



=== TEST 3: entries under ngx.socket
--- stream_server_config
    content_by_lua_block {
        local n = 0
        for k, v in pairs(ngx.socket) do
            n = n + 1
        end
        ngx.say("n = ", n)
    }
--- stream_response
n = 4
--- no_error_log
[error]



=== TEST 4: entries under ngx._tcp_meta
--- SKIP
--- stream_server_config
    content_by_lua_block {
        local n = 0
        for k, v in pairs(ngx._tcp_meta) do
            n = n + 1
        end
        ngx.say("n = ", n)
    }
--- stream_response
n = 10
--- no_error_log
[error]



=== TEST 5: entries under the metatable of req sockets
--- stream_server_config
    content_by_lua_block {
        local n = 0
        local sock, err = ngx.req.socket()
        if not sock then
            ngx.say("failed to get the request socket: ", err)
        end

        for k, v in pairs(getmetatable(sock)) do
            print("key: ", k)
            n = n + 1
        end
        assert(ngx.say("n = ", n))
    }
--- stream_response
n = 9
--- no_error_log
[error]



=== TEST 6: shdict metatable
--- stream_config
    lua_shared_dict dogs 1m;
--- stream_server_config
    content_by_lua_block {
        local dogs = ngx.shared.dogs
        local mt = dogs.__index
        local n = 0
        for k, v in pairs(mt) do
            n = n + 1
        end
        ngx.say("n = ", n)
    }
--- stream_response
n = 22
--- no_error_log
[error]



=== TEST 7: entries under ngx.timer
--- stream_server_config
    content_by_lua_block {
        local n = 0
        for k, v in pairs(ngx.timer) do
            n = n + 1
        end
        ngx.say("n = ", n)
    }
--- stream_response
n = 4
--- no_error_log
[error]



=== TEST 8: entries under ngx.config
--- stream_server_config
    content_by_lua_block {
        local n = 0
        for k, v in pairs(ngx.config) do
            n = n + 1
        end
        ngx.say("n = ", n)
    }
--- stream_response
n = 6
--- no_error_log
[error]



=== TEST 9: entries under ngx.re
--- stream_server_config
    content_by_lua_block {
        local n = 0
        for k, v in pairs(ngx.re) do
            n = n + 1
        end
        ngx.say("n = ", n)
    }
--- stream_response
n = 5
--- no_error_log
[error]



=== TEST 10: entries under coroutine. (content by lua)
--- stream_server_config
    content_by_lua_block {
        local n = 0
        for k, v in pairs(coroutine) do
            n = n + 1
        end
        ngx.say("coroutine: ", n)
    }
--- stap2
global c
probe process("$LIBLUA_PATH").function("rehashtab") {
    c++
    printf("rehash: %d\n", c)
}
--- stap_out2
3
--- stream_response
coroutine: 16
--- no_error_log
[error]



=== TEST 11: entries under ngx.thread. (content by lua)
--- stream_server_config
    content_by_lua_block {
        local n = 0
        for k, v in pairs(ngx.thread) do
            n = n + 1
        end
        ngx.say("thread: ", n)
    }
--- stap2
global c
probe process("$LIBLUA_PATH").function("rehashtab") {
    c++
    printf("rehash: %d\n", c)
}
--- stap_out2
--- stream_response
thread: 3
--- no_error_log
[error]



=== TEST 12: entries under ngx.worker
--- stream_server_config
    content_by_lua_block {
        local n = 0
        for k, v in pairs(ngx.worker) do
            n = n + 1
        end
        ngx.say("worker: ", n)
    }
--- stream_response
worker: 5
--- no_error_log
[error]



=== TEST 13: entries under the metatable of tcp sockets
--- stream_server_config
    content_by_lua_block {
        local n = 0
        local sock = ngx.socket.tcp()
        for k, v in pairs(getmetatable(sock)) do
            n = n + 1
        end
        ngx.say("n = ", n)
    }
--- stream_response
n = 14
--- no_error_log
[error]



=== TEST 14: entries under the metatable of udp sockets
--- stream_server_config
    content_by_lua_block {
        local n = 0
        local sock = ngx.socket.udp()
        for k, v in pairs(getmetatable(sock)) do
            n = n + 1
        end
        ngx.say("n = ", n)
    }
--- stream_response
n = 6
--- no_error_log
[error]



=== TEST 15: entries under the metatable of req raw sockets
--- stream_server_config
    content_by_lua_block {
        local n = 0
        local sock, err = ngx.req.socket(true)
        if not sock then
            ngx.log(ngx.ERR, "server: failed to get raw req socket: ", err)
            return
        end

        for k, v in pairs(getmetatable(sock)) do
            n = n + 1
        end

        local ok, err = sock:send("n = " .. n .. "\n")
        if not ok then
            ngx.log(ngx.ERR, "failed to send: ", err)
            return
        end
    }
--- stream_response
n = 9
--- no_error_log
[error]