Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BT-4181: Query limits test case and pipeline collateral #216

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions __tests__/integration/query-limits.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { Client, fql, Module } from "../../src";
import { getClient, getDefaultSecretAndEndpoint } from "../client";

const rootClient = getClient();
const clients = new Array<Client>();
const limitedDbName = process.env["QUERY_LIMITS_DB"] || "";
const collectionName = process.env["QUERY_LIMITS_COLL"] || "";
const maybeDescribe =
process.env["QUERY_LIMITS_DB"] && process.env["QUERY_LIMITS_COLL"]
? describe
: describe.skip;

beforeAll(async () => {
// Create Key for test database and create clients with the secret
let secret = await rootClient
.query<{ secret: string }>(
fql`
if (Database.byName(${limitedDbName}).exists()) {
Key.create({ role: "admin", database: ${limitedDbName} }) { secret }
} else {
abort("Database not found.")
}`
)
.then((res) => res.data.secret)
.catch((err) => {
console.log(err);
throw err;
});

for (let i = 0; i < 5; i++) {
clients.push(getClient({ secret: secret }));
}
});

afterAll(() => {
rootClient.close();
clients.forEach((x) => x.close());
});

maybeDescribe("Query with limits enabled", () => {
it("succeeds on retry after getting throttled", async () => {
expect.assertions(1);

let throttled = false;
await Promise.all(
clients.map((client) => {
// Target DB needs read_ops limit of 100; call .paginate(50) several times
// simultaneously to get throttled, all calls should succeed on client retry
return client
.query(fql`${fql([collectionName])}.all().paginate(50)`)
.then((res) => {
if (res.stats?.attempts && res.stats.attempts > 1) {
throttled = true;
}
})
.catch((err) => {
console.log(err);
throw err;
});
})
);

expect(throttled).toBeTruthy();
}, 20000);
});
8 changes: 7 additions & 1 deletion concourse/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ groups:
- name: standard-release
jobs:
- set-self
- test
- test
- release

jobs:
Expand Down Expand Up @@ -100,6 +100,12 @@ jobs:
NETLIFY_ACCOUNT: ((drivers-platform-tests/netlify-account))
NETLIFY_AUTH_TOKEN: ((drivers-platform-tests/netlify-auth-token))

- task: query-limits-tests
file: fauna-js-repository/concourse/tasks/query-limits-tests.yml
params:
QUERY_LIMITS_DB: limited
QUERY_LIMITS_COLL: limitCollection

# - task: vercel-tests
# image: testtools-image
# file: testtools-repo/fauna-driver-platform-tests/concourse/tasks/js-vercel-tests.yml
Expand Down
25 changes: 24 additions & 1 deletion concourse/scripts/docker-compose-fauna.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
version: "3.3"
version: "3.5"

networks:
limit-net:
external: true
name: limit-net

services:
faunadb:
Expand Down Expand Up @@ -44,3 +49,21 @@ services:
apk add --no-cache curl
./wait-for-it.sh http://faunadb:8443/ping
yarn test:integration

query-limits-tests:
image: node:20.2-alpine3.16
container_name: node-current-limits-test
networks:
- limit-net
volumes:
- "../../:/tmp/app"
working_dir: "/tmp/app"
environment:
FAUNA_ENDPOINT: ${FAUNA_ENDPOINT:-http://fauna-limits:8443}
QUERY_LIMITS_DB: ${QUERY_LIMITS_DB}
QUERY_LIMITS_COLL: ${QUERY_LIMITS_COLL}
command:
- /bin/sh
- -cxe
- |
yarn test:query-limits
34 changes: 34 additions & 0 deletions concourse/tasks/query-limits-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
platform: linux
image_resource:
type: registry-image
source:
repository: shared-concourse-dind
aws_access_key_id: ((prod-images-aws-access-key-id))
aws_secret_access_key: ((prod-images-aws-secret-key))
aws_region: us-east-2

params:
FAUNA_ENDPOINT: http://fauna-limits:8443
QUERY_LIMITS_DB:
QUERY_LIMITS_COLL:

inputs:
- name: fauna-js-repository
- name: testtools-repo

run:
path: entrypoint.sh
args:
- bash
- -ceu
- |
# setup Fauna container
docker-compose -f testtools-repo/fauna-driver-query-limits-tests/concourse/scripts/docker-compose.yml run setup
# run tests
docker-compose -f fauna-js-repository/concourse/scripts/docker-compose-fauna.yml run query-limits-tests
# stop and remove containers
docker-compose -f fauna-js-repository/concourse/scripts/docker-compose-fauna.yml down
docker-compose -f testtools-repo/fauna-driver-query-limits-tests/concourse/scripts/docker-compose.yml down
# remove volumes
docker volume rm $(docker volume ls -q)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"prepare": "husky install",
"test": "yarn fauna-local; yarn fauna-local-alt-port; ./prepare-test-env.sh; jest",
"test:ci": "yarn install; jest --ci --reporters=default --reporters=jest-junit",
"test:integration": "yarn install; jest --run-in-band ./__tests__/integration"
"test:integration": "yarn install; jest --run-in-band ./__tests__/integration",
"test:query-limits": "yarn install; jest ./__tests__/integration/query-limits.test.ts"
},
"jest-junit": {
"outputDirectory": "reports",
Expand Down