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

Adam Duskett adam.duskett at amarulasolutions.com
Mon Dec 18 18:10:22 UTC 2023


On Mon, Dec 18, 2023 at 10:41 AM Adam Duskett <aduskett at gmail.com> wrote:
>
> Yann;
>
> Thank you for reviewing the test.
>
> On Mon, Dec 18, 2023 at 10:31 AM Yann E. MORIN <yann.morin.1998 at free.fr> wrote:
> >
> > Adam, All,
> >
> > On 2023-11-02 12:41 -0600, Adam Duskett spake thusly:
> > > 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.
> >
> > Thanks for this new runtime test!
> >
> > > 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.
> >
> > I think that we already concluded that testing if a unit was active or
> > not was not representing whether the service was actually running. In
> > the fultter test case for example, the unit was active, but the flutter
> > app was just keeping crashing again and again, so the test wsa failing
> > to detect failure...
> >
> test_flutter.py:
> cmd = "systemctl is-active flutter-gallery"
> I am following what is in test_flutter.py...
To add to this, running a query on pgsql would fail if pgsql isn't running,
so this is perfectly safe.

>
> >
> > So, I don't think usingt is-active is a good way to test whether a
> > service is actually running.
> >
> > Furthermore, the unit may be active, but the service might not yet be
> > ready to serve, so again I don;t think it is still valid to reply on it.
> >
> > > Signed-off-by: Adam Duskett <adam.duskett at amarulasolutions.com>
> > > ---
> > >   - Drop BR2_PER_PACKAGE_DIRECTORIES (Thomas)
> >
> We need a consensus on this. This shouldn't happen. Either it is OK to
> enable PPD in tests or it isn't.
>
> > Actually, I disagree with Thomas here: we added support for PPD in the
> > infra, so that if PPD is enabled in a test, then TLPB is done to speed
> > up the test.
> >
> > [--SNIP--]
> > > diff --git a/support/testing/tests/package/test_postgresql.py b/support/testing/tests/package/test_postgresql.py
> > > new file mode 100644
> > > index 0000000000..fa692bab7b
> > > --- /dev/null
> > > +++ b/support/testing/tests/package/test_postgresql.py
> > > @@ -0,0 +1,73 @@
> > > +import os
> > > +import time
> > > +import infra.basetest
> > > +
> > > +
> > > +class TestPostgreSQLInitSysV(infra.basetest.BRTest):
> > > +    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
> > > +        """
> > > +        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="armv5",
> > > +            kernel="builtin",
> > > +            options=["-drive", f"file={img},if=scsi,format=raw"],
> > > +            kernel_cmdline=["root=/dev/sda"])
> > > +        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;'\"")
> >
> > I don't understand why we need to test for the PID file before we
> > connect to the daemon. If the daemon is not running, we won't be able to
> > connect to it, so the test will fail, so the PID file test is redundant,
> > no?
> I am being thorough. I can remove the check for the PID file if you want.
> >
> > Regards,
> > Yann E. MORIN.
> >
> > > +
> > > +class TestPostgreSQLInitSystemd(infra.basetest.BRTest):
> > > +    # Taken from test_systemd.py
> > > +    config = """
> > > +        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_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
> > > +        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",
> > > +            options=["-drive", f"file={img},if=sd,format=raw"],
> > > +            kernel_cmdline=["root=/dev/mmcblk0"])
> > > +        self.emulator.login()
> > > +
> > > +        # 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 activate!")
> > > +
> > > +        # Check if the Daemon is running
> > > +        self.assertRunOk("ls /var/lib/pgsql/postmaster.pid")
> > > +
> > > +        # Check if we can connect to the database.
> > > +        self.assertRunOk("cd / && su postgres -c \"psql -c 'SHOW server_version;'\"")
> > > --
> > > 2.41.0
> > >
> > > _______________________________________________
> > > buildroot mailing list
> > > buildroot at buildroot.org
> > > https://lists.buildroot.org/mailman/listinfo/buildroot
> >
> > --
> > .-----------------.--------------------.------------------.--------------------.
> > |  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
> > | +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
> > | +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
> > | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
> > '------------------------------^-------^------------------^--------------------'
> > _______________________________________________
> > buildroot mailing list
> > buildroot at buildroot.org
> > https://lists.buildroot.org/mailman/listinfo/buildroot



More information about the buildroot mailing list