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

Move the e2e tests to a separate package #413

Merged
merged 6 commits into from
Aug 8, 2024
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
63 changes: 52 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"packages/restate-sdk-core",
"packages/restate-sdk",
"packages/restate-sdk-clients",
"packages/restate-sdk-examples"
"packages/restate-sdk-examples",
"packages/restate-e2e-services"
],
"type": "module",
"scripts": {
Expand All @@ -29,7 +30,7 @@
"format": "npm run format -ws --if-present",
"format-check": "npm run format-check -ws --if-present",
"verify": "npm run verify -ws --if-present",
"clean": "rm -rf packages/restate-sdk/dist && rm -rf packages/restate-sdk-examples/dist && rm -rf packages/restate-sdk-ingress/dist"
"clean": "rm -rf packages/restate-sdk/dist && rm -rf packages/restate-sdk-examples/dist && rm -rf packages/restate-sdk-ingress/dist && rm -rf packages/restate-e2e-services/dist && rm -rf packages/restate-sdk-core/dist"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.3",
Expand Down
3 changes: 3 additions & 0 deletions packages/restate-e2e-services/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
dist
3 changes: 3 additions & 0 deletions packages/restate-e2e-services/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
src/generated
17 changes: 17 additions & 0 deletions packages/restate-e2e-services/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest"
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/no-empty-function": "off"
}
}
13 changes: 13 additions & 0 deletions packages/restate-e2e-services/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules/
dist/
generated/

.idea

npm-debug.log*
*.tsbuildinfo
.npm
.eslintcache

# We ignore the package-lock.json because this is updated every time with dev releases of sdk-typescript
package-lock.json
25 changes: 25 additions & 0 deletions packages/restate-e2e-services/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM node:20 AS build

WORKDIR /usr/src/app

COPY . .

RUN npm install

RUN npm run build

FROM node:20 as prod
WORKDIR /usr/src/app

# Install app dependencies
COPY ./packages/restate-e2e-services/package*.json ./
RUN npm install --production

COPY --from=build /usr/src/app/packages/restate-e2e-services/dist /usr/src/app/dist

# Install Tini
RUN apt-get update && apt-get -y install tini

EXPOSE 8080
ENTRYPOINT ["tini", "--"]
CMD ["node", "/usr/src/app/dist/src/app.js"]
15 changes: 15 additions & 0 deletions packages/restate-e2e-services/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Build Docker image from the project root

```shell
docker build . -f packages/restate-e2e-services/Dockerfile -t restatedev/node-test-services
```

## Running the services locally

The Node services can be run via:

```shell
SERVICES=<COMMA_SEPARATED_LIST_OF_SERVICES> gradle npm_run_app
```

For the list of supported services see [here](src/app.ts).
45 changes: 45 additions & 0 deletions packages/restate-e2e-services/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "@restatedev/restate-e2e-services",
"version": "1.1.2",
"description": "Typescript SDK e2e tests",
"private": true,
"author": "Restate Developers",
"license": "MIT",
"email": "[email protected]",
"homepage": "https://github.com/restatedev/sdk-typescript#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/restatedev/sdk-typescript.git"
},
"bugs": {
"url": "https://github.com/restatedev/sdk-typescript/issues"
},
"type": "module",
"main": "./dist/src/public_api.js",
"types": "./dist/src/public_api.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "tsc -b",
"lint": "eslint --ignore-path .eslintignore --max-warnings=0 --ext .ts .",
"format": "prettier --ignore-path .eslintignore --write \"**/*.+(js|ts|json)\"",
"format-check": "prettier --ignore-path .eslintignore --check \"**/*.+(js|ts|json)\"",
"test": "vitest run --silent",
"verify": "npm run format-check && npm run lint && npm run build",
"release": ""
},
"dependencies": {
"@restatedev/restate-sdk": "^1.1.2",
"@restatedev/restate-sdk-clients": "^1.1.2",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/node": "*",
"@types/uuid": "^10.0.0",
"tsx": "^4.15.7"
},
"engines": {
"node": ">= 18"
}
}
44 changes: 44 additions & 0 deletions packages/restate-e2e-services/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
//
// This file is part of the Restate e2e tests,
// which are released under the MIT license.
//
// You can find a copy of the license in file LICENSE in the root
// directory of this repository or package, or at
// https://github.com/restatedev/e2e/blob/main/LICENSE

import * as restate from "@restatedev/restate-sdk";

import "./awakeable_holder.js";
import "./counter.js";
import "./event_handler.js";
import "./list.js";
import "./map.js";
import "./cancel_test.js";
import "./non_determinism.js";
import "./failing.js";
import "./side_effect.js";
import "./workflow.js";
import "./proxy.js";
import "./test_utils.js";

import { REGISTRY } from "./services.js";

if (!process.env.SERVICES) {
throw new Error("Cannot find SERVICES env");
}
const fqdns = new Set(process.env.SERVICES.split(","));
const endpoint = restate.endpoint();
REGISTRY.register(fqdns, endpoint);

if (process.env.E2E_REQUEST_SIGNING) {
endpoint.withIdentityV1(...process.env.E2E_REQUEST_SIGNING.split(","));
}
if (!process.env.AWS_LAMBDA_FUNCTION_NAME) {
endpoint.listen().catch((e) => {
// eslint-disable-next-line no-console
console.error(e);
});
}

export const handler = endpoint.lambdaHandler();
43 changes: 43 additions & 0 deletions packages/restate-e2e-services/src/awakeable_holder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2023 - Restate Software, Inc., Restate GmbH
//
// This file is part of the Restate e2e tests,
// which are released under the MIT license.
//
// You can find a copy of the license in file LICENSE in the root
// directory of this repository or package, or at
// https://github.com/restatedev/e2e/blob/main/LICENSE

import * as restate from "@restatedev/restate-sdk";
import { REGISTRY } from "./services.js";

const ID_KEY = "id";

type Ctx = restate.ObjectContext;

const service = restate.object({
name: "AwakeableHolder",
handlers: {
hold(ctx: restate.ObjectContext, id: string) {
ctx.set(ID_KEY, id);
return Promise.resolve();
},

async hasAwakeable(ctx: Ctx): Promise<boolean> {
const maybe = await ctx.get<string>(ID_KEY);
return maybe !== null && maybe !== undefined;
},

async unlock(ctx: Ctx, request: string) {
const id = await ctx.get<string>(ID_KEY);
if (id === null || id === undefined) {
throw new Error("No awakeable registered");
}
ctx.resolveAwakeable(id, request);
ctx.clear(ID_KEY);
},
},
});

REGISTRY.addObject(service);

export type AwakeableHolder = typeof service;
Loading