Skip to content

Commit

Permalink
test: Add pg_cron to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Mar 29, 2024
1 parent 669fce5 commit 7a4862a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
11 changes: 11 additions & 0 deletions postgres.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM postgres:14

RUN apt-get update && apt-get install -y postgresql-14-cron

RUN echo "shared_preload_libraries = 'pg_cron'" >> /usr/share/postgresql/postgresql.conf.sample

RUN echo "CREATE EXTENSION pg_cron;" > /docker-entrypoint-initdb.d/init-pg-cron.sql

EXPOSE 5432

CMD ["postgres"]
15 changes: 12 additions & 3 deletions runner/tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { PostgreSqlContainer, type StartedPostgreSqlContainer } from './testcont
import block1 from './blocks/00115185108/streamer_message.json';

describe('Indexer integration', () => {
jest.setTimeout(600000);
jest.setTimeout(300_000);

let network: StartedNetwork;
let postgresContainer: StartedPostgreSqlContainer;
let hasuraContainer: StartedHasuraGraphQLContainer;

beforeAll(async () => {
network = await new Network().start();
postgresContainer = await new PostgreSqlContainer()
postgresContainer = await (await PostgreSqlContainer.build())
.withNetwork(network)
.start();
hasuraContainer = await (await HasuraGraphQLContainer.build())
Expand Down Expand Up @@ -54,7 +54,16 @@ describe('Indexer integration', () => {
database: postgresContainer.getDatabase(),
});

const provisioner = new Provisioner(hasuraClient, pgClient, pgClient);
const provisioner = new Provisioner(
hasuraClient,
pgClient,
pgClient,
{
cronDatabase: postgresContainer.getDatabase(),
postgresHost: postgresContainer.getIpAddress(),
postgresPort: Number(postgresContainer.getPort()),
}
);

const indexer = new Indexer(
{
Expand Down
33 changes: 21 additions & 12 deletions runner/tests/testcontainers/postgres.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { AbstractStartedContainer, GenericContainer, type StartedTestContainer, Wait } from 'testcontainers';
import { AbstractStartedContainer, GenericContainer, type StartedTestContainer, Wait, type StartedNetwork } from 'testcontainers';

import { logConsumer } from './utils';

export class PostgreSqlContainer extends GenericContainer {
private database = 'test';
private username = 'test';
private password = 'test';
export class PostgreSqlContainer {
private database = 'postgres';
private username = 'postgres';
private password = 'postgres';

private readonly PORT = 5432;

constructor (image = 'postgres:14') {
super(image);

this.withExposedPorts(this.PORT)
private constructor (private readonly container: GenericContainer) {
container.withExposedPorts(this.PORT)
.withWaitStrategy(Wait.forLogMessage(/.*database system is ready to accept connections.*/, 2))
.withLogConsumer(logConsumer)
.withStartupTimeout(120_000);
}

public static async build (): Promise<PostgreSqlContainer> {
const container = await GenericContainer.fromDockerfile('../', 'postgres.Dockerfile').build();

return new PostgreSqlContainer(container);
}

public withNetwork (network: StartedNetwork): this {
this.container.withNetwork(network);
return this;
}

public withDatabase (database: string): this {
this.database = database;
return this;
Expand All @@ -33,13 +42,13 @@ export class PostgreSqlContainer extends GenericContainer {
return this;
}

public override async start (): Promise<StartedPostgreSqlContainer> {
this.withEnvironment({
public async start (): Promise<StartedPostgreSqlContainer> {
this.container.withEnvironment({
POSTGRES_DB: this.database,
POSTGRES_USER: this.username,
POSTGRES_PASSWORD: this.password,
});
return new StartedPostgreSqlContainer(await super.start(), this.database, this.username, this.password, this.PORT);
return new StartedPostgreSqlContainer(await this.container.start(), this.database, this.username, this.password, this.PORT);
}
}

Expand Down

0 comments on commit 7a4862a

Please sign in to comment.