Skip to content

Commit 3017a46

Browse files
committed
test/system: Optimize the group and user tests
The system tests can be very I/O intensive, because many of them copy OCI images from the test suite's image cache directory to its local container/storage store, create containers, and then delete everything to run the next test with a clean slate. This makes them slow. The runtime environment tests, which includes the group and user tests, are particularly slow because they don't skip the I/O even when testing error handling. This makes them a good target for optimizations. The group and user tests check the group and user configuration in different containers without changing their state. Therefore, a lot of disk I/O can be avoided by creating these containers only once for all the tests. This can reduce the time needed to run the group and user tests from almost 22 minutes to almost 5 minutes. #1635
1 parent 69d6b11 commit 3017a46

File tree

1 file changed

+19
-61
lines changed

1 file changed

+19
-61
lines changed

test/system/206-user.bats

Lines changed: 19 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# shellcheck shell=bats
22
#
3-
# Copyright © 2023 – 2024 Red Hat, Inc.
3+
# Copyright © 2023 – 2025 Red Hat, Inc.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -21,14 +21,30 @@ load 'libs/bats-support/load'
2121
load 'libs/bats-assert/load'
2222
load 'libs/helpers'
2323

24-
setup() {
24+
setup_file() {
2525
bats_require_minimum_version 1.10.0
2626
_setup_environment
2727
cleanup_all
2828
pushd "$HOME" || return 1
29+
30+
if echo "$TOOLBX_TEST_SYSTEM_TAGS" | grep "arch" >/dev/null 2>/dev/null; then
31+
create_distro_container arch latest arch-toolbox-latest
32+
fi
33+
34+
if echo "$TOOLBX_TEST_SYSTEM_TAGS" | grep "fedora" >/dev/null 2>/dev/null; then
35+
create_default_container
36+
create_distro_container fedora 34 fedora-toolbox-34
37+
create_distro_container rhel 8.10 rhel-toolbox-8.10
38+
fi
39+
40+
if echo "$TOOLBX_TEST_SYSTEM_TAGS" | grep "ubuntu" >/dev/null 2>/dev/null; then
41+
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
42+
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
43+
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
44+
fi
2945
}
3046

31-
teardown() {
47+
teardown_file() {
3248
popd || return 1
3349
cleanup_all
3450
}
@@ -38,8 +54,6 @@ teardown() {
3854
local ns_host
3955
ns_host=$(readlink /proc/$$/ns/user)
4056

41-
create_default_container
42-
4357
run --keep-empty-lines --separate-stderr "$TOOLBX" run sh -c 'readlink /proc/$$/ns/user'
4458

4559
assert_success
@@ -56,7 +70,6 @@ teardown() {
5670
local default_container
5771
default_container="$(get_system_id)-toolbox-$(get_system_version)"
5872

59-
create_default_container
6073
container_root_file_system="$(podman unshare podman mount "$default_container")"
6174

6275
"$TOOLBX" run true
@@ -74,7 +87,6 @@ teardown() {
7487

7588
# bats test_tags=arch-fedora
7689
@test "user: root in shadow(5) inside Arch Linux" {
77-
create_distro_container arch latest arch-toolbox-latest
7890
container_root_file_system="$(podman unshare podman mount arch-toolbox-latest)"
7991

8092
"$TOOLBX" run --distro arch true
@@ -92,7 +104,6 @@ teardown() {
92104

93105
# bats test_tags=arch-fedora
94106
@test "user: root in shadow(5) inside Fedora 34" {
95-
create_distro_container fedora 34 fedora-toolbox-34
96107
container_root_file_system="$(podman unshare podman mount fedora-toolbox-34)"
97108

98109
"$TOOLBX" run --distro fedora --release 34 true
@@ -110,7 +121,6 @@ teardown() {
110121

111122
# bats test_tags=arch-fedora
112123
@test "user: root in shadow(5) inside RHEL 8.10" {
113-
create_distro_container rhel 8.10 rhel-toolbox-8.10
114124
container_root_file_system="$(podman unshare podman mount rhel-toolbox-8.10)"
115125

116126
"$TOOLBX" run --distro rhel --release 8.10 true
@@ -128,7 +138,6 @@ teardown() {
128138

129139
# bats test_tags=ubuntu
130140
@test "user: root in shadow(5) inside Ubuntu 16.04" {
131-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
132141
container_root_file_system="$(podman unshare podman mount ubuntu-toolbox-16.04)"
133142

134143
"$TOOLBX" run --distro ubuntu --release 16.04 true
@@ -146,7 +155,6 @@ teardown() {
146155

147156
# bats test_tags=ubuntu
148157
@test "user: root in shadow(5) inside Ubuntu 18.04" {
149-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
150158
container_root_file_system="$(podman unshare podman mount ubuntu-toolbox-18.04)"
151159

152160
"$TOOLBX" run --distro ubuntu --release 18.04 true
@@ -164,7 +172,6 @@ teardown() {
164172

165173
# bats test_tags=ubuntu
166174
@test "user: root in shadow(5) inside Ubuntu 20.04" {
167-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
168175
container_root_file_system="$(podman unshare podman mount ubuntu-toolbox-20.04)"
169176

170177
"$TOOLBX" run --distro ubuntu --release 20.04 true
@@ -188,8 +195,6 @@ teardown() {
188195
local user_id_real
189196
user_id_real="$(id --real --user)"
190197

191-
create_default_container
192-
193198
run --keep-empty-lines --separate-stderr "$TOOLBX" run cat /etc/passwd
194199

195200
assert_success
@@ -208,8 +213,6 @@ teardown() {
208213
local user_id_real
209214
user_id_real="$(id --real --user)"
210215

211-
create_distro_container arch latest arch-toolbox-latest
212-
213216
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro arch cat /etc/passwd
214217

215218
assert_success
@@ -228,8 +231,6 @@ teardown() {
228231
local user_id_real
229232
user_id_real="$(id --real --user)"
230233

231-
create_distro_container fedora 34 fedora-toolbox-34
232-
233234
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro fedora --release 34 cat /etc/passwd
234235

235236
assert_success
@@ -248,8 +249,6 @@ teardown() {
248249
local user_id_real
249250
user_id_real="$(id --real --user)"
250251

251-
create_distro_container rhel 8.10 rhel-toolbox-8.10
252-
253252
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro rhel --release 8.10 cat /etc/passwd
254253

255254
assert_success
@@ -268,8 +267,6 @@ teardown() {
268267
local user_id_real
269268
user_id_real="$(id --real --user)"
270269

271-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
272-
273270
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 16.04 cat /etc/passwd
274271

275272
assert_success
@@ -288,8 +285,6 @@ teardown() {
288285
local user_id_real
289286
user_id_real="$(id --real --user)"
290287

291-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
292-
293288
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 18.04 cat /etc/passwd
294289

295290
assert_success
@@ -308,8 +303,6 @@ teardown() {
308303
local user_id_real
309304
user_id_real="$(id --real --user)"
310305

311-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
312-
313306
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 20.04 cat /etc/passwd
314307

315308
assert_success
@@ -325,7 +318,6 @@ teardown() {
325318
local default_container
326319
default_container="$(get_system_id)-toolbox-$(get_system_version)"
327320

328-
create_default_container
329321
container_root_file_system="$(podman unshare podman mount "$default_container")"
330322

331323
"$TOOLBX" run true
@@ -343,7 +335,6 @@ teardown() {
343335

344336
# bats test_tags=arch-fedora
345337
@test "user: $USER in shadow(5) inside Arch Linux" {
346-
create_distro_container arch latest arch-toolbox-latest
347338
container_root_file_system="$(podman unshare podman mount arch-toolbox-latest)"
348339

349340
"$TOOLBX" run --distro arch true
@@ -361,7 +352,6 @@ teardown() {
361352

362353
# bats test_tags=arch-fedora
363354
@test "user: $USER in shadow(5) inside Fedora 34" {
364-
create_distro_container fedora 34 fedora-toolbox-34
365355
container_root_file_system="$(podman unshare podman mount fedora-toolbox-34)"
366356

367357
"$TOOLBX" run --distro fedora --release 34 true
@@ -379,7 +369,6 @@ teardown() {
379369

380370
# bats test_tags=arch-fedora
381371
@test "user: $USER in shadow(5) inside RHEL 8.10" {
382-
create_distro_container rhel 8.10 rhel-toolbox-8.10
383372
container_root_file_system="$(podman unshare podman mount rhel-toolbox-8.10)"
384373

385374
"$TOOLBX" run --distro rhel --release 8.10 true
@@ -397,7 +386,6 @@ teardown() {
397386

398387
# bats test_tags=ubuntu
399388
@test "user: $USER in shadow(5) inside Ubuntu 16.04" {
400-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
401389
container_root_file_system="$(podman unshare podman mount ubuntu-toolbox-16.04)"
402390

403391
"$TOOLBX" run --distro ubuntu --release 16.04 true
@@ -415,7 +403,6 @@ teardown() {
415403

416404
# bats test_tags=ubuntu
417405
@test "user: $USER in shadow(5) inside Ubuntu 18.04" {
418-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
419406
container_root_file_system="$(podman unshare podman mount ubuntu-toolbox-18.04)"
420407

421408
"$TOOLBX" run --distro ubuntu --release 18.04 true
@@ -433,7 +420,6 @@ teardown() {
433420

434421
# bats test_tags=ubuntu
435422
@test "user: $USER in shadow(5) inside Ubuntu 20.04" {
436-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
437423
container_root_file_system="$(podman unshare podman mount ubuntu-toolbox-20.04)"
438424

439425
"$TOOLBX" run --distro ubuntu --release 20.04 true
@@ -451,8 +437,6 @@ teardown() {
451437

452438
# bats test_tags=arch-fedora
453439
@test "user: $USER in group(5) inside the default container" {
454-
create_default_container
455-
456440
run --keep-empty-lines --separate-stderr "$TOOLBX" run cat /etc/group
457441

458442
assert_success
@@ -466,8 +450,6 @@ teardown() {
466450

467451
# bats test_tags=arch-fedora
468452
@test "user: $USER in group(5) inside Arch Linux" {
469-
create_distro_container arch latest arch-toolbox-latest
470-
471453
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro arch cat /etc/group
472454

473455
assert_success
@@ -481,8 +463,6 @@ teardown() {
481463

482464
# bats test_tags=arch-fedora
483465
@test "user: $USER in group(5) inside Fedora 34" {
484-
create_distro_container fedora 34 fedora-toolbox-34
485-
486466
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro fedora --release 34 cat /etc/group
487467

488468
assert_success
@@ -496,8 +476,6 @@ teardown() {
496476

497477
# bats test_tags=arch-fedora
498478
@test "user: $USER in group(5) inside RHEL 8.10" {
499-
create_distro_container rhel 8.10 rhel-toolbox-8.10
500-
501479
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro rhel --release 8.10 cat /etc/group
502480

503481
assert_success
@@ -511,8 +489,6 @@ teardown() {
511489

512490
# bats test_tags=ubuntu
513491
@test "user: $USER in group(5) inside Ubuntu 16.04" {
514-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
515-
516492
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 16.04 cat /etc/group
517493

518494
assert_success
@@ -526,8 +502,6 @@ teardown() {
526502

527503
# bats test_tags=ubuntu
528504
@test "user: $USER in group(5) inside Ubuntu 18.04" {
529-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
530-
531505
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 18.04 cat /etc/group
532506

533507
assert_success
@@ -541,8 +515,6 @@ teardown() {
541515

542516
# bats test_tags=ubuntu
543517
@test "user: $USER in group(5) inside Ubuntu 20.04" {
544-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
545-
546518
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 20.04 cat /etc/group
547519

548520
assert_success
@@ -556,8 +528,6 @@ teardown() {
556528

557529
# bats test_tags=arch-fedora
558530
@test "user: id(1) for $USER inside the default container" {
559-
create_default_container
560-
561531
run --keep-empty-lines --separate-stderr "$TOOLBX" run id
562532

563533
assert_success
@@ -580,8 +550,6 @@ teardown() {
580550

581551
# bats test_tags=arch-fedora
582552
@test "user: id(1) for $USER inside Arch Linux" {
583-
create_distro_container arch latest arch-toolbox-latest
584-
585553
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro arch id
586554

587555
assert_success
@@ -604,8 +572,6 @@ teardown() {
604572

605573
# bats test_tags=arch-fedora
606574
@test "user: id(1) for $USER inside Fedora 34" {
607-
create_distro_container fedora 34 fedora-toolbox-34
608-
609575
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro fedora --release 34 id
610576

611577
assert_success
@@ -628,8 +594,6 @@ teardown() {
628594

629595
# bats test_tags=arch-fedora
630596
@test "user: id(1) for $USER inside RHEL 8.10" {
631-
create_distro_container rhel 8.10 rhel-toolbox-8.10
632-
633597
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro rhel --release 8.10 id
634598

635599
assert_success
@@ -652,8 +616,6 @@ teardown() {
652616

653617
# bats test_tags=ubuntu
654618
@test "user: id(1) for $USER inside Ubuntu 16.04" {
655-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
656-
657619
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 16.04 id
658620

659621
assert_success
@@ -676,8 +638,6 @@ teardown() {
676638

677639
# bats test_tags=ubuntu
678640
@test "user: id(1) for $USER inside Ubuntu 18.04" {
679-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
680-
681641
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 18.04 id
682642

683643
assert_success
@@ -700,8 +660,6 @@ teardown() {
700660

701661
# bats test_tags=ubuntu
702662
@test "user: id(1) for $USER inside Ubuntu 20.04" {
703-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
704-
705663
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 20.04 id
706664

707665
assert_success

0 commit comments

Comments
 (0)