Skip to content

Commit

Permalink
Rewrite health check
Browse files Browse the repository at this point in the history
  • Loading branch information
EinKrebs committed Apr 15, 2024
1 parent b4db979 commit 55d48b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
20 changes: 4 additions & 16 deletions test/feature/features/scram_auth.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,20 @@ Feature: SCRAM auth test
ROUTER_CONFIG=/spqr/test/feature/conf/router_with_scram_backend.yaml
"""
Given cluster is up and running
When I run command on host "shard1" with timeout "220" seconds
When I run command on host "shard1"
"""
echo 'host all all all scram-sha-256' > /var/lib/postgresql/13/main/pg_hba.conf
service postgresql reload
for (( i = 0; i < 10; i++)); do
if PGPASSWORD=12345678 psql -h spqr_shard_1 -p 6432 -d db1 -U user1 -c "SELECT 1"; then
break
else
sleep 20
fi
done
"""
Then command return code should be "0"
When I run command on host "shard2" with timeout "220" seconds
And I wait for host "shard1" to respond
When I run command on host "shard2"
"""
echo 'host all all all scram-sha-256' > /var/lib/postgresql/13/main/pg_hba.conf
service postgresql reload
for (( i = 0; i < 10; i++)); do
if PGPASSWORD=12345678 psql -h spqr_shard_2 -p 6432 -d db1 -U user1 -c "SELECT 1"; then
break
else
sleep 20
fi
done
"""
Then command return code should be "0"
And I wait for host "shard2" to respond
When I run SQL on host "router"
"""
SELECT 1
Expand Down
15 changes: 14 additions & 1 deletion test/feature/spqr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,19 @@ func (tctx *testContext) stepHostIsStarted(service string) error {
return fmt.Errorf("service %s was not found in docker composer", service)
}

func (tctx *testContext) stepWaitPostgresqlToRespond(host string) error {
const trials = 10
const timeout = 20 * time.Second
for i := 0; i < trials; i++ {
_, err := tctx.queryPostgresql(host, "SELECT 1", struct{}{})
if err == nil {
return nil
}
time.Sleep(timeout)
}
return fmt.Errorf("host \"%s\" did not respond until timeout", host)
}

func (tctx *testContext) stepIRunCommandOnHost(host string, body *godog.DocString) error {
cmd := strings.TrimSpace(body.Content)
var err error
Expand Down Expand Up @@ -940,11 +953,11 @@ func InitializeScenario(s *godog.ScenarioContext, t *testing.T, debug bool) {
s.Step(`^SQL error on host "([^"]*)" should match (\w+)$`, tctx.stepErrorShouldMatch)
s.Step(`^file "([^"]*)" on host "([^"]*)" should match (\w+)$`, tctx.stepFileOnHostShouldMatch)
s.Step(`^I fail to run SQL on host "([^"]*)"$`, tctx.stepIFailSQLOnHost)
s.Step(`^I wait for host "([^"]*)" to respond$`, tctx.stepWaitPostgresqlToRespond)

// variable manipulation
s.Step(`^we save response row "([^"]*)" column "([^"]*)"$`, tctx.stepSaveResponseBodyAtPathAsJSON)
s.Step(`^hide "([^"]*)" field$`, tctx.stepHideField)

}

func TestSpqr(t *testing.T) {
Expand Down

0 comments on commit 55d48b7

Please sign in to comment.