Skip to content

[#419] CI: Delete after Restore - #461

Merged
jesperpedersen merged 2 commits into
pgmoneta:mainfrom
ashu3103:local-test
Feb 2, 2025
Merged

jesperpedersen merged 2 commits into
pgmoneta:mainfrom
ashu3103:local-test

Conversation

@ashu3103

Copy link
Copy Markdown
Collaborator

WIP

Created a testsuitelocal.sh file to run local tests added to script directory in test.

How to run tests

# Move to the project directory
mkdir build
cd build
cmake -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Debug ..
make
./testsuitelocal.sh <postgres_user_password>

Why postgres password?

postgres user password is required to -

  • create cluster data directory using initdb
  • start the cluster using pg_ctl
  • perform DDL, DML (create role, create replication slot) operations in postgres server using psql

What's next....

  • Add the rest of the test case (only one test case is in this commit, will add more once everything is in place)

@jesperpedersen PTAL

@jesperpedersen

Copy link
Copy Markdown
Member

You can assume you have access - either directly or through sudo as https://github.com/pgmoneta/pgmoneta/blob/main/.github/workflows/ci.yml#L87

Just call the script testsuite.sh - we can make an argument later for local, container, ...

@jesperpedersen

Copy link
Copy Markdown
Member

Probably just one .h file in the end - and its .c scan for tests

@jesperpedersen

Copy link
Copy Markdown
Member

It should be quick to add a test, even if it is just for a function call

@ashu3103

Copy link
Copy Markdown
Collaborator Author

You can assume you have access - either directly or through sudo as https://github.com/pgmoneta/pgmoneta/blob/main/.github/workflows/ci.yml#L87

But in that case we must have the passwordless sudo default user otherwise user will be prompted to provide sudo password.

Just call the script testsuite.sh - we can make an argument later for local, container, ...

Sure!

@jesperpedersen

Copy link
Copy Markdown
Member

We can see. The user that does initdb is the super-user

@ashu3103

ashu3103 commented Jan 18, 2025 •

Copy link
Copy Markdown
Collaborator Author

We can see. The user that does initdb is the super-user

I think I'm losing track of the conversion.

Let's discuss the flow inside the script once -

  • The user pgmoneta will run the script testsuite.sh (Ideally pgmoneta/ should not necessarily have sudo permissions).
  • We'll be creating database cluster using initdb with pgmoneta user (the data directory will be owned by pgmoneta but superuser will be postgres for the database).
  • Now since pgmoneta owns the database directory it can edit the pg_hba.conf to local all postgres trust -> so now we can login as postgres user inside database without authentication and then make pgmoneta the super-user.
  • Continue with rest of the operations with pgmoneta as the user

In the above flow we won't be needing password anywhere I suppose.

@jesperpedersen

Copy link
Copy Markdown
Member

Just start with the user that is running the script - we can look at CI after.

So, your friend is whoami for pg_hba.conf

@jesperpedersen

Copy link
Copy Markdown
Member

And yes, use local too - we are testing pgmoneta not PostgreSQL

@ashu3103

Copy link
Copy Markdown
Collaborator Author

@jesperpedersen, The test suite script is currently testsuitelocal.sh PTAL,
I am working on adding a new tutorial to execute test suite locally (as of now).

@jesperpedersen

Copy link
Copy Markdown
Member
Usage: ./testsuitelocal.sh <postgres_password>

so we need an update where a password isn't required because it is run as the local user

@jesperpedersen

Copy link
Copy Markdown
Member

Yeah, there are a lot of su - postgres -c in the script - they need to go away, and -U postgres should be -U $(whoami) or do a specific user with the correct permissions

@ashu3103

ashu3103 commented Jan 23, 2025 via email •

Copy link
Copy Markdown
Collaborator Author

@jesperpedersen

Copy link
Copy Markdown
Member

There need to be

  • Check if pgmoneta has been compiled such that the files can be copied

The only output is

Check System Requirements 
check initdb in path ... ok
check pg_ctl in path ... ok
check psql in path ... ok
check postgresql version: 17.2 ... ok

Initializing Cluster 
The files belonging to this database system will be owned by user "jews".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are enabled.

@ashu3103

ashu3103 commented Jan 23, 2025 •

Copy link
Copy Markdown
Collaborator Author
  • Check if pgmoneta has been compiled such that the files can be copied

The script was actually meant to be executed from inside the build folder (so the above thing is already in check),
So we do something like

mkdir build
cd build
cmake -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Debug .. // This would simply copy the `testsuitelocal.sh` file inside the build folder and then we run it from build directory
make 
./testsuitelocal.sh

@jesperpedersen

Copy link
Copy Markdown
Member

Same output though

@ashu3103

Copy link
Copy Markdown
Collaborator Author

The flow is something like this -

Check System Requirements 
check initdb in path ... ok
check pg_ctl in path ... ok
check psql in path ... ok
check postgresql version: 17.2 ... ok

Initializing Cluster 
The files belonging to this database system will be owned by user "pgmoneta".
This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are enabled.

creating directory /tmp/test ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Kolkata
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok


Success. You can now start the database server using:

    pg_ctl -D /tmp/test -l logfile start

setting password_encryption ... scram-sha-256
setting unix_socket_directories ... '/tmp'
setting shared_buffers ... 2GB
setting port ... 5432
setting max_prepared_transactions ... 100
setting work_mem ... 16MB
setting wal_level ... replica
setting wal_log_hints ... on
setting max_wal_size ... 16GB
setting min_wal_size ... 2GB

Create HBA Configuration 
initialize hba configuration at /tmp/test/pg_hba.conf ... ok

Initializing Cluster 
waiting for server to start.... done
server started
localhost:5432 - accepting connections
postgres server is accepting requests ... ok
create role repl ... ok
create replication slot for repl ... ok
create user myuser ... ok
create database mydb with owner myuser ... ok
waiting for server to shut down.... done
server stopped

Initialize pgmoneta configuration files 
create restore directory /home/pgmoneta/pgmoneta/build/restore ... ok
create configuration directory /home/pgmoneta/pgmoneta/build/conf ... ok
create pgmoneta.conf and pgmoneta_users.conf inside /home/pgmoneta/pgmoneta/build/conf ... ok
add test configuration to pgmoneta.conf ... ok
pgmoneta-admin: The file ~/.pgmoneta/master.key already exists
pgmoneta-admin: Cannot generate master key
add user repl to pgmoneta_users.conf file ... ok

Execute Tests 
waiting for server to start.... done
server started
localhost:5432 - accepting connections
postgres server accepting requests ... ok
starting pgmoneta server in daemon mode (wait time = 5 seconds)
Header: 
  ClientVersion: 0.16.0
  Command: ping
  Compression: none
  Encryption: none
  Output: text
  Timestamp: 20250123003507
Outcome: 
  Status: true
  Time: 00:00:0.0000
Request: {}
Response: 
  ServerVersion: 0.16.0
pgmoneta server started ... ok
Running suite(s): pgmoneta_test1
Header: 
  ClientVersion: 0.16.0
  Command: backup
  Compression: none
  Encryption: none
  Output: text
  Timestamp: 20250123003507
Outcome: 
  Status: true
  Time: 00:00:1.0403
Request: 
  Server: primary
Response: 
  Backup: 20250123003507
  BackupSize: 8.32MB
  Compression: zstd
  Encryption: none
  MajorVersion: 14
  MinorVersion: 13
  RestoreSize: 49.72MB
  Server: primary
  ServerVersion: 0.16.0
  Valid: yes
Header: 
  ClientVersion: 0.16.0
  Command: restore
  Compression: none
  Encryption: none
  Output: text
  Timestamp: 20250123003508
Outcome: 
  Status: true
  Time: 00:00:6.7660
Request: 
  Backup: newest
  Directory: /home/pgmoneta/pgmoneta/build/restore/
  Position: current
  Server: primary
Response: 
  Backup: 20250123003507
  BackupSize: 8.32MB
  Comments: ''
  Compression: zstd
  Encryption: none
  MajorVersion: 14
  MinorVersion: 13
  RestoreSize: 49.72MB
  Server: primary
  ServerVersion: 0.16.0
100%: Checks: 2, Failures: 0, Errors: 0
/home/pgmoneta/pgmoneta/test/script/pgmoneta_test_1.c:125:P:Core:test_pgmoneta_backup:0: Passed
/home/pgmoneta/pgmoneta/test/script/pgmoneta_test_1.c:167:P:Core:test_pgmoneta_restore:0: Passed
running shutdown cli command
Header: 
  ClientVersion: 0.16.0
  Command: shutdown
  Compression: none
  Encryption: none
  Output: text
  Timestamp: 20250123003515
Outcome: 
  Status: true
  Time: 00:00:0.0000
Request: {}
shutdown pgmoneta server ... ok
waiting for server to shut down.... done
server stopped

Clean Test Resources 
remove restore directory /home/pgmoneta/pgmoneta/build/restore ... ok
remove data directory /tmp/test ... ok
remove base directory /tmp/pgmoneta ... ok
remove log file /tmp/pgmoneta_test.log ... ok

@ashu3103

Copy link
Copy Markdown
Collaborator Author

Same output though

Not sure why it paused there, have to take a look at it

@jesperpedersen

Copy link
Copy Markdown
Member
rm -Rf /tmp/test

...

localhost:5434 - accepting connections
postgres server accepting requests ... ok
starting pgmoneta server in daemon mode (wait time = 5 seconds)

and then nothing

@jesperpedersen

Copy link
Copy Markdown
Member

Maybe have a ./testsuite.sh clean target

@ashu3103

ashu3103 commented Jan 23, 2025 •

Copy link
Copy Markdown
Collaborator Author
rm -Rf /tmp/test

...

localhost:5434 - accepting connections
postgres server accepting requests ... ok
starting pgmoneta server in daemon mode (wait time = 5 seconds)

and then nothing

Yeah the script is caliberated to wait for 5 seconds to start completely. In your case the script process is terminated or is just in blocked state (used sleep 5 after pgmoneta server startup).

@ashu3103

Copy link
Copy Markdown
Collaborator Author

Maybe have a ./testsuite.sh clean target

Yeah, we can have an explicit command for cleaning stuff too.

@jesperpedersen

Copy link
Copy Markdown
Member

After the no output...

/usr/local/packages/postgresql-17.x/bin/postgres -D /tmp/test

so a pg_ctl ... stop is missing

@jesperpedersen

Copy link
Copy Markdown
Member
pgmoneta-admin: Existing user: repl
Header: 
  ClientVersion: 0.16.0
  Command: 25
  Compression: 0
  Encryption: 0
  Output: 0
  Timestamp: 20250123124503
Outcome: 
  Error: 1
  Status: false
pgmoneta-admin: Error for <user add>

@jesperpedersen

Copy link
Copy Markdown
Member

Are you starting with "clean" configuration files ?

Make sure that you NEVER override the ~/.pgmoneta/master.key file - so that operation is ok to fail

@ashu3103

ashu3103 commented Jan 23, 2025 •

Copy link
Copy Markdown
Collaborator Author
pgmoneta-admin: Existing user: repl
Header: 
  ClientVersion: 0.16.0
  Command: 25
  Compression: 0
  Encryption: 0
  Output: 0
  Timestamp: 20250123124503
Outcome: 
  Error: 1
  Status: false
pgmoneta-admin: Error for <user add>

The pgmoneta-admin <user add> command is executed to add user in pgmoneta_users.conf which is present in the build itself so maybe I can clean the configuration file added in build so that one don't have to make new fresh builds again and again.

For now you can just do

rm -r <path to build>/conf

@ashu3103

Copy link
Copy Markdown
Collaborator Author

Are you starting with "clean" configuration files ?

Yes, I am starting this.

Make sure that you NEVER override the ~/.pgmoneta/master.key file - so that operation is ok to fail

Noted!

@ashu3103

ashu3103 commented Feb 2, 2025 •

Copy link
Copy Markdown
Collaborator Author

What is up with CI ?

I think we have to explicitly setup pgmoneta_ext in th pipeline before running test suite, the logs are showing

2025-02-02 12:18:50.663 UTC [16863] FATAL: could not access file "pgmoneta_ext": No such file or directory

@ashu3103

ashu3103 commented Feb 2, 2025 •

Copy link
Copy Markdown
Collaborator Author

Also is there any other way to run ci.yml than to push the changes in the PR.

@jesperpedersen

jesperpedersen commented Feb 2, 2025 •

Copy link
Copy Markdown
Member

I think we have to explicitly setup pgmoneta_ext in th pipeline before running test suite

Can we make this optional for now ? Or remove

Also is there any other way to run ci.yml than to push the changes in the PR.

I don't think so

@ashu3103

ashu3103 commented Feb 2, 2025

Copy link
Copy Markdown
Collaborator Author

I think we have to explicitly setup pgmoneta_ext in th pipeline before running test suite

Can we make this optional for now ? Or remove

Yes

Also is there any other way to run ci.yml than to push the changes in the PR.

I don't think so

Okay!

@ashu3103

ashu3103 commented Feb 2, 2025

Copy link
Copy Markdown
Collaborator Author

@jesperpedersen, In the latest ci flow, in Run Test Suite step, I am not able to figure out why its showing ./testsuite.sh: line 434: /home/runner/work/pgmoneta/pgmoneta/build/test/pgmoneta_test: No such file or directory at line number 120.

@jesperpedersen

Copy link
Copy Markdown
Member

Hmm, it says ./testsuite clean -- so missing .sh

@jesperpedersen

Copy link
Copy Markdown
Member

@jesperpedersen, In the latest ci flow, in Run Test Suite step, I am not able to figure out why its showing ./testsuite.sh: line 434: /home/runner/work/pgmoneta/pgmoneta/build/test/pgmoneta_test: No such file or directory at line number 120.

Maybe start by list all the files

@jesperpedersen

Copy link
Copy Markdown
Member

Maybe you need to install the ctest deb...

@jesperpedersen

Copy link
Copy Markdown
Member

You can add a check for the test requirements in the top-level /CMakeLists.txt file

@jesperpedersen

Copy link
Copy Markdown
Member

Ok, there is a check for it...

Maybe add a check in testsuite.sh that the ctest binary is in the path - otherwise skip

@jesperpedersen

Copy link
Copy Markdown
Member

Happy ?

@ashu3103

ashu3103 commented Feb 2, 2025 •

Copy link
Copy Markdown
Collaborator Author

Happy ?

:), Thanks!!

Will make changes for build-macos

@jesperpedersen

Copy link
Copy Markdown
Member

Ok

@ashu3103
ashu3103 force-pushed the local-test branch 5 times, most recently from b45c6c4 to a167089 Compare February 2, 2025 16:01
@jesperpedersen

Copy link
Copy Markdown
Member

@Annupamaa Do you have ideas about CI ?

Annupamaa and others added 2 commits February 3, 2025 00:51
While building the project for MacOS, it is failing
at rt library linking part. After some investigation,
I found that rt library linking is required only for
linux system. Hence, adding a check for MacOS.

Signed-off-by: Annupamaa <[email protected]>

-v
@ashu3103

ashu3103 commented Feb 2, 2025

Copy link
Copy Markdown
Collaborator Author

@jesperpedersen, PTAL

@jesperpedersen
jesperpedersen merged commit a88cb4b into pgmoneta:main Feb 2, 2025
@jesperpedersen

Copy link
Copy Markdown
Member

Rebased, and merged.

Thanks for your contribution !

@jesperpedersen

Copy link
Copy Markdown
Member

@Annupamaa See if you can get CI/Mac working

@ashu3103
ashu3103 deleted the local-test branch February 2, 2025 19:34
@Annupamaa

Copy link
Copy Markdown
Contributor

@jesperpedersen Yes, I can work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants