Skip to content

Commit

Permalink
Run test DB for full monorepo tests (#1225)
Browse files Browse the repository at this point in the history
* run with-test-db in monorepo test

* improve pg script

* tidy

* namespace bsky pg schemas

* differentiate schemas

* clean up script

* tweaking script
  • Loading branch information
dholms committed Jun 28, 2023
1 parent b852d2e commit ba870d3
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"verify": "lerna run verify --stream",
"prettier": "lerna run prettier",
"build": "lerna run build",
"test": "NODE_ENV=development lerna run test --stream",
"test:withFlags": "NODE_ENV=development lerna run test --stream --"
"test": "LOG_ENABLED=false NODE_ENV=development ./packages/pg/with-test-db.sh lerna run test --stream",
"test:withFlags": "LOG_ENABLED=false NODE_ENV=development ./packages/pg/with-test-db.sh lerna run test --stream --"
},
"devDependencies": {
"@babel/core": "^7.18.6",
Expand Down
2 changes: 1 addition & 1 deletion packages/bsky/tests/algos/hot-classic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('algo hot-classic', () => {

beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'algo_hot_classic',
dbPostgresSchema: 'bsky_algo_hot_classic',
bsky: { algos: makeAlgos(feedPublisherDid) },
})
agent = new AtpAgent({ service: network.bsky.url })
Expand Down
2 changes: 1 addition & 1 deletion packages/bsky/tests/algos/whats-hot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('algo whats-hot', () => {

beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'algo_whats_hot',
dbPostgresSchema: 'bsky_algo_whats_hot',
bsky: { algos: makeAlgos(feedPublisherDid) },
})
agent = new AtpAgent({ service: network.bsky.url })
Expand Down
2 changes: 1 addition & 1 deletion packages/bsky/tests/algos/with-friends.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe.skip('algo with friends', () => {

beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'algo_with_friends',
dbPostgresSchema: 'bsky_algo_with_friends',
bsky: { algos: makeAlgos(feedPublisherDid) },
})
agent = new AtpAgent({ service: network.bsky.url })
Expand Down
2 changes: 1 addition & 1 deletion packages/bsky/tests/feed-generation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('feed generation', () => {

beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'feed_generation',
dbPostgresSchema: 'bsky_feed_generation',
})
agent = network.bsky.getClient()
pdsAgent = network.pds.getClient()
Expand Down
2 changes: 1 addition & 1 deletion packages/bsky/tests/labeler/labeler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('labeler', () => {

beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'labeler',
dbPostgresSchema: 'bsky_labeler',
})
ctx = network.bsky.ctx
const pdsCtx = network.pds.ctx
Expand Down
2 changes: 1 addition & 1 deletion packages/bsky/tests/moderation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('moderation', () => {

beforeAll(async () => {
network = await TestNetwork.create({
dbPostgresSchema: 'moderation',
dbPostgresSchema: 'bsky_moderation',
})
agent = network.bsky.getClient()
const pdsAgent = network.pds.getClient()
Expand Down
11 changes: 1 addition & 10 deletions packages/pds/tests/_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as plc from '@did-plc/lib'
import { PlcServer, Database as PlcDatabase } from '@did-plc/server'
import { AtUri } from '@atproto/uri'
import { randomStr } from '@atproto/crypto'
import { uniqueLockId } from '@atproto/dev-env'
import { CID } from 'multiformats/cid'
import * as uint8arrays from 'uint8arrays'
import { PDS, ServerConfig, Database, MemoryBlobStore } from '../src/index'
Expand Down Expand Up @@ -159,16 +160,6 @@ export const runTestServer = async (
}
}

const usedLockIds = new Set()
const uniqueLockId = () => {
let lockId: number
do {
lockId = 1000 + Math.ceil(1000 * Math.random())
} while (usedLockIds.has(lockId))
usedLockIds.add(lockId)
return lockId
}

export const adminAuth = () => {
return basicAuth('admin', ADMIN_PASSWORD)
}
Expand Down
22 changes: 18 additions & 4 deletions packages/pg/with-test-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@
dir=$(dirname $0)
compose_file="$dir/docker-compose.yaml"

docker compose -f $compose_file up --wait --force-recreate db_test
echo # newline
# whether this particular script started the container or if it was running beforehand
started_container=false

trap on_sigint INT
on_sigint() {
echo # newline
docker compose -f $compose_file rm -f --stop --volumes db_test
if $started_container; then
docker compose -f $compose_file rm -f --stop --volumes db_test
fi
exit $?
}

# check if the container is already running
container_id=$(docker compose -f $compose_file ps --format json --status running | jq --raw-output '.[0]."ID"')
if [ -z $container_id ] || [ -z `docker ps -q --no-trunc | grep $container_id` ]; then
docker compose -f $compose_file up --wait --force-recreate db_test
started_container=true
echo # newline
else
echo "db_test already running"
fi

# Based on creds in compose.yaml
export PGPORT=5433
export PGHOST=localhost
Expand All @@ -27,6 +39,8 @@ export DB_POSTGRES_URL="postgresql://pg:password@localhost:5433/postgres"
code=$?

echo # newline
docker compose -f $compose_file rm -f --stop --volumes db_test
if $started_container; then
docker compose -f $compose_file rm -f --stop --volumes db_test
fi

exit $code

0 comments on commit ba870d3

Please sign in to comment.