File: test_sleep.test

package info (click to toggle)
duckdb 1.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 558
file content (268 lines) | stat: -rw-r--r-- 5,394 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
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
# name: test/sql/function/generic/test_sleep.test
# description: Test sleep_ms function
# group: [generic]

# Test basic sleep function - should return NULL
query T
SELECT sleep_ms(10)
----
NULL

# Test sleep with 0 milliseconds
query T
SELECT sleep_ms(0)
----
NULL

# Test sleep with NULL input
query T
SELECT sleep_ms(NULL)
----
NULL

# Test sleep in a query with timing
query ITI
SELECT 1, sleep_ms(50), 2
----
1	NULL	2

# Test sleep with different values
query T
SELECT sleep_ms(100)
----
NULL

# Test sleep in WHERE clause (should still execute)
query I
SELECT 42 WHERE sleep_ms(10) IS NULL
----
42

# Test sleep with multiple rows
query T
SELECT sleep_ms(10) FROM range(3)
----
NULL
NULL
NULL

# Test sleep with expression
query T
SELECT sleep_ms(10 + 20)
----
NULL

# Test sleep with negative value (should still work, but sleep for 0 or handle gracefully)
query T
SELECT sleep_ms(-10)
----
NULL

# Test sleep_ms over a table
statement ok
CREATE TABLE test_sleep_table AS SELECT * FROM range(5) tbl(id);

query IT
SELECT id, sleep_ms(10) FROM test_sleep_table ORDER BY id
----
0	NULL
1	NULL
2	NULL
3	NULL
4	NULL

# Test sleep_ms with aggregation over a table
query IT
SELECT id, sleep_ms(20) FROM test_sleep_table WHERE id < 3 ORDER BY id
----
0	NULL
1	NULL
2	NULL

# Test sleep_ms timing with JSON profiling - extract and validate actual timing
# For 50ms sleep, we expect to see at least 0.05s (50ms) in the operator_timing
require json

statement ok
PRAGMA enable_profiling = 'json'

statement ok
PRAGMA profiling_output = '__TEST_DIR__/sleep_profiling.json'

statement ok
SELECT sleep_ms(50) FROM range(1)

statement ok
PRAGMA disable_profiling

# Extract timing from JSON profiling output and validate it's >= 0.05s
statement ok
CREATE OR REPLACE TABLE sleep_profiling AS SELECT * FROM read_json('__TEST_DIR__/sleep_profiling.json')

query T
SELECT cpu_time >= 0.05 FROM sleep_profiling WHERE contains(extra_info, 'sleep_ms') OR contains(query_name, 'sleep_ms') LIMIT 1
----
true

statement ok
DROP TABLE sleep_profiling

# Test sleep_ms timing over multiple rows - should take cumulative time
# For 5 rows of 10ms each (50ms total), we expect to see at least 0.05s in the timing
statement ok
PRAGMA enable_profiling = 'json'

statement ok
PRAGMA profiling_output = '__TEST_DIR__/sleep_profiling_multi.json'

statement ok
SELECT sleep_ms(10) FROM range(5)

statement ok
PRAGMA disable_profiling

# Extract timing from JSON profiling output and validate it's >= 0.05s
statement ok
CREATE OR REPLACE TABLE sleep_profiling_multi AS SELECT * FROM read_json('__TEST_DIR__/sleep_profiling_multi.json')

query T
SELECT cpu_time >= 0.05 FROM sleep_profiling_multi WHERE contains(extra_info, 'sleep_ms') OR contains(query_name, 'sleep_ms') LIMIT 1
----
true

statement ok
DROP TABLE sleep_profiling_multi

statement ok
DROP TABLE test_sleep_table

# Test nested sleep_ms calls - the inner sleep should execute
# Test basic nested sleep_ms - should return NULL
query T
SELECT sleep_ms(sleep_ms(10))
----
NULL

# Test nested sleep_ms with timing validation - inner sleep should execute
# For nested sleep_ms(50) inside sleep_ms, we expect to see at least 0.05s (50ms) in the timing
require json

statement ok
PRAGMA enable_profiling = 'json'

statement ok
PRAGMA profiling_output = '__TEST_DIR__/sleep_nested_profiling.json'

statement ok
SELECT sleep_ms(sleep_ms(50)) FROM range(1)

statement ok
PRAGMA disable_profiling

# Extract timing from JSON profiling output and validate it's >= 0.05s
statement ok
CREATE OR REPLACE TABLE sleep_nested_profiling AS SELECT * FROM read_json('__TEST_DIR__/sleep_nested_profiling.json')

query T
SELECT cpu_time >= 0.05 FROM sleep_nested_profiling WHERE contains(extra_info, 'sleep_ms') OR contains(query_name, 'sleep_ms') LIMIT 1
----
true

statement ok
DROP TABLE sleep_nested_profiling

# Test nested sleep_ms with NULL input - outer sleep should receive NULL and return NULL
query T
SELECT sleep_ms(sleep_ms(NULL))
----
NULL

# Test nested sleep_ms with 0 milliseconds
query T
SELECT sleep_ms(sleep_ms(0))
----
NULL

# Test nested sleep_ms in WHERE clause (should still execute)
query I
SELECT 42 WHERE sleep_ms(sleep_ms(10)) IS NULL
----
42

# Test nested sleep_ms with expression
query T
SELECT sleep_ms(sleep_ms(10 + 20))
----
NULL

# Test nested sleep_ms with multiple rows
query T
SELECT sleep_ms(sleep_ms(10)) FROM range(3)
----
NULL
NULL
NULL

# Test pg_sleep function (Postgres compatibility - takes seconds, converts to milliseconds)
# Test basic pg_sleep function - should return NULL
query T
SELECT pg_sleep(0.1)
----
NULL

# Test pg_sleep with 0 seconds
query T
SELECT pg_sleep(0)
----
NULL

# Test pg_sleep with NULL input
query T
SELECT pg_sleep(NULL)
----
NULL

# Test pg_sleep with fractional seconds
query T
SELECT pg_sleep(0.05)
----
NULL

# Test pg_sleep with 1 second
query T
SELECT pg_sleep(1.0)
----
NULL

# Test pg_sleep in a query with other columns
query ITI
SELECT 1, pg_sleep(0.1), 2
----
1	NULL	2

# Test pg_sleep in WHERE clause (should still execute)
query I
SELECT 42 WHERE pg_sleep(0.1) IS NULL
----
42

# Test pg_sleep with multiple rows
query T
SELECT pg_sleep(0.01) FROM range(3)
----
NULL
NULL
NULL

# Test pg_sleep with expression
query T
SELECT pg_sleep(0.05 + 0.05)
----
NULL

# Test pg_sleep with negative value (should still work, but sleep for 0 or handle gracefully)
query T
SELECT pg_sleep(-0.1)
----
NULL