# Declare test services

> Prepare PostgreSQL or Redis declarations and check the current test-service availability limit.

Source: https://www.sorus.run/docs/guides/services
Reviewed: 2026-10-21

## Availability

**Declared test services are not yet offered to customer jobs.** The current application source reads service declarations but refuses them with `declared services are not offered yet`, before creating a job. The examples below describe the implemented schema and guest runtime, ready for when customer admission supports services.

The [test services reference](https://www.sorus.run/docs/reference/services) lists the complete catalogue, configuration fields, defaults, limits and permitted PostgreSQL settings.

## Declare the services

Add the services your tests need to `sorus.toml` at the repository root:

```toml
[[environment.service]]
name = "postgres"
version = "18.6"

[[environment.service]]
name = "redis"
version = "7.0.15"
```

Use exact versions. The declaration accepts catalogue services, not container images, custom entrypoints or commands. For an older checkout, follow [configuration-file compatibility](https://www.sorus.run/docs/release-status#existing-installations) and keep only one root configuration file.

## Connect from the tests

The services run inside the job's guest; they do not connect it to an external database. Sorus waits for both services to become ready, then starts the command with these connection variables:

| Variable                      | Default value                                            |
| ----------------------------- | -------------------------------------------------------- |
| `SORUS_SERVICE_POSTGRES_HOST` | `127.0.0.1`                                              |
| `SORUS_SERVICE_POSTGRES_PORT` | `5432`                                                   |
| `SORUS_SERVICE_POSTGRES_URL`  | `postgresql://postgres:postgres@127.0.0.1:5432/postgres` |
| `SORUS_SERVICE_REDIS_HOST`    | `127.0.0.1`                                              |
| `SORUS_SERVICE_REDIS_PORT`    | `6379`                                                   |
| `SORUS_SERVICE_REDIS_URL`     | `redis://127.0.0.1:6379`                                 |

Read these variables in your test configuration. If your application expects another variable such as `DATABASE_URL`, map the service URL to it in a repository script before starting the tests.

The defaults are credentials for the temporary, guest-local database. Do not put production credentials in the declaration.

## Initialise PostgreSQL

For tests that need a schema or seed data, add repository-relative SQL paths to the PostgreSQL entry:

```toml
[[environment.service]]
name = "postgres"
version = "18.6"
database = "app_test"
settings = { max_connections = "500" }
initialize = ["tests/sql/*.sql"]
```

Create the SQL files before submitting. A pattern may use `*` only in its last path component and must match captured files. Sorus applies files in byte order of path, one transaction per file, before starting the command. Prefix filenames with numbers when their order matters.

Service startup and SQL initialisation have a shared 60-second bound. A failing SQL file is reported as an input problem and the test command does not start.

## Choose memory and ports

The implemented schema defaults PostgreSQL to `1024` MiB and Redis to `256` MiB. Set `memory_mib` to change the limit: PostgreSQL accepts 256–16,384 MiB and Redis 32–16,384 MiB. Combined service limits may use at most half the selected class's job-memory ceiling and are deducted from the workload's available memory. Service-aware automatic sizing is not yet integrated into customer admission.

A custom `port` must be from 1024 to 65535, unique within the job and outside the guest-reserved ports `7401` and `7402`. Each service name may appear once. See the [configuration schema](https://www.sorus.run/docs/reference/services#configuration-schema) for the complete field rules.

## Run and verify

A job declaring these services cannot currently be submitted successfully. Keep tests that require them on a runner providing those databases until the [availability restriction](https://www.sorus.run/docs/reference/services#availability) is removed.

The implemented guest runtime discards services after each attempt, so database contents are not retained in build state. Initialisation runs again for a new attempt. [Runtime failure behavior](https://www.sorus.run/docs/reference/services#runtime-failures) describes the existing guest diagnostics; complete service reporting in customer job status is still pending.
