diff mbox series

[2/2] support/testing/tests/package/test_postgresql.py: new test

Message ID 20231010164554.2954023-2-adam.duskett@amarulasolutions.com
State Changes Requested
Headers show
Series [1/2] package/postgresql/postgresql.service: set locale for initdb to C | expand

Commit Message

Adam Duskett Oct. 10, 2023, 4:45 p.m. UTC
Perform a basic check that performs the following:
  - Check if /var/lib/pgsql/postmaster.pid exists.
  - Check if 'psql -c SHOW server_version;' returns sucessfully.

Note: systemd takes quite a while to start up, so check the output of
      `systemctl is-active postgresql` until it shows "active" with a timeout
      of 15 seconds.
Signed-off-by: Adam Duskett <adam.duskett@amarulasolutions.com>
---
 DEVELOPERS                                    |  1 +
 .../testing/tests/package/test_postgresql.py  | 76 +++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 support/testing/tests/package/test_postgresql.py

Comments

Thomas Petazzoni Nov. 1, 2023, 4:43 p.m. UTC | #1
Hello,

On Tue, 10 Oct 2023 18:45:54 +0200
Adam Duskett <adam.duskett@amarulasolutions.com> wrote:

> +class TestPostgreSQLInitd(infra.basetest.BRTest):

Initd is not a very good name. To me Initd doesn't mean
"Sysvinit/Busybox init".

I see the polkit tests already use that naming, though.

> +    config: str = """

Any reason to use this syntax? I don't have anything against it, but
it's not consistent with how we define the configuration in other test
cases, and I like consistency.

> +        BR2_arm=y
> +        BR2_cortex_a9=y
> +        BR2_ARM_ENABLE_VFP=y
> +        BR2_TOOLCHAIN_EXTERNAL=y
> +        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y

Any reason not to use BASIC_TOOLCHAIN_CONFIG instead?

> +        BR2_PER_PACKAGE_DIRECTORIES=y

Not needed.

> +        BR2_PACKAGE_POSTGRESQL=y
> +        BR2_TARGET_ROOTFS_EXT2=y
> +        BR2_TARGET_ROOTFS_EXT2_4=y
> +        BR2_TARGET_ROOTFS_EXT2_SIZE="128M"
> +        # BR2_TARGET_ROOTFS_TAR is not set
> +        """
> +
> +    def test_run(self):
> +        img = os.path.join(self.builddir, "images", "rootfs.ext2")
> +        self.emulator.boot(
> +            arch="armv7",

This would have to be changed to arvm5 if you use the
BASIC_TOOLCHAIN_CONFIG.

Long term, maybe we could consider changing the BASIC_TOOLCHAIN_CONFIG
to use ARMv7, would perhaps be more sensible than the aging ARMv5
architecture.

Thomas
diff mbox series

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index 3fffc4346c..2421bf8ff7 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -38,6 +38,7 @@  F:	package/flutter-gallery/
 F:	package/flutter-pi/
 F:	package/flutter-sdk-bin/
 F:	support/testing/tests/package/test_flutter.py
+F:	support/testing/tests/package/test_postgresql.py
 
 N:	Adam Heinrich <adam@adamh.cz>
 F:	package/jack1/
diff --git a/support/testing/tests/package/test_postgresql.py b/support/testing/tests/package/test_postgresql.py
new file mode 100644
index 0000000000..b510a02f44
--- /dev/null
+++ b/support/testing/tests/package/test_postgresql.py
@@ -0,0 +1,76 @@ 
+import os
+import time
+import infra.basetest
+
+
+class TestPostgreSQLInitd(infra.basetest.BRTest):
+    config: str = """
+        BR2_arm=y
+        BR2_cortex_a9=y
+        BR2_ARM_ENABLE_VFP=y
+        BR2_TOOLCHAIN_EXTERNAL=y
+        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
+        BR2_PER_PACKAGE_DIRECTORIES=y
+        BR2_PACKAGE_POSTGRESQL=y
+        BR2_TARGET_ROOTFS_EXT2=y
+        BR2_TARGET_ROOTFS_EXT2_4=y
+        BR2_TARGET_ROOTFS_EXT2_SIZE="128M"
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    def test_run(self):
+        img = os.path.join(self.builddir, "images", "rootfs.ext2")
+        self.emulator.boot(
+            arch="armv7",
+            kernel="builtin",
+            kernel_cmdline=["root=/dev/mmcblk0"],
+            options=["-drive", f"file={img},if=sd,format=raw"])
+        self.emulator.login()
+
+        # Check if the Daemon is running
+        self.assertRunOk("ls /var/lib/pgsql/postmaster.pid")
+
+        # Check if we can connect to the database.
+        self.assertRunOk("su postgres -c \"psql -c 'SHOW server_version;'\"")
+
+
+class TestPostgreSQLSystemd(infra.basetest.BRTest):
+    config: str = """
+        BR2_arm=y
+        BR2_cortex_a9=y
+        BR2_ARM_ENABLE_VFP=y
+        BR2_TOOLCHAIN_EXTERNAL=y
+        BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y
+        BR2_INIT_SYSTEMD=y
+        BR2_PER_PACKAGE_DIRECTORIES=y
+        BR2_PACKAGE_POSTGRESQL=y
+        BR2_TARGET_ROOTFS_EXT2=y
+        BR2_TARGET_ROOTFS_EXT2_4=y
+        BR2_TARGET_ROOTFS_EXT2_SIZE="128M"
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    def test_run(self):
+        img = os.path.join(self.builddir, "images", "rootfs.ext2")
+        self.emulator.boot(
+            arch="armv7",
+            kernel="builtin",
+            kernel_cmdline=["root=/dev/mmcblk0"],
+            options=["-drive", f"file={img},if=sd,format=raw"])
+        self.emulator.login()
+
+        # Check if the Daemon is running
+        self.assertRunOk("ls /var/lib/pgsql/postmaster.pid")
+
+        # It may take some time for PostgreSQL to finish startup. Give it at least 15 seconds.
+        is_active = False
+        for i in range(15):
+            output, _ = self.emulator.run("systemctl is-active postgresql")
+            if output[0] == "active":
+                is_active = True
+                break
+            time.sleep(1)
+        if not is_active:
+            self.fail("postgresql failed to active.")
+        # Check if we can connect to the database.
+        self.assertRunOk("cd / && su postgres -c \"psql -c 'SHOW server_version;'\"")