feat(testing): add full integration test suite
Some checks failed
Integration Tests / integration-test (push) Failing after -23m59s
Some checks failed
Integration Tests / integration-test (push) Failing after -23m59s
This commit introduces a comprehensive integration test suite for the pgsql-broker. The test suite includes: - A Docker/Podman environment for running a PostgreSQL database, managed via a . - Integration tests that cover the broker's lifecycle, including job creation, execution, and instance management. - A GitHub Actions workflow to automate the execution of all tests on push and pull requests. - A dedicated test configuration file () and helper test files. refactor(worker): fix job processing transaction - The worker's job processing now uses a single transaction to fetch and run a job, resolving a race condition where jobs were not in the 'running' state when being executed. - The broker's database instance registration is now more robust, handling cases where another instance is already active. The Makefile has been significantly updated to orchestrate the entire test flow, including setting up the database, starting/stopping the broker, and running unit and integration tests separately.
This commit is contained in:
31
tests/integration/connection_test.go
Normal file
31
tests/integration/connection_test.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestConnection(t *testing.T) {
|
||||
connStr := "user=user password=password dbname=broker_test port=5433 sslmode=disable"
|
||||
var db *sql.DB
|
||||
var err error
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
db, err = sql.Open("postgres", connStr)
|
||||
require.NoError(t, err)
|
||||
err = db.Ping()
|
||||
if err == nil {
|
||||
t.Log("Successfully connected to the database")
|
||||
db.Close()
|
||||
return
|
||||
}
|
||||
t.Logf("Failed to connect to database (attempt %d), retrying... Error: %v", i+1, err)
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
|
||||
require.NoError(t, err, "Failed to connect to database after retries")
|
||||
}
|
||||
Reference in New Issue
Block a user