Skip to content

Commit 8fe926d

Browse files
test: Add datafusion-cli fair and unbounded memory-pool test coverage (#20565)
## Which issue does this PR close? - Closes #20564. ## Rationale for this change Currently, `datafusion-cli` submodule does not have test coverage for `--mem-pool-type = fair / unbounded` (default: `greedy` and `unbounded` memory pool is used when both `--memory-limit` and `--mem-pool-type` are `not` set). Legacy test cases use `greedy` memory pool by setting `--memory-limit`. This PR aims to cover `--mem-pool-type = fair / unbounded` cases with `--memory-limit` and `--top-memory-consumers` usages. Also, `datafusion-cli` is a client used by end-users so extending test coverages of the exposed features can be useful for the functional verification and long-term maintenance. **Case1:** `fair` memory pool usage by `datafusion-cli` when `top-memory-consumers = 0` (Top Memory Consumers will not be listed when memory is exhausted) ``` program: datafusion-cli args: - "--memory-limit" - 10M - "--mem-pool-type" - fair - "--command" - "select * from generate_series(1,500000) as t1(v1) order by v1;" - "--top-memory-consumers" - "0" ``` **Case2:** `fair` memory pool usage by `datafusion-cli` when `top-memory-consumers > 0` (Top Memory Consumers will be listed when memory is exhausted) ``` program: datafusion-cli args: - "--memory-limit" - 10M - "--mem-pool-type" - fair - "--command" - "select * from generate_series(1,500000) as t1(v1) order by v1;" - "--top-memory-consumers" - "2" ``` **Case3:** `unbounded` memory pool usage by `datafusion-cli` ``` program: datafusion-cli args: - "--maxrows" - "10" - "--command" - "select * from generate_series(1,500000) as t1(v1) order by v1;" ``` ## What changes are included in this PR? Explained under above section. ## Are these changes tested? Yes, being added new integration tests and they are successful locally: ``` test test_cli_top_memory_consumers_with_mem_pool_type::case_1 ... ok test test_cli_top_memory_consumers_with_mem_pool_type::case_2 ... ok test test_cli_with_unbounded_memory_pool::case_1 ... ok ``` ## Are there any user-facing changes? No
1 parent bfa0ea8 commit 8fe926d

4 files changed

Lines changed: 132 additions & 2 deletions

datafusion-cli/tests/cli_integration.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use std::process::Command;
2020
use rstest::rstest;
2121

2222
use async_trait::async_trait;
23+
use insta::internals::SettingsBindDropGuard;
2324
use insta::{Settings, glob};
2425
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
2526
use std::path::PathBuf;
@@ -215,6 +216,42 @@ fn test_cli_top_memory_consumers<'a>(
215216
#[case] snapshot_name: &str,
216217
#[case] top_memory_consumers: impl IntoIterator<Item = &'a str>,
217218
) {
219+
let _bound = bind_to_settings(snapshot_name);
220+
221+
let mut cmd = cli();
222+
let sql = "select * from generate_series(1,500000) as t1(v1) order by v1;";
223+
cmd.args(["--memory-limit", "10M", "--command", sql]);
224+
cmd.args(top_memory_consumers);
225+
226+
assert_cmd_snapshot!(cmd);
227+
}
228+
229+
#[rstest]
230+
#[case("no_track", ["--top-memory-consumers", "0"])]
231+
#[case("top2", ["--top-memory-consumers", "2"])]
232+
#[test]
233+
fn test_cli_top_memory_consumers_with_mem_pool_type<'a>(
234+
#[case] snapshot_name: &str,
235+
#[case] top_memory_consumers: impl IntoIterator<Item = &'a str>,
236+
) {
237+
let _bound = bind_to_settings(snapshot_name);
238+
239+
let mut cmd = cli();
240+
let sql = "select * from generate_series(1,500000) as t1(v1) order by v1;";
241+
cmd.args([
242+
"--memory-limit",
243+
"10M",
244+
"--mem-pool-type",
245+
"fair",
246+
"--command",
247+
sql,
248+
]);
249+
cmd.args(top_memory_consumers);
250+
251+
assert_cmd_snapshot!(cmd);
252+
}
253+
254+
fn bind_to_settings(snapshot_name: &str) -> SettingsBindDropGuard {
218255
let mut settings = make_settings();
219256

220257
settings.set_snapshot_suffix(snapshot_name);
@@ -232,12 +269,20 @@ fn test_cli_top_memory_consumers<'a>(
232269
"Resources exhausted: Failed to allocate",
233270
);
234271

272+
settings.bind_to_scope()
273+
}
274+
275+
#[test]
276+
fn test_cli_with_unbounded_memory_pool() {
277+
let mut settings = make_settings();
278+
279+
settings.set_snapshot_suffix("default");
280+
235281
let _bound = settings.bind_to_scope();
236282

237283
let mut cmd = cli();
238284
let sql = "select * from generate_series(1,500000) as t1(v1) order by v1;";
239-
cmd.args(["--memory-limit", "10M", "--command", sql]);
240-
cmd.args(top_memory_consumers);
285+
cmd.args(["--maxrows", "10", "--command", sql]);
241286

242287
assert_cmd_snapshot!(cmd);
243288
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
source: datafusion-cli/tests/cli_integration.rs
3+
info:
4+
program: datafusion-cli
5+
args:
6+
- "--memory-limit"
7+
- 10M
8+
- "--mem-pool-type"
9+
- fair
10+
- "--command"
11+
- "select * from generate_series(1,500000) as t1(v1) order by v1;"
12+
- "--top-memory-consumers"
13+
- "0"
14+
---
15+
success: false
16+
exit_code: 1
17+
----- stdout -----
18+
[CLI_VERSION]
19+
Error: Not enough memory to continue external sort. Consider increasing the memory limit config: 'datafusion.runtime.memory_limit', or decreasing the config: 'datafusion.execution.sort_spill_reservation_bytes'.
20+
caused by
21+
Resources exhausted: Failed to allocate
22+
23+
----- stderr -----
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
source: datafusion-cli/tests/cli_integration.rs
3+
info:
4+
program: datafusion-cli
5+
args:
6+
- "--memory-limit"
7+
- 10M
8+
- "--mem-pool-type"
9+
- fair
10+
- "--command"
11+
- "select * from generate_series(1,500000) as t1(v1) order by v1;"
12+
- "--top-memory-consumers"
13+
- "2"
14+
---
15+
success: false
16+
exit_code: 1
17+
----- stdout -----
18+
[CLI_VERSION]
19+
Error: Not enough memory to continue external sort. Consider increasing the memory limit config: 'datafusion.runtime.memory_limit', or decreasing the config: 'datafusion.execution.sort_spill_reservation_bytes'.
20+
caused by
21+
Resources exhausted: Additional allocation failed for ExternalSorter[0] with top memory consumers (across reservations) as:
22+
Consumer(can spill: bool) consumed XB, peak XB,
23+
Consumer(can spill: bool) consumed XB, peak XB.
24+
Error: Failed to allocate
25+
26+
----- stderr -----
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
source: datafusion-cli/tests/cli_integration.rs
3+
info:
4+
program: datafusion-cli
5+
args:
6+
- "--maxrows"
7+
- "10"
8+
- "--command"
9+
- "select * from generate_series(1,500000) as t1(v1) order by v1;"
10+
---
11+
success: true
12+
exit_code: 0
13+
----- stdout -----
14+
[CLI_VERSION]
15+
+----+
16+
| v1 |
17+
+----+
18+
| 1 |
19+
| 2 |
20+
| 3 |
21+
| 4 |
22+
| 5 |
23+
| 6 |
24+
| 7 |
25+
| 8 |
26+
| 9 |
27+
| 10 |
28+
| . |
29+
| . |
30+
| . |
31+
+----+
32+
500000 row(s) fetched. (First 10 displayed. Use --maxrows to adjust)
33+
[ELAPSED]
34+
35+
36+
----- stderr -----

0 commit comments

Comments
 (0)