Skip to content

Commit 1b9dd00

Browse files
committed
test/system: Optimize the networking 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 networking 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 networking tests check the behaviour and configuration of the network 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 networking tests from almost 15 minutes to almost 6 minutes. #1637
1 parent 259de86 commit 1b9dd00

File tree

1 file changed

+19
-47
lines changed

1 file changed

+19
-47
lines changed

test/system/203-network.bats

Lines changed: 19 additions & 47 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.
@@ -33,14 +33,30 @@ print(addr)'
3333
readonly RESOLVER_SH='resolvectl --legend false --no-pager --type "$0" query "$1" \
3434
| cut --delimiter " " --fields 4'
3535

36-
setup() {
36+
setup_file() {
3737
bats_require_minimum_version 1.10.0
3838
_setup_environment
3939
cleanup_all
4040
pushd "$HOME" || return 1
41+
42+
if echo "$TOOLBX_TEST_SYSTEM_TAGS" | grep "arch" >/dev/null 2>/dev/null; then
43+
create_distro_container arch latest arch-toolbox-latest
44+
fi
45+
46+
if echo "$TOOLBX_TEST_SYSTEM_TAGS" | grep "fedora" >/dev/null 2>/dev/null; then
47+
create_default_container
48+
create_distro_container fedora 34 fedora-toolbox-34
49+
create_distro_container rhel 8.10 rhel-toolbox-8.10
50+
fi
51+
52+
if echo "$TOOLBX_TEST_SYSTEM_TAGS" | grep "ubuntu" >/dev/null 2>/dev/null; then
53+
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
54+
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
55+
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
56+
fi
4157
}
4258

43-
teardown() {
59+
teardown_file() {
4460
popd || return 1
4561
cleanup_all
4662
}
@@ -50,8 +66,6 @@ teardown() {
5066
local ns_host
5167
ns_host=$(readlink /proc/$$/ns/net)
5268

53-
create_default_container
54-
5569
run --keep-empty-lines --separate-stderr "$TOOLBX" run sh -c 'readlink /proc/$$/ns/net'
5670

5771
assert_success
@@ -64,8 +78,6 @@ teardown() {
6478

6579
# bats test_tags=arch-fedora
6680
@test "network: /etc/resolv.conf inside the default container" {
67-
create_default_container
68-
6981
run --keep-empty-lines --separate-stderr "$TOOLBX" run readlink /etc/resolv.conf
7082

7183
assert_success
@@ -84,8 +96,6 @@ teardown() {
8496

8597
# bats test_tags=arch-fedora
8698
@test "network: /etc/resolv.conf inside Arch Linux" {
87-
create_distro_container arch latest arch-toolbox-latest
88-
8999
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro arch readlink /etc/resolv.conf
90100

91101
assert_success
@@ -104,8 +114,6 @@ teardown() {
104114

105115
# bats test_tags=arch-fedora
106116
@test "network: /etc/resolv.conf inside Fedora 34" {
107-
create_distro_container fedora 34 fedora-toolbox-34
108-
109117
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro fedora --release 34 readlink /etc/resolv.conf
110118

111119
assert_success
@@ -124,8 +132,6 @@ teardown() {
124132

125133
# bats test_tags=arch-fedora
126134
@test "network: /etc/resolv.conf inside RHEL 8.10" {
127-
create_distro_container rhel 8.10 rhel-toolbox-8.10
128-
129135
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro rhel --release 8.10 readlink /etc/resolv.conf
130136

131137
assert_success
@@ -144,8 +150,6 @@ teardown() {
144150

145151
# bats test_tags=ubuntu
146152
@test "network: /etc/resolv.conf inside Ubuntu 16.04" {
147-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
148-
149153
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 16.04 readlink /etc/resolv.conf
150154

151155
assert_success
@@ -164,8 +168,6 @@ teardown() {
164168

165169
# bats test_tags=ubuntu
166170
@test "network: /etc/resolv.conf inside Ubuntu 18.04" {
167-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
168-
169171
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 18.04 readlink /etc/resolv.conf
170172

171173
assert_success
@@ -184,8 +186,6 @@ teardown() {
184186

185187
# bats test_tags=ubuntu
186188
@test "network: /etc/resolv.conf inside Ubuntu 20.04" {
187-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
188-
189189
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 20.04 readlink /etc/resolv.conf
190190

191191
assert_success
@@ -220,8 +220,6 @@ teardown() {
220220
skip "DNS not working on host"
221221
fi
222222

223-
create_default_container
224-
225223
if ! $ipv4_skip; then
226224
run --keep-empty-lines --separate-stderr "$TOOLBX" run python3 -c "$RESOLVER_PYTHON3" A k.root-servers.net
227225

@@ -259,8 +257,6 @@ teardown() {
259257
skip "DNS not working on host"
260258
fi
261259

262-
create_distro_container arch latest arch-toolbox-latest
263-
264260
if ! $ipv4_skip; then
265261
run --keep-empty-lines --separate-stderr "$TOOLBX" run \
266262
--distro arch \
@@ -302,8 +298,6 @@ teardown() {
302298
skip "DNS not working on host"
303299
fi
304300

305-
create_distro_container fedora 34 fedora-toolbox-34
306-
307301
if ! $ipv4_skip; then
308302
run --keep-empty-lines --separate-stderr "$TOOLBX" run \
309303
--distro fedora \
@@ -347,8 +341,6 @@ teardown() {
347341
skip "DNS not working on host"
348342
fi
349343

350-
create_distro_container rhel 8.10 rhel-toolbox-8.10
351-
352344
if ! $ipv4_skip; then
353345
run --keep-empty-lines --separate-stderr "$TOOLBX" run \
354346
--distro rhel \
@@ -392,8 +384,6 @@ teardown() {
392384
skip "DNS not working on host"
393385
fi
394386

395-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
396-
397387
if ! $ipv4_skip; then
398388
run --keep-empty-lines --separate-stderr "$TOOLBX" run \
399389
--distro ubuntu \
@@ -437,8 +427,6 @@ teardown() {
437427
skip "DNS not working on host"
438428
fi
439429

440-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
441-
442430
if ! $ipv4_skip; then
443431
run --keep-empty-lines --separate-stderr "$TOOLBX" run \
444432
--distro ubuntu \
@@ -482,8 +470,6 @@ teardown() {
482470
skip "DNS not working on host"
483471
fi
484472

485-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
486-
487473
if ! $ipv4_skip; then
488474
run --keep-empty-lines --separate-stderr "$TOOLBX" run \
489475
--distro ubuntu \
@@ -511,8 +497,6 @@ teardown() {
511497

512498
# bats test_tags=arch-fedora
513499
@test "network: ping(8) inside the default container" {
514-
create_default_container
515-
516500
run --keep-empty-lines --separate-stderr "$TOOLBX" run ping -c 2 f.root-servers.net
517501

518502
if [ "$status" -eq 1 ]; then
@@ -528,8 +512,6 @@ teardown() {
528512

529513
# bats test_tags=arch-fedora
530514
@test "network: ping(8) inside Arch Linux" {
531-
create_distro_container arch latest arch-toolbox-latest
532-
533515
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro arch ping -c 2 f.root-servers.net
534516

535517
if [ "$status" -eq 1 ]; then
@@ -545,8 +527,6 @@ teardown() {
545527

546528
# bats test_tags=arch-fedora
547529
@test "network: ping(8) inside Fedora 34" {
548-
create_distro_container fedora 34 fedora-toolbox-34
549-
550530
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro fedora --release 34 ping -c 2 f.root-servers.net
551531

552532
if [ "$status" -eq 1 ]; then
@@ -562,8 +542,6 @@ teardown() {
562542

563543
# bats test_tags=arch-fedora
564544
@test "network: ping(8) inside RHEL 8.10" {
565-
create_distro_container rhel 8.10 rhel-toolbox-8.10
566-
567545
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro rhel --release 8.10 ping -c 2 f.root-servers.net
568546

569547
if [ "$status" -eq 1 ]; then
@@ -579,8 +557,6 @@ teardown() {
579557

580558
# bats test_tags=ubuntu
581559
@test "network: ping(8) inside Ubuntu 16.04" {
582-
create_distro_container ubuntu 16.04 ubuntu-toolbox-16.04
583-
584560
run -2 --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 16.04 ping -c 2 f.root-servers.net
585561

586562
assert_failure
@@ -594,8 +570,6 @@ teardown() {
594570

595571
# bats test_tags=ubuntu
596572
@test "network: ping(8) inside Ubuntu 18.04" {
597-
create_distro_container ubuntu 18.04 ubuntu-toolbox-18.04
598-
599573
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 18.04 ping -c 2 f.root-servers.net
600574

601575
if [ "$status" -eq 1 ]; then
@@ -611,8 +585,6 @@ teardown() {
611585

612586
# bats test_tags=ubuntu
613587
@test "network: ping(8) inside Ubuntu 20.04" {
614-
create_distro_container ubuntu 20.04 ubuntu-toolbox-20.04
615-
616588
run --keep-empty-lines --separate-stderr "$TOOLBX" run --distro ubuntu --release 20.04 ping -c 2 f.root-servers.net
617589

618590
if [ "$status" -eq 1 ]; then

0 commit comments

Comments
 (0)