meson: Add 'running' test setup, as a replacement for installcheck
authorAndres Freund <[email protected]>
Wed, 7 Dec 2022 20:13:35 +0000 (12:13 -0800)
committerAndres Freund <[email protected]>
Wed, 7 Dec 2022 20:13:35 +0000 (12:13 -0800)
To run all tests that support running against existing server:
$ meson test --setup running

To run just the main pg_regress tests against existing server:
$ meson test --setup running regress-running/regress

To ensure the 'running' setup continues to work, test it as part of the
freebsd CI task.

Discussion: https://postgr.es/m/CAH2-Wz=XDQcmLoo7RR_i6FKQdDmcyb9q5gStnfuuQXrOGhB2sQ@mail.gmail.com

17 files changed:
.cirrus.yml
contrib/basic_archive/meson.build
contrib/pg_freespacemap/meson.build
contrib/pg_stat_statements/meson.build
contrib/pg_walinspect/meson.build
contrib/test_decoding/meson.build
doc/src/sgml/installation.sgml
meson.build
src/interfaces/ecpg/test/meson.build
src/test/isolation/meson.build
src/test/modules/commit_ts/meson.build
src/test/modules/snapshot_too_old/meson.build
src/test/modules/test_oat_hooks/meson.build
src/test/modules/test_pg_dump/meson.build
src/test/modules/test_slru/meson.build
src/test/modules/worker_spi/meson.build
src/test/regress/meson.build

index f31923333ef979d47905a560d472c86656879817..0113799a6e22f98b99b428343f3b31191c599d24 100644 (file)
@@ -195,6 +195,21 @@ task:
       meson test $MTEST_ARGS --num-processes ${TEST_JOBS}
     EOF
 
+  # test runningcheck, freebsd chosen because it's currently fast enough
+  test_running_script: |
+    su postgres <<-EOF
+      set -e
+      ulimit -c unlimited
+      meson test $MTEST_ARGS --quiet --suite setup
+      export LD_LIBRARY_PATH="$(pwd)/build/tmp_install/usr/local/pgsql/lib/:$LD_LIBRARY_PATH"
+      mkdir -p build/testrun
+      build/tmp_install/usr/local/pgsql/bin/initdb -N build/runningcheck --no-instructions -A trust
+      echo "include '$(pwd)/src/tools/ci/pg_ci_base.conf'" >> build/runningcheck/postgresql.conf
+      build/tmp_install/usr/local/pgsql/bin/pg_ctl -c -o '-c fsync=off' -D build/runningcheck -l build/testrun/runningcheck.log start
+      meson test $MTEST_ARGS --num-processes ${TEST_JOBS} --setup running
+      build/tmp_install/usr/local/pgsql/bin/pg_ctl -D build/runningcheck stop
+    EOF
+
   on_failure:
     <<: *on_failure_meson
     cores_script: src/tools/ci/cores_backtrace.sh freebsd /tmp/cores
index c30dcfa5d41f9232f96159ed8456fff7d7648ef3..08d72598e9d887cadbc06199f81fb539969b30c2 100644 (file)
@@ -25,5 +25,8 @@ tests += {
     'regress_args': [
       '--temp-config', files('basic_archive.conf'),
     ],
+    # Disabled because these tests require "shared_preload_libraries=basic_archive",
+    # which typical runningcheck users do not have (e.g. buildfarm clients).
+    'runningcheck': false,
   },
 }
index 904b37b6e9b4f701a9ced1b9711b1538060f5e12..f802e297b67ded0fc19f9396e4c8249bd0d12d29 100644 (file)
@@ -33,5 +33,8 @@ tests += {
     'regress_args': [
       '--temp-config', files('pg_freespacemap.conf')
     ],
+    # Disabled because these tests require "autovacuum=off", which
+    # typical runningcheck users do not have (e.g. buildfarm clients).
+    'runningcheck': false,
   },
 }
index 854df138e762d546d43f0efef25269df714210f4..bd0e42331ebb7aeec48f01b7efc9fea4a4cfba34 100644 (file)
@@ -41,5 +41,9 @@ tests += {
       'pg_stat_statements',
     ],
     'regress_args': ['--temp-config', files('pg_stat_statements.conf')],
+    # Disabled because these tests require
+    # "shared_preload_libraries=pg_stat_statements", which typical
+    # runningcheck users do not have (e.g. buildfarm clients).
+    'runningcheck': false,
   },
 }
index 4314a3182a24618fe60bace6845d8566c2d69859..351f184de83d91f5ff107e5ca49f5be34d8dd1d4 100644 (file)
@@ -28,6 +28,9 @@ tests += {
     'sql': [
       'pg_walinspect',
     ],
+    # Disabled because these tests require "wal_level=replica", which
+    # some runningcheck users do not have (e.g. buildfarm clients).
     'regress_args': ['--temp-config', files('walinspect.conf')],
+    'runningcheck': false,
   },
 }
index 6876792fd86ca37fcd6176f5909f8a89841d1e6b..65dfd3f7d88584a71342518d03be6ecf1e98f2b7 100644 (file)
@@ -43,6 +43,9 @@ tests += {
     'regress_args': [
       '--temp-config', files('logical.conf'),
     ],
+    # Disabled because these tests require "wal_level=logical", which
+    # typical runningcheck users do not have (e.g. buildfarm clients).
+    'runningcheck': false,
   },
   'isolation': {
     'specs': [
@@ -61,6 +64,8 @@ tests += {
     'regress_args': [
       '--temp-config', files('logical.conf'),
     ],
+    # see above
+    'runningcheck': false,
   },
   'tap': {
     'tests': [
index 9c7f019392e151ca81653b4648379a145561fb97..f64f32904470607443c37fce9fb251b4fc8e85e9 100644 (file)
@@ -2108,6 +2108,12 @@ ninja
     detailed information about interpreting the test results. You can
     repeat this test at any later time by issuing the same command.
    </para>
+
+   <para>
+    To run pg_regress and pg_isolation_regress tests against a running
+    postgres instance, specify <userinput>--setup running</userinput> as an
+    argument to <userinput>meson test</userinput>.
+   </para>
   </step>
 
   <step id="meson-install">
index 39fc3ddab260cc8284f25a7bd0e6d4c7d4b1221c..3cb50c0b1725ebcbd1cb4151131b5a4e0113271f 100644 (file)
@@ -2920,6 +2920,20 @@ endif
 # Test Generation
 ###############################################################
 
+# When using a meson version understanding exclude_suites, define a
+# 'tmp_install' test setup (the default) that excludes tests running against a
+# pre-existing install and a 'running' setup that conflicts with creation of
+# the temporary installation and tap tests (which don't support running
+# against a running server).
+
+running_suites = []
+install_suites = []
+if meson.version().version_compare('>=0.57')
+  runningcheck = true
+else
+  runningcheck = false
+endif
+
 testwrap = files('src/tools/testwrap')
 
 foreach test_dir : tests
@@ -2927,7 +2941,6 @@ foreach test_dir : tests
     testwrap,
     '--basedir', meson.build_root(),
     '--srcdir', test_dir['sd'],
-    '--testgroup', test_dir['name'],
   ]
 
   foreach kind, v : test_dir
@@ -2940,55 +2953,94 @@ foreach test_dir : tests
     if kind in ['regress', 'isolation', 'ecpg']
       if kind == 'regress'
         runner = pg_regress
+        fallback_dbname = 'regression_@0@'
       elif kind == 'isolation'
         runner = pg_isolation_regress
+        fallback_dbname = 'isolation_regression_@0@'
       elif kind == 'ecpg'
         runner = pg_regress_ecpg
+        fallback_dbname = 'ecpg_regression_@0@'
       endif
 
-      test_output = test_result_dir / test_dir['name'] / kind
+      test_group = test_dir['name']
+      test_group_running = test_dir['name'] + '-running'
 
-      test_command = [
+      test_output = test_result_dir / test_group / kind
+      test_output_running = test_result_dir / test_group_running/ kind
+
+      # Unless specified by the test, choose a non-conflicting database name,
+      # to avoid conflicts when running against existing server.
+      dbname = t.get('dbname',
+        fallback_dbname.format(test_dir['name']))
+
+      test_command_base = [
         runner.full_path(),
         '--inputdir', t.get('inputdir', test_dir['sd']),
         '--expecteddir', t.get('expecteddir', test_dir['sd']),
-        '--outputdir', test_output,
-        '--temp-instance', test_output / 'tmp_check',
         '--bindir', '',
         '--dlpath', test_dir['bd'],
         '--max-concurrent-tests=20',
-        '--port', testport.to_string(),
+        '--dbname', dbname,
       ] + t.get('regress_args', [])
 
+      test_selection = []
       if t.has_key('schedule')
-        test_command += ['--schedule', t['schedule'],]
+        test_selection += ['--schedule', t['schedule'],]
       endif
 
       if kind == 'isolation'
-        test_command += t.get('specs', [])
+        test_selection += t.get('specs', [])
       else
-        test_command += t.get('sql', [])
+        test_selection += t.get('sql', [])
       endif
 
       env = test_env
       env.prepend('PATH', temp_install_bindir, test_dir['bd'])
 
       test_kwargs = {
-        'suite': [test_dir['name']],
         'priority': 10,
         'timeout': 1000,
         'depends': test_deps + t.get('deps', []),
         'env': env,
       } + t.get('test_kwargs', {})
 
-      test(test_dir['name'] / kind,
+      test(test_group / kind,
         python,
-        args: testwrap_base + [
+        args: [
+          testwrap_base,
+          '--testgroup', test_group,
           '--testname', kind,
-          '--', test_command,
+          '--',
+          test_command_base,
+          '--outputdir', test_output,
+          '--temp-instance', test_output / 'tmp_check',
+          '--port', testport.to_string(),
+          test_selection,
         ],
+        suite: test_group,
         kwargs: test_kwargs,
       )
+      install_suites += test_group
+
+      # some tests can't support running against running DB
+      if runningcheck and t.get('runningcheck', true)
+        test(test_group_running / kind,
+          python,
+          args: [
+            testwrap_base,
+            '--testgroup', test_group_running,
+            '--testname', kind,
+            '--',
+            test_command_base,
+            '--outputdir', test_output_running,
+            test_selection,
+          ],
+          is_parallel: t.get('runningcheck-parallel', true),
+          suite: test_group_running,
+          kwargs: test_kwargs,
+        )
+        running_suites += test_group_running
+      endif
 
       testport += 1
     elif kind == 'tap'
@@ -3011,9 +3063,10 @@ foreach test_dir : tests
         env.set(name, value)
       endforeach
 
+      test_group = test_dir['name']
       test_kwargs = {
         'protocol': 'tap',
-        'suite': [test_dir['name']],
+        'suite': test_group,
         'timeout': 1000,
         'depends': test_deps + t.get('deps', []),
         'env': env,
@@ -3033,12 +3086,14 @@ foreach test_dir : tests
           python,
           kwargs: test_kwargs,
           args: testwrap_base + [
+            '--testgroup', test_dir['name'],
             '--testname', onetap_p,
             '--', test_command,
             test_dir['sd'] / onetap,
           ],
         )
       endforeach
+      install_suites += test_group
     else
       error('unknown kind @0@ of test in @1@'.format(kind, test_dir['sd']))
     endif
@@ -3047,6 +3102,14 @@ foreach test_dir : tests
 
 endforeach # directories with tests
 
+# repeat condition so meson realizes version dependency
+if meson.version().version_compare('>=0.57')
+  add_test_setup('tmp_install',
+    is_default: true,
+    exclude_suites: running_suites)
+  add_test_setup('running',
+    exclude_suites: ['setup'] + install_suites)
+endif
 
 
 ###############################################################
index 94b26d10314638c7663efeb67b32f04cc17e42d4..d4f1f1c0fcf7325aeab92be538b4e3f052708dc8 100644 (file)
@@ -84,6 +84,7 @@ tests += {
     'test_kwargs': {
       'depends': ecpg_test_dependencies,
     },
+    'dbname': 'ecpg1_regression,ecpg2_regression',
     'regress_args': ecpg_regress_args,
   },
 }
index e2ed400a80aed7b8e52cf5b4fa050fd3eee5f665..a999791876a48beda8980cdc7195e8834d3f7d84 100644 (file)
@@ -67,5 +67,6 @@ tests += {
       'priority': 40,
       'timeout': 1000,
     },
+    'dbname': 'isolation_regression',
   },
 }
index 60cb12164d221d1847ef5b3611800b42f6af8a70..fa86e70e880bc639c1b8d8fc8dec93f0401839ab 100644 (file)
@@ -6,6 +6,9 @@ tests += {
     'sql': [
       'commit_timestamp',
     ],
+    # Disabled because these tests require "track_commit_timestamp = on",
+    # which typical runningcheck users do not have (e.g. buildfarm clients).
+    'runningcheck': false,
   },
   'tap': {
     'tests': [
index efd3f1f113bea9206d0f71934e8eb18e589ad245..5094b52949b7652cda4b3f19f41629beb2d51d27 100644 (file)
@@ -10,5 +10,8 @@ tests += {
       'sto_using_hash_index',
     ],
     'regress_args': ['--temp-config', files('sto.conf')],
+    # Disabled because these tests require "old_snapshot_threshold" >= 0, which
+    # typical runningcheck users do not have (e.g. buildfarm clients).
+    'runningcheck': false,
   },
 }
index 8802bbbac55e84e667ef9069b6a98e081bf1e5af..e9d09d92c3042bc01fc21cdbc2a7b4d6d7e48e3b 100644 (file)
@@ -25,5 +25,6 @@ tests += {
       'test_oat_hooks',
     ],
     'regress_args': ['--no-locale', '--encoding=UTF8'],
+    'runningcheck': false,
   },
 }
index 41021829f3a4323a788cca79d6ee0da4d04b4b0f..73f1fcf94283341e5df4320cbd11c1b8619f579e 100644 (file)
@@ -13,6 +13,8 @@ tests += {
     'sql': [
       'test_pg_dump',
     ],
+    # doesn't delete its user
+    'runningcheck': false,
   },
   'tap': {
     'tests': [
index ca4633c793e42c86c3c3753ad66974abc29ec3d0..74dacd11ac8b3e4c8aa462dd6739845eae8ec503 100644 (file)
@@ -31,5 +31,6 @@ tests += {
       'test_slru',
     ],
     'regress_args': ['--temp-config', files('test_slru.conf')],
+    'runningcheck': false,
   },
 }
index a4a158c75b96d62cd053c6bea1c3cedf07352c7e..660d721eea9b3aff693972a2529e3b9003437094 100644 (file)
@@ -30,6 +30,8 @@ tests += {
     'sql': [
       'worker_spi',
     ],
-    'regress_args': ['--temp-config', files('dynamic.conf'), '--dbname=contrib_regression'],
+    'dbname': 'contrib_regression',
+    'regress_args': ['--temp-config', files('dynamic.conf')],
+    'runningcheck': false,
   },
 }
index 72a23737fa708bbfa95375157d79b5ba0e56f9f7..fbca624948b44ee97a6a3470db709c3861223372 100644 (file)
@@ -75,5 +75,6 @@ tests += {
       'priority': 50,
       'timeout': 1000,
     },
+    'dbname': 'regression',
   },
 }