Skip to content

Commit 836c055

Browse files
committed
test/system: Optimize the environment variable 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 environment variable 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 environment variable tests query the values of different environment variables from 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 environment variable tests from almost 26 minutes to almost 9 minutes. #1646
1 parent a5a0d53 commit 836c055

File tree

1 file changed

+19
-73
lines changed

1 file changed

+19
-73
lines changed

test/system/220-environment-variables.bats

Lines changed: 19 additions & 73 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,22 +21,36 @@ 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
}
3551

3652
# bats test_tags=arch-fedora
3753
@test "environment variables: HISTFILESIZE inside the default container" {
38-
create_default_container
39-
4054
if [ "$HISTFILESIZE" = "" ]; then
4155
# shellcheck disable=SC2030
4256
HISTFILESIZE=1001
@@ -59,8 +73,6 @@ teardown() {
5973

6074
# bats test_tags=arch-fedora
6175
@test "environment variables: HISTFILESIZE inside Arch Linux" {
62-
create_distro_container arch latest arch-toolbox-latest
63-
6476
# shellcheck disable=SC2031
6577
if [ "$HISTFILESIZE" = "" ]; then
6678
# shellcheck disable=SC2030
@@ -84,8 +96,6 @@ teardown() {
8496

8597
# bats test_tags=arch-fedora
8698
@test "environment variables: HISTFILESIZE inside Fedora 34" {
87-
create_distro_container fedora 34 fedora-toolbox-34
88-
8999
# shellcheck disable=SC2031
90100
if [ "$HISTFILESIZE" = "" ]; then
91101
# shellcheck disable=SC2030
@@ -109,8 +119,6 @@ teardown() {
109119

110120
# bats test_tags=arch-fedora
111121
@test "environment variables: HISTFILESIZE inside RHEL 8.10" {
112-
create_distro_container rhel 8.10 rhel-toolbox-8.10
113-
114122
# shellcheck disable=SC2031
115123
if [ "$HISTFILESIZE" = "" ]; then
116124
# shellcheck disable=SC2030
@@ -134,8 +142,6 @@ teardown() {
134142

135143
# bats test_tags=ubuntu
136144
@test "environment variables: HISTFILESIZE inside Ubuntu 16.04" {
137-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
138-
139145
# shellcheck disable=SC2031
140146
if [ "$HISTFILESIZE" = "" ]; then
141147
# shellcheck disable=SC2030
@@ -160,8 +166,6 @@ teardown() {
160166

161167
# bats test_tags=ubuntu
162168
@test "environment variables: HISTFILESIZE inside Ubuntu 18.04" {
163-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
164-
165169
# shellcheck disable=SC2031
166170
if [ "$HISTFILESIZE" = "" ]; then
167171
# shellcheck disable=SC2030
@@ -186,8 +190,6 @@ teardown() {
186190

187191
# bats test_tags=ubuntu
188192
@test "environment variables: HISTFILESIZE inside Ubuntu 20.04" {
189-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
190-
191193
# shellcheck disable=SC2031
192194
if [ "$HISTFILESIZE" = "" ]; then
193195
HISTFILESIZE=1001
@@ -213,8 +215,6 @@ teardown() {
213215
@test "environment variables: HISTSIZE inside the default container" {
214216
skip "https://pagure.io/setup/pull-request/48"
215217

216-
create_default_container
217-
218218
if [ "$HISTSIZE" = "" ]; then
219219
# shellcheck disable=SC2030
220220
HISTSIZE=1001
@@ -237,8 +237,6 @@ teardown() {
237237

238238
# bats test_tags=arch-fedora
239239
@test "environment variables: HISTSIZE inside Arch Linux" {
240-
create_distro_container arch latest arch-toolbox-latest
241-
242240
# shellcheck disable=SC2031
243241
if [ "$HISTSIZE" = "" ]; then
244242
# shellcheck disable=SC2030
@@ -264,8 +262,6 @@ teardown() {
264262
@test "environment variables: HISTSIZE inside Fedora 34" {
265263
skip "https://pagure.io/setup/pull-request/48"
266264

267-
create_distro_container fedora 34 fedora-toolbox-34
268-
269265
# shellcheck disable=SC2031
270266
if [ "$HISTSIZE" = "" ]; then
271267
# shellcheck disable=SC2030
@@ -291,8 +287,6 @@ teardown() {
291287
@test "environment variables: HISTSIZE inside RHEL 8.10" {
292288
skip "https://pagure.io/setup/pull-request/48"
293289

294-
create_distro_container rhel 8.10 rhel-toolbox-8.10
295-
296290
# shellcheck disable=SC2031
297291
if [ "$HISTSIZE" = "" ]; then
298292
# shellcheck disable=SC2030
@@ -316,8 +310,6 @@ teardown() {
316310

317311
# bats test_tags=ubuntu
318312
@test "environment variables: HISTSIZE inside Ubuntu 16.04" {
319-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
320-
321313
# shellcheck disable=SC2031
322314
if [ "$HISTSIZE" = "" ]; then
323315
# shellcheck disable=SC2030
@@ -341,8 +333,6 @@ teardown() {
341333

342334
# bats test_tags=ubuntu
343335
@test "environment variables: HISTSIZE inside Ubuntu 18.04" {
344-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
345-
346336
# shellcheck disable=SC2031
347337
if [ "$HISTSIZE" = "" ]; then
348338
# shellcheck disable=SC2030
@@ -366,8 +356,6 @@ teardown() {
366356

367357
# bats test_tags=ubuntu
368358
@test "environment variables: HISTSIZE inside Ubuntu 20.04" {
369-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
370-
371359
# shellcheck disable=SC2031
372360
if [ "$HISTSIZE" = "" ]; then
373361
HISTSIZE=1001
@@ -390,8 +378,6 @@ teardown() {
390378

391379
# bats test_tags=arch-fedora
392380
@test "environment variables: HOSTNAME inside the default container" {
393-
create_default_container
394-
395381
# shellcheck disable=SC2016
396382
run --keep-empty-lines --separate-stderr "$TOOLBX" run bash -c 'echo "$HOSTNAME"'
397383

@@ -403,8 +389,6 @@ teardown() {
403389

404390
# bats test_tags=arch-fedora
405391
@test "environment variables: HOSTNAME inside Arch Linux" {
406-
create_distro_container arch latest arch-toolbox-latest
407-
408392
# shellcheck disable=SC2016
409393
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro arch bash -c 'echo "$HOSTNAME"'
410394

@@ -416,8 +400,6 @@ teardown() {
416400

417401
# bats test_tags=arch-fedora
418402
@test "environment variables: HOSTNAME inside Fedora 34" {
419-
create_distro_container fedora 34 fedora-toolbox-34
420-
421403
# shellcheck disable=SC2016
422404
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro fedora --release 34 bash -c 'echo "$HOSTNAME"'
423405

@@ -429,8 +411,6 @@ teardown() {
429411

430412
# bats test_tags=arch-fedora
431413
@test "environment variables: HOSTNAME inside RHEL 8.10" {
432-
create_distro_container rhel 8.10 rhel-toolbox-8.10
433-
434414
# shellcheck disable=SC2016
435415
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro rhel --release 8.10 bash -c 'echo "$HOSTNAME"'
436416

@@ -442,8 +422,6 @@ teardown() {
442422

443423
# bats test_tags=ubuntu
444424
@test "environment variables: HOSTNAME inside Ubuntu 16.04" {
445-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
446-
447425
# shellcheck disable=SC2016
448426
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 16.04 bash -c 'echo "$HOSTNAME"'
449427

@@ -455,8 +433,6 @@ teardown() {
455433

456434
# bats test_tags=ubuntu
457435
@test "environment variables: HOSTNAME inside Ubuntu 18.04" {
458-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
459-
460436
# shellcheck disable=SC2016
461437
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 18.04 bash -c 'echo "$HOSTNAME"'
462438

@@ -468,8 +444,6 @@ teardown() {
468444

469445
# bats test_tags=ubuntu
470446
@test "environment variables: HOSTNAME inside Ubuntu 20.04" {
471-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
472-
473447
# shellcheck disable=SC2016
474448
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 20.04 bash -c 'echo "$HOSTNAME"'
475449

@@ -481,8 +455,6 @@ teardown() {
481455

482456
# bats test_tags=arch-fedora
483457
@test "environment variables: KONSOLE_VERSION inside the default container" {
484-
create_default_container
485-
486458
if [ "$KONSOLE_VERSION" = "" ]; then
487459
# shellcheck disable=SC2030
488460
export KONSOLE_VERSION=230804
@@ -501,8 +473,6 @@ teardown() {
501473

502474
# bats test_tags=arch-fedora
503475
@test "environment variables: KONSOLE_VERSION inside Arch Linux" {
504-
create_distro_container arch latest arch-toolbox-latest
505-
506476
# shellcheck disable=SC2031
507477
if [ "$KONSOLE_VERSION" = "" ]; then
508478
# shellcheck disable=SC2030
@@ -522,8 +492,6 @@ teardown() {
522492

523493
# bats test_tags=arch-fedora
524494
@test "environment variables: KONSOLE_VERSION inside Fedora 34" {
525-
create_distro_container fedora 34 fedora-toolbox-34
526-
527495
# shellcheck disable=SC2031
528496
if [ "$KONSOLE_VERSION" = "" ]; then
529497
# shellcheck disable=SC2030
@@ -543,8 +511,6 @@ teardown() {
543511

544512
# bats test_tags=arch-fedora
545513
@test "environment variables: KONSOLE_VERSION inside RHEL 8.10" {
546-
create_distro_container rhel 8.10 rhel-toolbox-8.10
547-
548514
# shellcheck disable=SC2031
549515
if [ "$KONSOLE_VERSION" = "" ]; then
550516
# shellcheck disable=SC2030
@@ -564,8 +530,6 @@ teardown() {
564530

565531
# bats test_tags=ubuntu
566532
@test "environment variables: KONSOLE_VERSION inside Ubuntu 16.04" {
567-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
568-
569533
# shellcheck disable=SC2031
570534
if [ "$KONSOLE_VERSION" = "" ]; then
571535
# shellcheck disable=SC2030
@@ -585,8 +549,6 @@ teardown() {
585549

586550
# bats test_tags=ubuntu
587551
@test "environment variables: KONSOLE_VERSION inside Ubuntu 18.04" {
588-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
589-
590552
# shellcheck disable=SC2031
591553
if [ "$KONSOLE_VERSION" = "" ]; then
592554
# shellcheck disable=SC2030
@@ -606,8 +568,6 @@ teardown() {
606568

607569
# bats test_tags=ubuntu
608570
@test "environment variables: KONSOLE_VERSION inside Ubuntu 20.04" {
609-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
610-
611571
# shellcheck disable=SC2031
612572
if [ "$KONSOLE_VERSION" = "" ]; then
613573
export KONSOLE_VERSION=230804
@@ -626,8 +586,6 @@ teardown() {
626586

627587
# bats test_tags=arch-fedora
628588
@test "environment variables: XTERM_VERSION inside the default container" {
629-
create_default_container
630-
631589
if [ "$XTERM_VERSION" = "" ]; then
632590
# shellcheck disable=SC2030
633591
export XTERM_VERSION="XTerm(385)"
@@ -646,8 +604,6 @@ teardown() {
646604

647605
# bats test_tags=arch-fedora
648606
@test "environment variables: XTERM_VERSION inside Arch Linux" {
649-
create_distro_container arch latest arch-toolbox-latest
650-
651607
# shellcheck disable=SC2031
652608
if [ "$XTERM_VERSION" = "" ]; then
653609
# shellcheck disable=SC2030
@@ -667,8 +623,6 @@ teardown() {
667623

668624
# bats test_tags=arch-fedora
669625
@test "environment variables: XTERM_VERSION inside Fedora 34" {
670-
create_distro_container fedora 34 fedora-toolbox-34
671-
672626
# shellcheck disable=SC2031
673627
if [ "$XTERM_VERSION" = "" ]; then
674628
# shellcheck disable=SC2030
@@ -688,8 +642,6 @@ teardown() {
688642

689643
# bats test_tags=arch-fedora
690644
@test "environment variables: XTERM_VERSION inside RHEL 8.10" {
691-
create_distro_container rhel 8.10 rhel-toolbox-8.10
692-
693645
# shellcheck disable=SC2031
694646
if [ "$XTERM_VERSION" = "" ]; then
695647
# shellcheck disable=SC2030
@@ -709,8 +661,6 @@ teardown() {
709661

710662
# bats test_tags=ubuntu
711663
@test "environment variables: XTERM_VERSION inside Ubuntu 16.04" {
712-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
713-
714664
# shellcheck disable=SC2031
715665
if [ "$XTERM_VERSION" = "" ]; then
716666
# shellcheck disable=SC2030
@@ -730,8 +680,6 @@ teardown() {
730680

731681
# bats test_tags=ubuntu
732682
@test "environment variables: XTERM_VERSION inside Ubuntu 18.04" {
733-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
734-
735683
# shellcheck disable=SC2031
736684
if [ "$XTERM_VERSION" = "" ]; then
737685
# shellcheck disable=SC2030
@@ -751,8 +699,6 @@ teardown() {
751699

752700
# bats test_tags=ubuntu
753701
@test "environment variables: XTERM_VERSION inside Ubuntu 20.04" {
754-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
755-
756702
# shellcheck disable=SC2031
757703
if [ "$XTERM_VERSION" = "" ]; then
758704
export XTERM_VERSION="XTerm(385)"

0 commit comments

Comments
 (0)