Postgresql 中文操作指南

33.4. TAP Tests #

各种测试,尤其是 src/bin 下的客户端程序测试,使用 Perl TAP 工具,并使用 Perl 测试程序 prove 运行。您可以通过设置 make 变量 PROVE_FLAGSprove 传递命令行选项,例如:

Various tests, particularly the client program tests under src/bin, use the Perl TAP tools and are run using the Perl testing program prove. You can pass command-line options to prove by setting the make variable PROVE_FLAGS, for example:

make -C src/bin check PROVE_FLAGS='--timer'

请参阅 prove 的手册页以了解更多信息。

See the manual page of prove for more information.

make 变量 PROVE_TESTS 可用于定义相对于 Makefile 的路径的白空格分隔列表,调用 prove 以运行指定的测试子集(而不是默认 t/*.pl)。例如:

The make variable PROVE_TESTS can be used to define a whitespace-separated list of paths relative to the Makefile invoking prove to run the specified subset of tests instead of the default t/*.pl. For example:

make check PROVE_TESTS='t/001_test1.pl t/003_test3.pl'

TAP 测试需要 Perl 模块 IPC::Run。此模块可从 CPAN 或操作系统包中获取。它们还需要使用 —​enable-tap-tests 选项配置 PostgreSQL。

The TAP tests require the Perl module IPC::Run. This module is available from CPAN or an operating system package. They also require PostgreSQL to be configured with the option —​enable-tap-tests.

一般来说,如果您说 make installcheck,TAP 测试将测试之前安装的安装树中的可执行文件;如果您说 make check,则会基于当前源构建新的本地安装树。无论哪种情况,它们都会初始化本地实例(数据目录)并在其中瞬态运行服务器。其中一些测试会运行多个服务器。因此,这些测试可能相当耗费资源。

Generically speaking, the TAP tests will test the executables in a previously-installed installation tree if you say make installcheck, or will build a new local installation tree from current sources if you say make check. In either case they will initialize a local instance (data directory) and transiently run a server in it. Some of these tests run more than one server. Thus, these tests can be fairly resource-intensive.

重要的是要意识到,即使您说 make installcheck,TAP 测试也会启动测试服务器;这与传统的非 TAP 测试基础设施不同,在没有运行的测试服务器的情况下,后者希望使用已经运行的测试服务器。一些 PostgreSQL 子目录同时包含传统样式和 TAP 样式测试,这意味着 make installcheck 将从临时服务器和已经运行的测试服务器产生混合结果。

It’s important to realize that the TAP tests will start test server(s) even when you say make installcheck; this is unlike the traditional non-TAP testing infrastructure, which expects to use an already-running test server in that case. Some PostgreSQL subdirectories contain both traditional-style and TAP-style tests, meaning that make installcheck will produce a mix of results from temporary servers and the already-running test server.

33.4.1. Environment Variables #

数据目录根据测试文件名命名,如果测试失败,则将保留数据目录。如果设置了环境变量 PG_TEST_NOCLEAN,无论测试状态如何,都将保留数据目录。例如,在运行 pg_dump 测试时,无论测试结果如何,都保留数据目录:

Data directories are named according to the test filename, and will be retained if a test fails. If the environment variable PG_TEST_NOCLEAN is set, data directories will be retained regardless of test status. For example, retaining the data directory regardless of test results when running the pg_dump tests:

PG_TEST_NOCLEAN=1 make -C src/bin/pg_dump check

此环境变量还可以防止删除测试的临时目录。

This environment variable also prevents the test’s temporary directories from being removed.

测试套件中的许多操作都使用 180 秒的超时,在速度较慢的主机上,这可能导致负载引起的超时。将环境变量 PG_TEST_TIMEOUT_DEFAULT 设置为更高的数字将更改默认值以避免这种情况。

Many operations in the test suites use a 180-second timeout, which on slow hosts may lead to load-induced timeouts. Setting the environment variable PG_TEST_TIMEOUT_DEFAULT to a higher number will change the default to avoid this.